ResponsivePreview.php in Thunder 8.5
File
tests/src/FunctionalJavascript/Integration/ResponsivePreview.php
View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript\Integration;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase;
class ResponsivePreview extends ThunderJavascriptTestBase {
public function testDevicePreview() {
$assert_session = $this
->assertSession();
$session = $this
->getSession();
$this
->drupalGet('news');
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertTrue($session
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/news')"));
$current_width = $session
->evaluateScript("jQuery('#responsive-preview-frame').width()");
$current_height = $session
->evaluateScript("jQuery('#responsive-preview-frame').height()");
$this
->changeDeviceRotation();
$assert_session
->elementExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertEqual($current_height, $session
->evaluateScript("jQuery('#responsive-preview-frame').width()"));
$this
->assertEqual($current_width, $session
->evaluateScript("jQuery('#responsive-preview-frame').height()"));
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[last()]');
$assert_session
->elementExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->changeDeviceRotation();
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->getSession()
->getPage()
->find('xpath', '//*[@id="responsive-preview-close"]')
->click();
$this
->getSession()
->wait(5000, "jQuery('#responsive-preview').length === 0");
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview"]');
$this
->drupalGet('node/8/edit');
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->assertNotEqual(-1, $session
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.indexOf('/node/preview/')"));
$this
->changeDeviceRotation();
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->getSession()
->wait(5000, "jQuery('#responsive-preview').length === 0");
$assert_session
->elementNotExists('xpath', '//*[@id="responsive-preview"]');
}
protected function changeDeviceRotation() {
$this
->getSession()
->getPage()
->find('xpath', '//*[@id="responsive-preview-orientation"]')
->click();
$this
->assertSession()
->assertWaitOnAjaxRequest();
}
protected function selectDevice($xpath_device_button) {
$page = $this
->getSession()
->getPage();
$page
->find('xpath', '//*[@id="responsive-preview-toolbar-tab"]/button')
->click();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$page
->find('xpath', $xpath_device_button)
->click();
$this
->assertSession()
->assertWaitOnAjaxRequest();
}
}