View source
<?php
namespace Drupal\Tests\name\Functional;
use Drupal\Tests\BrowserTestBase;
abstract class NameTestBase extends BrowserTestBase {
protected $defaultTheme = 'stable';
public static $modules = [
'field',
'field_ui',
'node',
'name',
];
protected $webUser;
protected $adminUser;
public function setUp() {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([]);
$this->adminUser = $this
->drupalCreateUser([
'administer site configuration',
'administer content types',
'access content',
'access administration pages',
'administer node fields',
]);
}
protected function assertNoFieldCheckedByName($name, $message = '') {
$elements = $this
->xpath('//input[@name=:name]', [
':name' => $name,
]);
return $this
->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @name is not checked.', [
'@name' => $name,
]), t('Browser'));
}
protected function assertFieldCheckedByName($name, $message = '') {
$elements = $this
->xpath('//input[@name=:name]', [
':name' => $name,
]);
return $this
->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @name is checked.', [
'@name' => $name,
]), t('Browser'));
}
protected function assertNameFormat($name_components, $type, $object, $format, $expected, array $options = []) {
$this
->assertNameFormats($name_components, $type, $object, [
$format => $expected,
], $options);
}
protected function assertNameFormats($name_components, $type, $object, array $names, array $options = []) {
foreach ($names as $format => $expected) {
$value = \Drupal::service('name.format_parser')
->parse($name_components, $format);
$this
->assertIdentical($value, $expected, t("Name value for '@name' was '@actual', expected value '@expected'. Components were: %components", [
'@name' => $format,
'@actual' => $value,
'@expected' => $expected,
'%components' => implode(' ', $name_components),
]));
}
}
}