Skip to content
Snippets Groups Projects
Commit f93d9a39 authored by catch's avatar catch
Browse files

Issue #3227161 by dww, xjm, longwave, Wim Leers, paulocs, lauriii, Berdir:...

Issue #3227161 by dww, xjm, longwave, Wim Leers, paulocs, lauriii, Berdir: Stop using Quick Edit data attributes as selectors in tests that are not testing Quick Edit
parent 8ce891e4
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ class NodeDisplayConfigurableTest extends NodeTestBase {
*
* @var array
*/
protected static $modules = ['quickedit', 'rdf', 'block'];
protected static $modules = ['rdf', 'block'];
/**
* {@inheritdoc}
......@@ -61,7 +61,6 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
$node_type->save();
$user = $this->drupalCreateUser([
'access in-place editing',
'administer nodes',
], $this->randomMachineName(14));
$this->drupalLogin($user);
......@@ -70,7 +69,7 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
// Check the node with Drupal default non-configurable display.
$this->drupalGet($node->toUrl());
$this->assertNodeHtml($node, $user, 'span', $metadata_region, $field_classes);
$this->assertNodeHtml($node, $user, TRUE, $metadata_region, $field_classes);
// Enable module to make base fields' displays configurable.
\Drupal::service('module_installer')->install(['node_display_configurable_test']);
......@@ -88,7 +87,9 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
// Recheck the node with configurable display.
$this->drupalGet($node->toUrl());
$this->assertNodeHtml($node, $user, 'div', $metadata_region, $field_classes);
$this->assertNodeHtml($node, $user, FALSE, $metadata_region, $field_classes);
$assert->elementExists('css', 'div[rel="schema:author"]');
// Remove from display.
$display->removeComponent('uid')
......@@ -96,8 +97,8 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
->save();
$this->drupalGet($node->toUrl());
$assert->elementNotExists('css', 'div[data-quickedit-field-id="node/1/uid/en/full"]');
$assert->elementTextNotContains('css', 'article[data-quickedit-entity-id="node/1"]', $user->getAccountName());
$assert->elementNotExists('css', 'div[rel="schema:author"]');
$assert->elementTextNotContains('css', 'article', $user->getAccountName());
}
/**
......@@ -107,31 +108,48 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
* The node being tested.
* @param \Drupal\user\UserInterface $user
* The logged in user.
* @param string $html_element
* Either 'div' or 'span'
* @param bool $is_inline
* Whether the fields are rendered inline or not.
* @param string $metadata_region
* The region of the node html content where meta data is expected.
* @param bool $field_classes
* If TRUE, check for field--name-XXX classes.
*/
protected function assertNodeHtml(NodeInterface $node, UserInterface $user, string $html_element, string $metadata_region, bool $field_classes) {
protected function assertNodeHtml(NodeInterface $node, UserInterface $user, bool $is_inline, string $metadata_region, bool $field_classes) {
$assert = $this->assertSession();
$title_selector = 'h1 span' . ($field_classes ? '.field--name-title' : '') . '[data-quickedit-field-id="node/1/title/en/full"]';
$created_selector = 'article[data-quickedit-entity-id="node/1"] ' . $html_element . ($field_classes ? '.field--name-created' : '') . '[data-quickedit-field-id="node/1/created/en/full"]';
$uid_selector = 'article[data-quickedit-entity-id="node/1"] ' . $html_element . ($field_classes ? '.field--name-uid' : '') . '[data-quickedit-field-id="node/1/uid/en/full"]';
$html_element = $is_inline ? 'span' : 'div';
$title_selector = 'h1 span' . ($field_classes ? '.field--name-title' : '');
$assert->elementTextContains('css', $title_selector, $node->getTitle());
$assert->elementTextContains('css', $created_selector, \Drupal::service('date.formatter')->format($node->getCreatedTime()));
if ($html_element === 'div') {
// With field classes, the selector can be very specific.
if ($field_classes) {
$created_selector = 'article ' . $html_element . '.field--name-created';
$assert->elementTextContains('css', $created_selector, \Drupal::service('date.formatter')->format($node->getCreatedTime()));
}
else {
// When field classes aren't available, use HTML elements for testing.
$formatted_time = \Drupal::service('date.formatter')->format($node->getCreatedTime());
if ($is_inline) {
$created_selector = sprintf('//article//%s//%s[text()="%s"]', $metadata_region, $html_element, $formatted_time);
}
else {
$created_selector = sprintf('//article//%s[text()="%s"]', $html_element, $formatted_time);
}
$assert->elementExists('xpath', $created_selector);
}
$uid_selector = 'article ' . $html_element . ($field_classes ? '.field--name-uid' : '');
if (!$is_inline) {
$field_classes_selector = $field_classes ? "[contains(concat(' ', normalize-space(@class), ' '), ' field--name-uid ')]" : '';
$assert->elementExists('xpath', sprintf('//article//%s//*%s//%s[text()="Authored by"]', $html_element, $field_classes_selector, $html_element));
$assert->elementTextContains('css', "$uid_selector $html_element" . '[rel="schema:author"]', $user->getAccountName());
$assert->elementNotExists('css', "$uid_selector a");
$assert->elementTextContains('css', "$uid_selector $html_element", 'Authored by');
$assert->elementExists('css', 'span[property="schema:dateCreated"]');
}
else {
$assert->elementTextContains('css', $uid_selector . ' a[property="schema:name"]', $user->getAccountName());
$assert->elementTextContains('css', 'article[data-quickedit-entity-id="node/1"] ' . $metadata_region, 'Submitted by');
$assert->elementTextContains('css', 'article ' . $metadata_region, 'Submitted by');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment