X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv4%2FAction%2FContactGetTest.php;h=e7d5ba1adaae54a720cc33fa9f85e466ea940fb6;hb=19dc865264f31f29eef39a374d7e3ccc1cb60239;hp=e1be3ca566cd962a1091ccc175bf794c4e82d56e;hpb=fa580b281d0b8e6e0895b84d3349a4654585963e;p=civicrm-core.git diff --git a/tests/phpunit/api/v4/Action/ContactGetTest.php b/tests/phpunit/api/v4/Action/ContactGetTest.php index e1be3ca566..e7d5ba1ada 100644 --- a/tests/phpunit/api/v4/Action/ContactGetTest.php +++ b/tests/phpunit/api/v4/Action/ContactGetTest.php @@ -73,10 +73,23 @@ class ContactGetTest extends \api\v4\UnitTestCase { ->setValues(['first_name' => 'Dan', 'last_name' => $last_name]) ->execute()->first(); - $num = Contact::get()->setCheckPermissions(FALSE)->selectRowCount()->execute()->count(); - $this->assertCount($num - 1, Contact::get()->setCheckPermissions(FALSE)->setLimit(0)->setOffset(1)->execute()); - $this->assertCount($num - 2, Contact::get()->setCheckPermissions(FALSE)->setLimit(0)->setOffset(2)->execute()); - $this->assertCount(2, Contact::get()->setCheckPermissions(FALSE)->setLimit(2)->setOffset(0)->execute()); + $num = Contact::get(FALSE)->selectRowCount()->execute()->count(); + + // The object's count() method will account for all results, ignoring limit & offset, while the array results are limited + $offset1 = Contact::get(FALSE)->setOffset(1)->execute(); + $this->assertCount($num, $offset1); + $this->assertCount($num - 1, (array) $offset1); + $offset2 = Contact::get(FALSE)->setOffset(2)->execute(); + $this->assertCount($num - 2, (array) $offset2); + $this->assertCount($num, $offset2); + // With limit, it doesn't fetch total count by default + $limit2 = Contact::get(FALSE)->setLimit(2)->execute(); + $this->assertCount(2, (array) $limit2); + $this->assertCount(2, $limit2); + // With limit, you have to trigger the full row count manually + $limit2 = Contact::get(FALSE)->setLimit(2)->addSelect('sort_name', 'row_count')->execute(); + $this->assertCount(2, (array) $limit2); + $this->assertCount($num, $limit2); } }