View source
<?php
namespace Drupal\simplify\Tests;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\BrowserTestBase;
class PerVocabularySettingsTest extends BrowserTestBase {
public static $modules = [
'path',
'taxonomy',
'simplify',
];
public static function getInfo() {
return [
'name' => 'Simplify per taxonomy settings test.',
'description' => 'Test the Simplify per taxonomy settings.',
'group' => 'Simplify',
];
}
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer url aliases',
'administer taxonomy',
'administer simplify',
]);
$this
->drupalLogin($admin_user);
$vocabulary = Vocabulary::create([
'name' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'vid' => 'testing_vocabulary',
]);
$vocabulary
->save();
}
public function testSettingSaving() {
$this
->drupalGet("/admin/structure/taxonomy/manage/testing_vocabulary/add");
$this
->assertRaw('About text formats', 'Term edit text format option is defined.');
$this
->assertRaw('Relations', 'Term Relations option is defined.');
$this
->assertRaw('URL alias', 'Term URL alias option is defined.');
$this
->drupalGet('/admin/config/user-interface/simplify');
$options = [
'simplify_admin' => TRUE,
'simplify_taxonomies_global[format]' => 'format',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save configuration'));
$this
->drupalGet('/admin/structure/taxonomy/manage/testing_vocabulary');
$this
->assertFieldChecked('edit-simplify-taxonomies-format', 'Vocabulary text fomat selection option is checked.');
$this
->assertNoFieldChecked('edit-simplify-taxonomies-relations', 'Vocabulary relations option is not checked.');
$this
->assertNoFieldChecked('edit-simplify-taxonomies-path', 'Vocabulary Path settings option is not checked.');
$text_format = $this
->xpath('//input[@name="simplify_taxonomies[format]" and @disabled="disabled"]');
$this
->assertTrue(count($text_format) === 1, 'Vocabulary text format option is disabled.');
$text_format = $this
->xpath('//input[@name="simplify_taxonomies[relations]" and @disabled="disabled"]');
$this
->assertTrue(count($text_format) === 0, 'Vocabulary relations option is not disabled.');
$text_format = $this
->xpath('//input[@name="simplify_taxonomies[path]" and @disabled="disabled"]');
$this
->assertTrue(count($text_format) === 0, 'Vocabulary URL alias option is not disabled.');
$options = [
'simplify_taxonomies[relations]' => 'relations',
'simplify_taxonomies[path]' => 'path',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save'));
$this
->drupalGet('/admin/structure/taxonomy/manage/testing_vocabulary');
$this
->assertFieldChecked('edit-simplify-taxonomies-relations', 'Vocabulary relations option is checked.');
$this
->assertFieldChecked('edit-simplify-taxonomies-path', 'Vocabulary URL alias option is checked.');
$this
->drupalGet("/admin/structure/taxonomy/manage/testing_vocabulary/add");
$this
->assertNoRaw('About text formats', 'Term edit text format option is not defined.');
$this
->assertNoRaw('Relations', 'Term Relations option is not defined.');
$this
->assertNoRaw('URL alias', 'Term URL alias option is not defined.');
}
}