You are here

public function JuiceboxFieldFormatterCase::testFieldFormatterConf in Juicebox HTML5 Responsive Image Galleries 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/JuiceboxFieldFormatterCase.php \Drupal\Tests\juicebox\Functional\JuiceboxFieldFormatterCase::testFieldFormatterConf()

Test configuration options that are specific to Juicebox field formatter.

File

tests/src/Functional/JuiceboxFieldFormatterCase.php, line 64

Class

JuiceboxFieldFormatterCase
Tests the Juicebox field formatter.

Namespace

Drupal\Tests\juicebox\Functional

Code

public function testFieldFormatterConf() {
  $node = $this->node;

  // Do a set of control requests as an anon user that will also prime any
  // caches.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertResponse(200, 'Control request of test node was successful.');
  $this
    ->drupalGet('juicebox/xml/field/node/' . $node
    ->id() . '/' . $this->instFieldName . '/full');
  $this
    ->assertResponse(200, 'Control request of XML was successful.');

  // Alter field formatter specific settings to contain custom values.
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->instBundle . '/display');
  $this
    ->submitForm([], $this->instFieldName . '_settings_edit', 'entity-view-display-edit-form');
  $edit = [
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][image_style]' => '',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][thumb_style]' => 'thumbnail',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][caption_source]' => 'alt',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][title_source]' => 'title',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertText($this
    ->t('Your settings have been saved.'), 'Gallery configuration changes saved.');

  // Get the urls to the image and thumb derivatives expected.
  $uri = File::load($node->{$this->instFieldName}[0]->target_id)
    ->getFileUri();
  $test_formatted_image_url = file_create_url($uri);
  $test_formatted_thumb_url = entity_load('image_style', 'thumbnail')
    ->buildUrl($uri);

  // Check for correct embed markup as anon user.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertRaw(Html::escape(file_url_transform_relative($test_formatted_image_url)), 'Test styled image found in embed code');

  // Check for correct XML.
  $this
    ->drupalGet('juicebox/xml/field/node/' . $node
    ->id() . '/' . $this->instFieldName . '/full');
  $this
    ->assertRaw('imageURL="' . Html::escape($test_formatted_image_url), 'Test styled image found in XML.');
  $this
    ->assertRaw('thumbURL="' . Html::escape($test_formatted_thumb_url), 'Test styled thumbnail found in XML.');

  // Note the intended title and caption text does not contain any block-level
  // tags as long as the global title and caption output filter is working.
  // So this acts as a test for that feature as well.
  $this
    ->assertRaw('<title><![CDATA[Some title text for field ' . $this->instFieldName . ' on node ' . $node
    ->id() . ']]></title>', 'Image title text found in XML');
  $this
    ->assertRaw('<caption><![CDATA[Some alt text for field ' . $this->instFieldName . ' on node ' . $node
    ->id() . ' &lt;strong&gt;with formatting&lt;/strong&gt;]]></caption>', 'Image caption text found in XML');

  // Now that we have title and caption data set, also ensure this text can
  // be found in search results. First we update the search index by marking
  // our test node as dirty and running cron.
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm([], 'Save');
  $this
    ->cronRun();
  $this
    ->drupalGet('search');
  $this
    ->submitForm([
    'keys' => '"Some title text"',
  ], 'Search');
  $this
    ->assertText('Test Juicebox Gallery Node', 'Juicebox node found in search for title text.');

  // The Juicebox javascript should have been excluded from the search results
  // page.
  $this
    ->assertNoRaw('"configUrl":"', 'Juicebox Drupal.settings vars not included on search result page.');
}