function EntityFieldQueryTestCase::testEntityFieldQueryPager

Tests the pager integration of EntityFieldQuery.

File

modules/simpletest/tests/entity_query.test, line 1363

Class

EntityFieldQueryTestCase
Tests EntityFieldQuery.

Code

function testEntityFieldQueryPager() {
    // Test pager in propertyQuery
    $_GET['page'] = '0,1';
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'test_entity_bundle_key')
        ->propertyOrderBy('ftid', 'ASC')
        ->pager(3, 0);
    $this->assertEntityFieldQuery($query, array(
        array(
            'test_entity_bundle_key',
            1,
        ),
        array(
            'test_entity_bundle_key',
            2,
        ),
        array(
            'test_entity_bundle_key',
            3,
        ),
    ), 'Test pager integration in propertyQuery: page 1.', TRUE);
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'test_entity_bundle_key')
        ->propertyOrderBy('ftid', 'ASC')
        ->pager(3, 1);
    $this->assertEntityFieldQuery($query, array(
        array(
            'test_entity_bundle_key',
            4,
        ),
        array(
            'test_entity_bundle_key',
            5,
        ),
        array(
            'test_entity_bundle_key',
            6,
        ),
    ), 'Test pager integration in propertyQuery: page 2.', TRUE);
    // Test pager in field storage
    $_GET['page'] = '0,1';
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'test_entity_bundle_key')
        ->fieldCondition($this->fields[0], 'value', 0, '>')
        ->propertyOrderBy('ftid', 'ASC')
        ->pager(2, 0);
    $this->assertEntityFieldQuery($query, array(
        array(
            'test_entity_bundle_key',
            1,
        ),
        array(
            'test_entity_bundle_key',
            2,
        ),
    ), 'Test pager integration in field storage: page 1.', TRUE);
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'test_entity_bundle_key')
        ->fieldCondition($this->fields[0], 'value', 0, '>')
        ->propertyOrderBy('ftid', 'ASC')
        ->pager(2, 1);
    $this->assertEntityFieldQuery($query, array(
        array(
            'test_entity_bundle_key',
            3,
        ),
        array(
            'test_entity_bundle_key',
            4,
        ),
    ), 'Test pager integration in field storage: page 2.', TRUE);
    unset($_GET['page']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.