Interim commit.
[yaffs-website] / web / modules / contrib / blazy / tests / src / FunctionalJavascript / BlazyJavaScriptTest.php
1 <?php
2
3 namespace Drupal\Tests\blazy\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6 use Drupal\Tests\blazy\Traits\BlazyUnitTestTrait;
7 use Drupal\Tests\blazy\Traits\BlazyCreationTestTrait;
8
9 /**
10  * Tests the Blazy JavaScript using PhantomJS.
11  *
12  * @group blazy
13  */
14 class BlazyJavaScriptTest extends JavascriptTestBase {
15
16   use BlazyUnitTestTrait;
17   use BlazyCreationTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = [
23     'field',
24     'filter',
25     'image',
26     'node',
27     'text',
28     'blazy',
29   ];
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36
37     $this->setUpVariables();
38
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';
46
47     $this->setUpContentTypeTest($bundle);
48     $this->setUpFormatterDisplay($bundle, $data);
49   }
50
51   /**
52    * Test the Blazy element from loading to loaded states.
53    */
54   public function testFormatterDisplay() {
55     $session    = $this->getSession();
56     $image_path = $this->getImagePath(TRUE);
57     $bundle     = $this->bundle;
58
59     $this->setUpContentWithItems($bundle);
60     $this->drupalGet('node/' . $this->entity->id());
61
62     // Capture the loading moment.
63     $this->createScreenshot($image_path . '/1_blazy_loading.png');
64
65     // Wait a moment.
66     $session->wait(1000);
67
68     // Trigger Blazy to load images by scrolling down window.
69     $session->executeScript('window.scrollTo(0, document.body.scrollHeight);');
70
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.');
74
75     // Wait a moment.
76     $session->wait(10000);
77
78     // Capture the loaded moment, only images within viewport are loaded here.
79     $this->createScreenshot($image_path . '/2_blazy_loaded.png');
80   }
81
82 }