BlazyFilterJavaScriptTest.php in Blazy 8.2
File
tests/src/FunctionalJavascript/BlazyFilterJavaScriptTest.php
View source
<?php
namespace Drupal\Tests\blazy\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\blazy\Traits\BlazyUnitTestTrait;
use Drupal\Tests\blazy\Traits\BlazyCreationTestTrait;
class BlazyFilterJavaScriptTest extends WebDriverTestBase {
use BlazyUnitTestTrait;
use BlazyCreationTestTrait;
protected $defaultTheme = 'stark';
protected $minkDefaultDriverClass = DrupalSelenium2Driver::class;
protected static $modules = [
'field',
'filter',
'image',
'media',
'node',
'text',
'blazy',
'blazy_test',
];
protected function setUp() {
parent::setUp();
$this
->setUpVariables();
$this->root = $this->container
->get('app.root');
$this->fileSystem = $this->container
->get('file_system');
$this->entityFieldManager = $this->container
->get('entity_field.manager');
$this->formatterPluginManager = $this->container
->get('plugin.manager.field.formatter');
$this->blazyAdmin = $this->container
->get('blazy.admin');
$this->blazyOembed = $this->container
->get('blazy.oembed');
$this->blazyManager = $this->container
->get('blazy.manager');
$this->testPluginId = 'blazy_filter';
$this->maxParagraphs = 280;
$full_html = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 0,
]);
$full_html
->save();
$this->filterFormatFull = FilterFormat::load('full_html');
$this->filterFormatFull
->setFilterConfig('blazy_filter', [
'status' => TRUE,
]);
$this->filterFormatFull
->save();
$this
->setUpRealImage();
}
public function testFilterDisplay() {
$image_path = $this
->getImagePath(TRUE);
$settings['extra_text'] = '<div style="width: 640px;">';
$settings['extra_text'] .= '<img data-unblazy src="' . $this->url . '" width="320" height="320" />';
$settings['extra_text'] .= '<iframe src="https://www.youtube.com/watch?v=uny9kbh4iOEd" width="640" height="360"></iframe>';
$settings['extra_text'] .= '<img src="' . $this->url . '" width="320" height="320" />';
$settings['extra_text'] .= '<img src="https://www.drupal.org/files/project-images/slick-carousel-drupal.png" width="215" height="162" />';
$settings['extra_text'] .= '</div>';
$this
->setUpContentTypeTest($this->bundle);
$this
->setUpContentWithItems($this->bundle, $settings);
$session = $this
->getSession();
$this
->drupalGet('node/' . $this->entity
->id());
$this
->createScreenshot($image_path . '/1_blazy_filter_initial.png');
$this
->assertSession()
->elementExists('css', '.b-lazy');
$session
->executeScript('window.scrollTo(0, document.body.scrollHeight);');
$this
->createScreenshot($image_path . '/2_blazy_filter_loading.png');
$this
->assertSession()
->elementExists('css', '.media-wrapper--blazy');
$this
->assertSession()
->elementContains('css', '.media-wrapper--blazy', 'b-lazy');
$this
->assertSession()
->elementNotContains('css', '.media-wrapper--blazy', 'data-unblazy');
$result = $this
->assertSession()
->waitForElement('css', '.b-loaded');
$this
->assertNotEmpty($result);
$this
->createScreenshot($image_path . '/3_blazy_filter_loaded.png');
}
}