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
No related branches found
No related tags found
1 merge request!19Fix phpunit test failure.
Pipeline #236410 passed with warnings
......@@ -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 {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
......
......@@ -84,8 +84,7 @@ class ResponsivePreview {
}
/**
* Determines wether the responsive preview should be shown and returns the
* url for the preview.
* Helper to show responsive preview and returns the url for the preview.
*/
public function getPreviewUrl() {
// Determine if responsive preview should be available for this node type.
......@@ -133,6 +132,7 @@ class ResponsivePreview {
*
* @return array
* A render array of enabled devices.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
......
......@@ -43,14 +43,10 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
$this->assertSession()->titleEquals('Responsive preview device | Drupal');
// 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"]');
$this->assertNotEmpty($element, 'Device entity list table found.');
// 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');
$this->assertEquals(count($elements), 5, 'Correct number of table header cells found.');
......@@ -89,7 +85,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
'orientation' => 'portrait',
];
$this->drupalGet('admin/config/user-interface/responsive-preview/add');
$this->submitForm($edit, $this->t('Save'));
$this->submitForm($edit, 'Save');
$this->assertSession()
->responseContains($this->t('Device %name has been added.', ['%name' => 'Smartwatch']));
$this->assertSession()
......@@ -97,7 +93,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
// Ensures that is not possible to insert a non-unique device id.
$this->drupalGet('admin/config/user-interface/responsive-preview/add');
$this->submitForm($edit, $this->t('Save'));
$this->submitForm($edit, 'Save');
$this->assertSession()
->responseContains($this->t('The machine-readable name is already in use. It must be unique.'));
......@@ -112,7 +108,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
];
$this->drupalGet('admin/config/user-interface/responsive-preview/small/edit');
$this->submitForm($edit, $this->t('Save'));
$this->submitForm($edit, 'Save');
$this->assertSession()
->responseContains($this->t('Device %name has been updated.', ['%name' => 'Smart phone updated']));
$this->assertSession()
......@@ -121,7 +117,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
// Tests the delete of a predefined devices.
$this->drupalGet('admin/config/user-interface/responsive-preview/large/delete');
$this->submitForm([], $this->t('Delete'));
$this->submitForm([], 'Delete');
$this->assertSession()
->responseContains($this->t('Device %name has been deleted.', ['%name' => 'Typical desktop']));
$this->assertSession()
......@@ -134,7 +130,7 @@ class ResponsivePreviewAdminTest extends ResponsivePreviewTestBase {
'entities[smartwatch][status]' => 0,
];
$this->drupalGet('admin/config/user-interface/responsive-preview');
$this->submitForm($edit, $this->t('Save'));
$this->submitForm($edit, 'Save');
$this->assertSession()
->responseContains($this->t('The device settings have been updated.'));
$this->assertSession()->checkboxChecked('entities[medium][status]');
......
......@@ -66,11 +66,10 @@ class ResponsivePreviewTest extends WebDriverTestBase {
$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();
$element = $this->assertSession()->waitForElementVisible('css', '#responsive-preview-orientation');
$this->assertStringNotContainsString('rotated', $element->getAttribute('class'));
// @todo fix failing test as part of #3359983
// $this->assertTrue($this->getSession()->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/entity_test/1')"));
$this->assertTrue($this->getSession()->getDriver()->evaluateScript("jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/entity_test/1')"));
}
/**
......@@ -89,13 +88,12 @@ class ResponsivePreviewTest extends WebDriverTestBase {
$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();
$element = $this->assertSession()->waitForElementVisible('css', '#responsive-preview-orientation');
$this->assertStringNotContainsString('rotated', $element->getAttribute('class'));
// @todo fix failing test as part of #3359983
// $this->assertTrue($this->getSession()->evaluateScript(
// "jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/node/preview/" . $node->uuid() . "/full')"
// ));
$this->assertTrue($this->getSession()->getDriver()->evaluateScript(
"jQuery('#responsive-preview-frame')[0].contentWindow.location.href.endsWith('/node/preview/" . $node->uuid() . "/full')"
));
}
/**
......@@ -109,12 +107,13 @@ class ResponsivePreviewTest extends WebDriverTestBase {
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('css', '#responsive-preview-toolbar-tab button')->click();
// Wait for the dropdown.
$this->assertSession()->waitForElementVisible('css', '.responsive-preview-options');
$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