3 namespace Drupal\Tests\blazy\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6 use Drupal\Tests\blazy\Traits\BlazyUnitTestTrait;
7 use Drupal\Tests\blazy\Traits\BlazyCreationTestTrait;
10 * Tests the Blazy JavaScript using PhantomJS.
14 class BlazyJavaScriptTest extends JavascriptTestBase {
16 use BlazyUnitTestTrait;
17 use BlazyCreationTestTrait;
22 public static $modules = [
34 protected function setUp() {
37 $this->setUpVariables();
39 $this->entityManager = $this->container->get('entity.manager');
40 $this->entityFieldManager = $this->container->get('entity_field.manager');
41 $this->formatterPluginManager = $this->container->get('plugin.manager.field.formatter');
42 $this->blazyAdmin = $this->container->get('blazy.admin');
43 $this->blazyManager = $this->container->get('blazy.manager');
44 $bundle = $this->bundle;
45 $data['settings']['ratio'] = '16:9';
47 $this->setUpContentTypeTest($bundle);
48 $this->setUpFormatterDisplay($bundle, $data);
52 * Test the Blazy element from loading to loaded states.
54 public function testFormatterDisplay() {
55 $session = $this->getSession();
56 $image_path = $this->getImagePath(TRUE);
57 $bundle = $this->bundle;
59 $this->setUpContentWithItems($bundle);
60 $this->drupalGet('node/' . $this->entity->id());
62 // Capture the loading moment.
63 $this->createScreenshot($image_path . '/1_blazy_loading.png');
68 // Trigger Blazy to load images by scrolling down window.
69 $session->executeScript('window.scrollTo(0, document.body.scrollHeight);');
71 // Wait for the loaded images, at least one will do dependent on viewport.
72 $loaded = $this->assertSession()->waitForElement('css', '.b-loaded');
73 $this->assertNotEmpty($loaded, 'Blazy image is loaded, one or more.');
76 $session->wait(10000);
78 // Capture the loaded moment, only images within viewport are loaded here.
79 $this->createScreenshot($image_path . '/2_blazy_loaded.png');