You are here

public function DisplayJsonFeedTest::testFeedOutput in JSON Feed 8

Tests the rendered feed output.

File

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

Class

DisplayJsonFeedTest
Tests the json_feed display plugin.

Namespace

Drupal\Tests\json_feed\Functional

Code

public function testFeedOutput() {
  $json_response = Json::decode($this
    ->drupalGet($this->feedPath, [
    'query' => [
      '_format' => 'json',
    ],
  ]));
  $this
    ->assertResponse(200);
  $this
    ->assertTrue(array_key_exists('version', $json_response), 'JSON Feed version present.');
  $this
    ->assertEqual('https://jsonfeed.org/version/1', $json_response['version'], 'JSON Feed version set correctly.');
  $this
    ->assertTrue(array_key_exists('title', $json_response), 'JSON Feed title present.');
  $this
    ->assertEqual('test_display_json_feed', $json_response['title'], 'JSON Feed title set correctly.');
  $this
    ->assertTrue(array_key_exists('description', $json_response), 'JSON Feed description present.');
  $this
    ->assertEqual('Test feed description.', $json_response['description'], 'JSON Feed description set correctly.');
  $this
    ->assertTrue(array_key_exists('home_page_url', $json_response), 'JSON Feed home_page_url present.');

  // @TODO: Implement test for home_page_url attribute value.
  $this
    ->assertTrue(array_key_exists('feed_url', $json_response), 'JSON Feed feed_url present.');
  $this
    ->assertTrue(strpos($json_response['feed_url'], $this->feedPath) !== FALSE, 'JSON Feed feed_url set correctly.');
  $this
    ->assertTrue(array_key_exists('favicon', $json_response), 'JSON Feed favicon present.');
  $favicon_path = Url::fromUserInput(theme_get_setting('favicon.url'))
    ->setAbsolute()
    ->toString();
  $this
    ->assertEqual($favicon_path, $json_response['favicon'], 'JSON Feed favicon set correctly.');
  $this
    ->assertTrue(array_key_exists('expired', $json_response), 'JSON Feed expired attribute present.');
  $this
    ->assertEqual(FALSE, $json_response['expired'], 'JSON Feed expired attribute set to FALSE.');
}