New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxLimit is ignored in PaginatorComponent.php #9848

Closed
gorogoroyasu opened this Issue Dec 7, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@gorogoroyasu
Contributor

gorogoroyasu commented Dec 7, 2016

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.3.9

  • Platform and Target: This phenomenon seems not depend on platform.

What you did

One of the options maxLimit was ignored in my application, and I checked the codes.
Finally, I found a suspicious code in cakephp/src/Controller/Component/PaginatorComponent.php.
I wrote some test codes, and the error occured.

The test codes I added is shown below.

/**
 * test getDefaults with limit > maxLimit in code.
 *
 * @return void
 */
public function testGetDefaultMaxLimit()
{
    $settings = [
        'page' => 1,
        'limit' => 2,
        'maxLimit' => 10,
        'order' => [
            'Users.username' => 'asc'
        ],
    ];
    $result = $this->Paginator->mergeOptions('Post', $settings);
    $expected = [
        'page' => 1,
        'limit' => 2,
        'maxLimit' => 10,
        'order' => [
            'Users.username' => 'asc'
        ],
        'whitelist' => ['limit', 'sort', 'page', 'direction']
    ];
    $this->assertEquals($expected, $result);

    $settings = [
        'page' => 1,
        'limit' => 100,
        'maxLimit' => 10,
        'order' => [
            'Users.username' => 'asc'
        ],
    ];
    $result = $this->Paginator->mergeOptions('Post', $settings);
    $expected = [
        'page' => 1,
        'limit' => 10,
        'maxLimit' => 10,
        'order' => [
            'Users.username' => 'asc'
        ],
        'whitelist' => ['limit', 'sort', 'page', 'direction']
    ];
    $this->assertEquals($expected, $result);
}

What happened

The error shown below occured in the test.


gorogoroyasu$ vendor/bin/phpunit tests/TestCase/Controller/Component/PaginatorComponentTest.php
PHPUnit 5.7.2 by Sebastian Bergmann and contributors.

.............F.............................                       43 / 43 (100%)

Time: 302 ms, Memory: 14.25MB

There was 1 failure:

1) Cake\Test\TestCase\Controller\Component\PaginatorComponentTest::testGetDefaultMaxLimit
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     'page' => 1
-    'limit' => 10
-    'maxLimit' => 10
+    'limit' => 100
+    'maxLimit' => 100
     'order' => Array (...)
     'whitelist' => Array (...)
 )

/Users/gorogoroyasu/cakephp3-core/cakephp/tests/TestCase/Controller/Component/PaginatorComponentTest.php:550

FAILURES!
Tests: 43, Assertions: 94, Failures: 1.

What you expected to happen

If maxLimit is given in array $settings, the limit value in array $result should be equal to maxLimit, though it wasn't.
In conclusion, I regard this phenomenon as bug.

I showed an example to fix this bug in #9849 ,
please review it, and I expect for some comments.
If my PullRequest is not worth to merge, don't hesitate to close it.

Thanks for your attention.

@VarCI-bot VarCI-bot added the Defect label Dec 7, 2016

gorogoroyasu added a commit to gorogoroyasu/cakephp that referenced this issue Dec 7, 2016

@chinpei215 chinpei215 added this to the 3.3.10 milestone Dec 7, 2016

@chinpei215

This comment has been minimized.

Show comment
Hide comment
@chinpei215

chinpei215 Dec 7, 2016

Member

Sounds reasonable to me. This behavior seems different from 2.x.

Member

chinpei215 commented Dec 7, 2016

Sounds reasonable to me. This behavior seems different from 2.x.

@chinpei215

This comment has been minimized.

Show comment
Hide comment
@chinpei215

chinpei215 Dec 7, 2016

Member

Closing, as pull request up now.

Member

chinpei215 commented Dec 7, 2016

Closing, as pull request up now.

@chinpei215 chinpei215 closed this Dec 7, 2016

markstory added a commit that referenced this issue Dec 7, 2016

Merge pull request #9849 from gorogoroyasu/issue9848-cakephp-paginato…
…rcomponent-maxlimit

#9848 PaginatorComponent.php does not cap limit to maxLimit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment