You are here

public function DisplayJsonFeedTest::testFeedItems in JSON Feed 8

Tests the feed items.

File

tests/src/Functional/DisplayJsonFeedTest.php, line 138

Class

DisplayJsonFeedTest
Tests the json_feed display plugin.

Namespace

Drupal\Tests\json_feed\Functional

Code

public function testFeedItems() {
  $json_response = Json::decode($this
    ->drupalGet($this->feedPath, [
    'query' => [
      '_format' => 'json',
    ],
  ]));
  $this
    ->assertEqual($this
    ->expectedFirstPageItems(), count($json_response['items']), 'JSON Feed returned ' . $this
    ->expectedFirstPageItems() . ' items.');
  $item = $json_response['items'][0];
  $this
    ->assertTrue(array_key_exists('date_published', $item), 'JSON Feed item date_published attribute present.');
  $this
    ->assertTrue(array_key_exists('date_modified', $item), 'JSON Feed item date_modified attribute present.');
  $this
    ->assertTrue(array_key_exists('tags', $item), 'JSON Feed item tags attribute present.');

  // @TODO: Test remaining item attributes.
}