You are here

public function ResponsivePreview::testDevicePreview in Thunder 8.5

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()
  2. 8.3 tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()
  3. 8.4 tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()
  4. 6.2.x tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()
  5. 6.0.x tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()
  6. 6.1.x tests/src/FunctionalJavascript/Integration/ResponsivePreview.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ResponsivePreview::testDevicePreview()

Testing integration of "responsive_preview" module.

File

tests/src/FunctionalJavascript/Integration/ResponsivePreview.php, line 17

Class

ResponsivePreview
Tests the device preview functionality integration.

Namespace

Drupal\Tests\thunder\FunctionalJavascript\Integration

Code

public function testDevicePreview() {

  /** @var \Drupal\FunctionalJavascriptTests\WebDriverWebAssert $assert_session */
  $assert_session = $this
    ->assertSession();

  /** @var \Behat\Mink\Session $session */
  $session = $this
    ->getSession();

  // Check channel page.
  $this
    ->drupalGet('news');

  // The selection of device should create overlay with iframe to news page.
  $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')"));

  // Clicking of rotate should rotate iframe sizes.
  $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()"));

  // Switching of device should keep rotation.
  $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")]');

  // Clicking on preview close, should remove overlay.
  $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');

  // Using preview on entity edit should use preview page.
  $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();

  // Un-checking device from dropdown should turn off preview.
  $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"]');
}