ResponsivePreviewTest.php in Responsive Theme Preview 8
File
tests/src/FunctionalJavascript/ResponsivePreviewTest.php
View source
<?php
namespace Drupal\Tests\responsive_preview\FunctionalJavascript;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
class ResponsivePreviewTest extends WebDriverTestBase {
protected static $modules = [
'entity_test',
'node',
'responsive_preview',
'toolbar',
];
protected $defaultTheme = 'stark';
protected $previewUser;
public function setUp() {
parent::setUp();
NodeType::create([
'type' => 'article',
'name' => 'Article',
])
->save();
$this->previewUser = $this
->drupalCreateUser([
'access responsive preview',
'access toolbar',
'view test entity',
'administer entity_test content',
'create article content',
'edit own article content',
]);
}
public function testToolbarIntegration() {
$entity = EntityTest::create();
$entity->name->value = $this
->randomMachineName();
$entity
->save();
$this
->drupalLogin($this->previewUser);
$this
->drupalGet($entity
->toUrl());
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->assertSession()
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertTrue($this
->getSession()
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/entity_test/1')"));
}
public function testContentEdit() {
$this
->drupalLogin($this->previewUser);
$node = Node::create([
'type' => 'article',
'uid' => $this->previewUser
->id(),
'title' => $this
->randomString(),
]);
$node
->save();
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]');
$this
->assertSession()
->elementNotExists('xpath', '//*[@id="responsive-preview-orientation" and contains(@class, "rotated")]');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertTrue($this
->getSession()
->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/node/preview/" . $node
->uuid() . "/full')"));
}
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();
}
}