You are here

public function BlazyTest::testAttach in Blazy 7

Tests cases for attachments.

@covers \Drupal\blazy\BlazyManager::attach

File

tests/Blazy.test, line 155

Class

BlazyTest
Tests the Blazy configuration options and permission controls.

Code

public function testAttach() {
  $attach = [
    'blazy' => TRUE,
    'grid' => 0,
    'media' => TRUE,
    'ratio' => 'fluid',
    'style' => 'column',
  ];
  $attachments = blazy()
    ->attach($attach);

  // Verifies the required libraries are attached.
  $this
    ->assertTrue(array_key_exists('library', $attachments), 'Attachments has library defined.');
  $this
    ->assertTrue(array_key_exists('blazy', $attachments['js'][0]['data']), 'Attachments has blazy settings in JS data.');

  // Requires PHP 5.5+.
  $this
    ->assertTrue(array_search('media', array_column($attachments['library'], 1)) !== FALSE, 'Blazy media is attached.');
  $this
    ->assertTrue(array_search('ratio', array_column($attachments['library'], 1)) !== FALSE, 'Blazy ratio is attached.');
  $this
    ->assertTrue(array_search('load', array_column($attachments['library'], 1)) !== FALSE, 'Blazy library is attached.');
  $this
    ->assertTrue(array_search('column', array_column($attachments['library'], 1)) !== FALSE, 'Blazy column is attached.');

  // Grid should not be loaded.
  $this
    ->assertFalse(array_search('grid', array_column($attachments['library'], 1)) === FALSE, 'Blazy grid should NOT be attached.');
}