View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript;
class ModuleIntegrationTest extends ThunderJavascriptTestBase {
use ThunderParagraphsTestTrait;
use ThunderArticleTestTrait;
use ThunderMetaTagTrait;
protected static $previousTextColumn = 3;
protected static $newTextColumn = 6;
protected function validateDiff($fieldName, array $previous = [], array $previousHighlighted = [], array $new = [], array $newHighlighted = []) {
$this
->checkFullText($fieldName, static::$previousTextColumn, $previous);
$this
->checkFullText($fieldName, static::$newTextColumn, $new);
$this
->checkHighlightedText($fieldName, static::$previousTextColumn, $previousHighlighted);
$this
->checkHighlightedText($fieldName, static::$newTextColumn, $newHighlighted);
}
protected function checkFullText($fieldName, $columnIndex, array $textRows = []) {
$page = $this
->getSession()
->getPage();
foreach ($textRows as $indexRow => $expectedText) {
$previousText = $page
->find('xpath', "//tr[./td[text()=\"{$fieldName}\"]]/following-sibling::tr[{$indexRow}]/td[{$columnIndex}]")
->getText();
$this
->assertEquals($expectedText, htmlspecialchars_decode($previousText, ENT_QUOTES | ENT_HTML401));
}
}
protected function checkHighlightedText($fieldName, $columnIndex, array $highlightedTextRows) {
$page = $this
->getSession()
->getPage();
foreach ($highlightedTextRows as $indexRow => $expectedTexts) {
foreach ($expectedTexts as $indexHighlighted => $expectedText) {
$highlightedText = $page
->find('xpath', "//tr[./td[text()=\"{$fieldName}\"]]/following-sibling::tr[{$indexRow}]/td[{$columnIndex}]/span[" . ($indexHighlighted + 1) . "]")
->getText();
$this
->assertEquals($expectedText, htmlspecialchars_decode($highlightedText, ENT_QUOTES | ENT_HTML401));
}
}
}
public function testDiffModule() {
$node = $this
->loadNodeByUuid('36b2e2b2-3df0-43eb-a282-d792b0999c07');
$this
->drupalGet($node
->toUrl('edit-form'));
$page = $this
->getSession()
->getPage();
$teaserField = $page
->find('xpath', '//*[@data-drupal-selector="edit-field-teaser-text-0-value"]');
$initialTeaserText = $teaserField
->getValue();
$teaserText = 'Start with Text. ' . $initialTeaserText . ' End with Text.';
$teaserField
->setValue($teaserText);
$this
->clickButtonDrupalSelector($page, 'edit-field-teaser-media-current-items-0-remove-button');
$media1 = $this
->loadMediaByUuid('17965877-27b2-428f-8b8c-7dccba9786e5');
$this
->selectMedia('field_teaser_media', 'image_browser', [
'media:' . $media1
->id(),
]);
$newParagraphText = 'One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them!';
$this
->addTextParagraph('field_paragraphs', $newParagraphText);
$media2 = $this
->loadMediaByUuid('5d719c64-7f32-4062-9967-9874f5ca3eba');
$this
->addImageParagraph('field_paragraphs', [
'media:' . $media2
->id(),
]);
$this
->clickSave();
$this
->drupalGet($node
->toUrl('version-history'));
$firstRightRadio = $page
->find('xpath', '//table[contains(@class, "diff-revisions")]/tbody//tr[1]//input[@name="radios_right"]');
$firstRightRadio
->click();
$lastLeftRadio = $page
->find('xpath', '//table[contains(@class, "diff-revisions")]/tbody//tr[last()]//input[@name="radios_left"]');
$lastLeftRadio
->click();
$page
->find('xpath', '//*[@data-drupal-selector="edit-submit"]')
->click();
$this
->validateDiff('Teaser Text', [
'1' => $initialTeaserText,
], [], [
'1' => $teaserText,
], [
'1' => [
'Start with Text.',
'. End with Text',
],
]);
$this
->validateDiff('Teaser Media', [
'1' => 'DrupalCon Logo',
], [
'1' => [
'DrupalCon Logo',
],
], [
'1' => 'Thunder',
], [
'1' => [
'Thunder',
],
]);
$this
->validateDiff('Paragraphs > Text', [
'1' => '',
], [], [
'1' => '<p>' . $newParagraphText . '</p>',
'2' => '',
], []);
$this
->validateDiff('Paragraphs > Image', [
'1' => '',
], [], [
'1' => 'Thunder City',
], []);
}
public function testFacebookMetaTags() {
$facebookMetaTags = $this
->generateMetaTagConfiguration([
[
'facebook fb:admins' => 'zuck',
'facebook fb:pages' => 'some-fancy-fb-page-url',
'facebook fb:app_id' => '1121151812167212,1121151812167213',
],
]);
$fieldValues = $this
->generateMetaTagFieldValues($facebookMetaTags, 'field_meta_tags[0]');
$term = $this
->loadTermByUuid('bfc251bc-de35-467d-af44-1f7a7012b845');
$fieldValues += [
'field_channel' => $term
->id(),
'title[0][value]' => 'Test FB MetaTags Article',
'field_seo_title[0][value]' => 'Facebook MetaTags',
'field_teaser_text[0][value]' => 'Facebook MetaTags Testing',
];
$this
->articleFillNew($fieldValues);
$this
->clickSave();
$this
->checkMetaTags($facebookMetaTags);
}
public function testContentLock() {
$node = $this
->loadNodeByUuid('0bd5c257-2231-450f-b4c2-ab156af7b78d');
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->assertSession()
->pageTextContains('This content is now locked against simultaneous editing. This content will remain locked if you navigate away from this page without saving or unlocking it.');
$page = $this
->getSession()
->getPage();
$page
->find('xpath', '//*[@id="edit-unlock"]')
->click();
$page
->find('xpath', '//*[@id="edit-submit"]')
->click();
$this
->assertSession()
->pageTextContains('Lock broken. Anyone can now edit this content.');
$this
->drupalGet($node
->toUrl('edit-form'));
$loggedInUser = $this->loggedInUser
->label();
$this
->drupalLogout();
$this
->logWithRole(static::$defaultUserRole);
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->assertSession()
->pageTextContains('This content is being edited by the user ' . $loggedInUser . ' and is therefore locked to prevent other users changes.');
}
}