View source
<?php
namespace Drupal\Tests\conditional_fields\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
abstract class ConditionalFieldTestBase extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $screenshotPath = 'sites/simpletest/conditional_fields/';
public static $modules = [
'conditional_fields',
'node',
'datetime',
'field_ui',
'taxonomy',
];
protected function setUp() {
parent::setUp();
if ($this->profile != 'standard') {
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
}
$this
->checkScreenshotPathExist();
}
private function checkScreenshotPathExist() {
if (file_exists($this->screenshotPath)) {
return;
}
mkdir($this->screenshotPath, 0777, TRUE);
}
protected function waitUntilVisible($selector, $timeout = 1000, $message = '') {
$condition = "jQuery('{$selector}').is(':visible');console.log(jQuery('{$selector}'))";
$this
->assertJsCondition($condition, $timeout, $message);
}
protected function waitUntilHidden($selector, $timeout = 1000, $message = '') {
$condition = "jQuery('{$selector}').is(':hidden');";
$this
->assertJsCondition($condition, $timeout, $message);
}
protected function changeField($selector, $value = '') {
$this
->getSession()
->executeScript("jQuery('" . $selector . "').val('" . $value . "').trigger('keyup').trigger('change');");
}
protected function changeSelect($selector, $value = '') {
$this
->getSession()
->executeScript("jQuery('" . $selector . "').val('" . $value . "').trigger('click').trigger('change');");
}
protected function createCondition($dependent, $dependee, $state, $condition) {
$edit = [
'table[add_new_dependency][dependent][]' => $dependent,
'table[add_new_dependency][dependee]' => $dependee,
'table[add_new_dependency][state]' => $state,
'table[add_new_dependency][condition]' => $condition,
];
$this
->submitForm($edit, 'Add dependency');
}
protected function baseTestSteps() {
$admin_account = $this
->createUser([
'view conditional fields',
'edit conditional fields',
'delete conditional fields',
'administer nodes',
'create article content',
'administer content types',
]);
$this
->drupalLogin($admin_account);
$this
->drupalGet('admin/structure/conditional_fields');
$this
->assertSession()
->pageTextContains('Content');
$this
->assertSession()
->linkByHrefExists('/admin/structure/conditional_fields/node');
$this
->drupalGet('admin/structure/conditional_fields/node');
$this
->assertSession()
->pageTextContains('Article');
$this
->assertSession()
->linkByHrefExists('admin/structure/conditional_fields/node/article');
$this
->drupalGet('admin/structure/conditional_fields/node/article');
$this
->assertSession()
->pageTextContains('Target field');
}
}