View source
<?php
namespace Drupal\Tests\metatag_async_widget\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class MetatagAsyncWidgetTest extends WebDriverTestBase {
protected static $modules = [
'field_ui',
'metatag_async_widget',
'node',
'block',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$name = $this
->randomMachineName() . ' ' . $this
->randomMachineName();
$this
->drupalCreateContentType([
'type' => 'metatag_node',
'name' => $name,
]);
$this
->drupalLogin($this
->drupalCreateUser([
'administer content types',
'administer nodes',
'administer node fields',
'bypass node access',
'administer node form display',
]));
}
public function testMetatagAsyncWidgetStark() {
$this
->doTestMetatagAsyncWidget('//li[contains(@class, "vertical-tabs__menu-item")]/a/strong[text()="Meta tags"]');
}
public function testMetatagAsyncWidgetSeven() {
\Drupal::service('theme_installer')
->install([
'seven',
]);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'seven')
->save();
$this
->rebuildAll();
$this
->doTestMetatagAsyncWidget('//div[@id="edit-advanced"]/details/summary/span[text()="Meta tags"]');
}
public function testMetatagAsyncWidgetClaro() {
if (!\Drupal::service('extension.list.theme')
->exists('claro')) {
$this
->markTestSkipped('The Claro theme does not exist');
}
\Drupal::service('theme_installer')
->install([
'claro',
]);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'claro')
->save();
$this
->rebuildAll();
$this
->doTestMetatagAsyncWidget('//div[@id="edit-advanced"]/details/summary[text()="Meta tags"]');
}
public function testMetatagAsyncWidgetBartik() {
if (!\Drupal::service('extension.list.theme')
->exists('bartik')) {
$this
->markTestSkipped('The Bartik theme does not exist');
}
\Drupal::service('theme_installer')
->install([
'bartik',
]);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'bartik')
->save();
$this
->rebuildAll();
$this
->doTestMetatagAsyncWidget('//li[contains(@class, "vertical-tabs__menu-item")]/a/strong[text()="Meta tags"]');
}
public function doTestMetatagAsyncWidget($metatag_details_xpath) {
$assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/structure/types/manage/metatag_node/fields/add-field');
$assert
->fieldExists('new_storage_type')
->setValue('metatag');
$assert
->waitForField('label');
$assert
->fieldExists('label')
->setValue('Meta tags');
$assert
->waitForText('Machine name');
$page
->pressButton('Save and continue');
$page
->pressButton('Save field settings');
$page
->pressButton('Save settings');
$this
->drupalGet('admin/structure/types/manage/metatag_node/form-display');
$assert
->fieldExists('edit-fields-field-meta-tags-type')
->setValue('metatag_async_widget_firehose');
$assert
->assertWaitOnAjaxRequest();
$page
->pressButton('Save');
$assert
->pageTextContains('Your settings have been saved.');
$this
->drupalGet('node/add/metatag_node');
$assert
->fieldExists('edit-title-0-value')
->setValue($this
->getRandomGenerator()
->sentences('4'));
$assert
->fieldNotExists('field_meta_tags[0][basic][abstract]');
$assert
->waitForElement('xpath', $metatag_details_xpath)
->click();
$assert
->waitForButton('Customize meta tags')
->click();
$assert
->waitForText('Configure the meta tags below.');
$assert
->pageTextContains('Configure the meta tags below.');
$selector = substr($metatag_details_xpath, strrpos($metatag_details_xpath, '/') + 1);
$this
->htmlOutput();
$assert
->elementsCount('xpath', '//' . $selector, 1);
$abstract = $this
->getRandomGenerator()
->sentences(10);
$field = $assert
->fieldExists('field_meta_tags[0][basic][abstract]');
$this
->assertRegExp('/^edit-field-meta-tags-0-basic-abstract--([a-zA-Z0-9_-])*$/', $field
->getAttribute('id'));
$field
->setValue($abstract);
$page
->pressButton('Save');
sleep(1);
$assert
->waitForLink('Edit')
->click();
$assert
->fieldNotExists('field_meta_tags[0][basic][abstract]');
$assert
->waitForElement('xpath', $metatag_details_xpath)
->click();
$assert
->waitForButton('Customize meta tags')
->click();
$assert
->waitForText('Configure the meta tags below.');
$assert
->fieldValueEquals('field_meta_tags[0][basic][abstract]', $abstract);
}
}