You are here

public function RestfulListTestCase::testCountWithUnpublished in RESTful 7.2

Same name and namespace in other branches
  1. 7 tests/RestfulListTestCase.test \RestfulListTestCase::testCountWithUnpublished()

Test node count and pager when there are unpublished nodes.

File

tests/RestfulListTestCase.test, line 841
Contains RestfulListTestCase.

Class

RestfulListTestCase
Class RestfulListTestCase.

Code

public function testCountWithUnpublished() {
  foreach (range(1, 9) as $key) {
    $settings = array(
      'type' => 'article',
      'title' => $key,
      'status' => NODE_PUBLISHED,
    );
    $this
      ->drupalCreateNode($settings);
  }
  foreach (range(1, 3) as $key) {
    $settings = array(
      'type' => 'article',
      'title' => $key,
      'status' => NODE_NOT_PUBLISHED,
    );
    $this
      ->drupalCreateNode($settings);
  }
  $handler = restful()
    ->getResourceManager()
    ->getPlugin('articles:1.0');
  $formatter = restful()
    ->getFormatterManager()
    ->getPlugin('json');
  $formatter
    ->setResource($handler);

  // Set a range for pagination to check only .
  $handler
    ->getDataProvider()
    ->setRange(9);

  // Check pagination of first page.
  $result = $handler
    ->doGet('', array(
    'page' => 1,
  ));
  $output = drupal_json_decode($formatter
    ->format($result));
  $this
    ->assertEqual(count($result), 9, 'Number of results displayed');
  $this
    ->assertEqual(count($result), $handler
    ->getDataProvider()
    ->count(), 'Count of results takes into account unpublished nodes');
  $this
    ->assertTrue(empty($output['next']), '"Next" link does not exist on the first page.');
  $this
    ->assertTrue(empty($output['previous']), '"Previous" link does not exist on the first page.');
}