Skip to content
Snippets Groups Projects
Commit c89e9af8 authored by Pravin Gaikwad's avatar Pravin Gaikwad
Browse files

Issue #3434218 by Rajeshreeputra: Automated Drupal 11 compatibility fixes for responsive_preview

parent 9efe8053
Branches
Tags 2.2.0
1 merge request!19Fix phpunit test failure.
Pipeline #236410 passed with warnings
...@@ -30,7 +30,13 @@ class DeviceHtmlRouteProvider extends AdminHtmlRouteProvider { ...@@ -30,7 +30,13 @@ class DeviceHtmlRouteProvider extends AdminHtmlRouteProvider {
} }
/** /**
* {@inheritdoc} * ResponsivePreview constructor.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return Symfony\Component\Routing\Route|null
* returns route.
*/ */
protected function getCollectionRoute(EntityTypeInterface $entity_type): ?Route { protected function getCollectionRoute(EntityTypeInterface $entity_type): ?Route {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) { if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
......
...@@ -84,8 +84,7 @@ class ResponsivePreview { ...@@ -84,8 +84,7 @@ class ResponsivePreview {
} }
/** /**
* Determines wether the responsive preview should be shown and returns the * Helper to show responsive preview and returns the url for the preview.
* url for the preview.
*/ */
public function getPreviewUrl() { public function getPreviewUrl() {
// Determine if responsive preview should be available for this node type. // Determine if responsive preview should be available for this node type.
...@@ -133,6 +132,7 @@ class ResponsivePreview { ...@@ -133,6 +132,7 @@ class ResponsivePreview {
* *
* @return array * @return array
* A render array of enabled devices. * A render array of enabled devices.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/ */
......
...@@ -43,14 +43,10 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -43,14 +43,10 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
$this->assertSession()->titleEquals('Responsive preview device | Drupal'); $this->assertSession()->titleEquals('Responsive preview device | Drupal');
// Test for the table. // Test for the table.
// @todo fix failing test as part of #3359983
// $element = $this->xpath('//div[@class="layout-content"]//table');
$element = $this->xpath('//*[@id="edit-entities"]'); $element = $this->xpath('//*[@id="edit-entities"]');
$this->assertNotEmpty($element, 'Device entity list table found.'); $this->assertNotEmpty($element, 'Device entity list table found.');
// Test the table header. // Test the table header.
// @todo fix failing test as part of #3359983
// $elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
$elements = $this->xpath('//*[@id="edit-entities"]/thead/tr/th'); $elements = $this->xpath('//*[@id="edit-entities"]/thead/tr/th');
$this->assertEquals(count($elements), 5, 'Correct number of table header cells found.'); $this->assertEquals(count($elements), 5, 'Correct number of table header cells found.');
...@@ -89,7 +85,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -89,7 +85,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
'orientation' => 'portrait', 'orientation' => 'portrait',
]; ];
$this->drupalGet('admin/config/user-interface/responsive-preview/add'); $this->drupalGet('admin/config/user-interface/responsive-preview/add');
$this->submitForm($edit, $this->t('Save')); $this->submitForm($edit, 'Save');
$this->assertSession() $this->assertSession()
->responseContains($this->t('Device %name has been added.', ['%name' => 'Smartwatch'])); ->responseContains($this->t('Device %name has been added.', ['%name' => 'Smartwatch']));
$this->assertSession() $this->assertSession()
...@@ -97,7 +93,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -97,7 +93,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
// Ensures that is not possible to insert a non-unique device id. // Ensures that is not possible to insert a non-unique device id.
$this->drupalGet('admin/config/user-interface/responsive-preview/add'); $this->drupalGet('admin/config/user-interface/responsive-preview/add');
$this->submitForm($edit, $this->t('Save')); $this->submitForm($edit, 'Save');
$this->assertSession() $this->assertSession()
->responseContains($this->t('The machine-readable name is already in use. It must be unique.')); ->responseContains($this->t('The machine-readable name is already in use. It must be unique.'));
...@@ -112,7 +108,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -112,7 +108,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
]; ];
$this->drupalGet('admin/config/user-interface/responsive-preview/small/edit'); $this->drupalGet('admin/config/user-interface/responsive-preview/small/edit');
$this->submitForm($edit, $this->t('Save')); $this->submitForm($edit, 'Save');
$this->assertSession() $this->assertSession()
->responseContains($this->t('Device %name has been updated.', ['%name' => 'Smart phone updated'])); ->responseContains($this->t('Device %name has been updated.', ['%name' => 'Smart phone updated']));
$this->assertSession() $this->assertSession()
...@@ -121,7 +117,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -121,7 +117,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
// Tests the delete of a predefined devices. // Tests the delete of a predefined devices.
$this->drupalGet('admin/config/user-interface/responsive-preview/large/delete'); $this->drupalGet('admin/config/user-interface/responsive-preview/large/delete');
$this->submitForm([], $this->t('Delete')); $this->submitForm([], 'Delete');
$this->assertSession() $this->assertSession()
->responseContains($this->t('Device %name has been deleted.', ['%name' => 'Typical desktop'])); ->responseContains($this->t('Device %name has been deleted.', ['%name' => 'Typical desktop']));
$this->assertSession() $this->assertSession()
...@@ -134,7 +130,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase { ...@@ -134,7 +130,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
'entities[smartwatch][status]' => 0, 'entities[smartwatch][status]' => 0,
]; ];
$this->drupalGet('admin/config/user-interface/responsive-preview'); $this->drupalGet('admin/config/user-interface/responsive-preview');
$this->submitForm($edit, $this->t('Save')); $this->submitForm($edit, 'Save');
$this->assertSession() $this->assertSession()
->responseContains($this->t('The device settings have been updated.')); ->responseContains($this->t('The device settings have been updated.'));
$this->assertSession()->checkboxChecked('entities[medium][status]'); $this->assertSession()->checkboxChecked('entities[medium][status]');
......
...@@ -66,11 +66,10 @@ class ResponsivePreviewTest extends WebDriverTestBase { ...@@ -66,11 +66,10 @@ class ResponsivePreviewTest extends WebDriverTestBase {
$this->drupalGet($entity->toUrl()); $this->drupalGet($entity->toUrl());
$this->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]'); $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")]'); $element = $this->assertSession()->waitForElementVisible('css', '#responsive-preview-orientation');
$this->assertSession()->assertWaitOnAjaxRequest(); $this->assertStringNotContainsString('rotated', $element->getAttribute('class'));
// @todo fix failing test as part of #3359983 $this->assertTrue($this->getSession()->getDriver()->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/entity_test/1')"));
// $this->assertTrue($this->getSession()->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/entity_test/1')"));
} }
/** /**
...@@ -89,13 +88,12 @@ class ResponsivePreviewTest extends WebDriverTestBase { ...@@ -89,13 +88,12 @@ class ResponsivePreviewTest extends WebDriverTestBase {
$this->drupalGet('node/' . $node->id() . '/edit'); $this->drupalGet('node/' . $node->id() . '/edit');
$this->selectDevice('(//*[@id="responsive-preview-toolbar-tab"]//button[@data-responsive-preview-name])[1]'); $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")]'); $element = $this->assertSession()->waitForElementVisible('css', '#responsive-preview-orientation');
$this->assertSession()->assertWaitOnAjaxRequest(); $this->assertStringNotContainsString('rotated', $element->getAttribute('class'));
// @todo fix failing test as part of #3359983 $this->assertTrue($this->getSession()->getDriver()->evaluateScript(
// $this->assertTrue($this->getSession()->evaluateScript( "jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/node/preview/" . $node->uuid() . "/full')"
// "jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/node/preview/" . $node->uuid() . "/full')" ));
// ));
} }
/** /**
...@@ -109,12 +107,13 @@ class ResponsivePreviewTest extends WebDriverTestBase { ...@@ -109,12 +107,13 @@ class ResponsivePreviewTest extends WebDriverTestBase {
protected function selectDevice($xpath_device_button) { protected function selectDevice($xpath_device_button) {
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$page->find('xpath', '//*[@id="responsive-preview-toolbar-tab"]/button') $page->find('css', '#responsive-preview-toolbar-tab button')->click();
->click(); // Wait for the dropdown.
$this->assertSession()->assertWaitOnAjaxRequest(); $this->assertSession()->waitForElementVisible('css', '.responsive-preview-options');
$page->find('xpath', $xpath_device_button)->click(); $page->find('xpath', $xpath_device_button)->click();
$this->assertSession()->assertWaitOnAjaxRequest(); // Wait for the responsive preview iframe.
$this->assertSession()->waitForElementVisible('css', '#responsive-preview-frame');
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment