3 namespace Drupal\pathauto\Tests;
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\comment\Tests\CommentTestTrait;
9 * Tests pathauto settings form.
13 class PathautoEnablingEntityTypesTest extends WebTestBase {
15 use PathautoTestHelperTrait;
23 public static $modules = array('node', 'pathauto', 'comment');
28 * @var \Drupal\user\UserInterface
38 $this->drupalCreateContentType(array('type' => 'article'));
39 $this->addDefaultCommentField('node', 'article');
42 'administer pathauto',
43 'administer url aliases',
48 $this->adminUser = $this->drupalCreateUser($permissions);
49 $this->drupalLogin($this->adminUser);
53 * A suite of tests to verify if the feature to enable and disable the
54 * ability to define alias patterns for a given entity type works. Test with
55 * the comment module, as it is not enabled by default.
57 function testEnablingEntityTypes() {
58 // Verify that the comment entity type is not available when trying to add
59 // a new pattern, nor "broken".
60 $this->drupalGet('/admin/config/search/path/patterns/add');
61 $this->assertEqual(count($this->cssSelect('option[value = "canonical_entities:comment"]:contains(Comment)')), 0);
62 $this->assertEqual(count($this->cssSelect('option:contains(Broken)')), 0);
64 // Enable the entity type and create a pattern for it.
65 $this->drupalGet('/admin/config/search/path/settings');
67 'enabled_entity_types[comment]' => TRUE,
69 $this->drupalPostForm(NULL, $edit, 'Save configuration');
70 $this->createPattern('comment', '/comment/[comment:body]');
72 // Create a node, a comment type and a comment entity.
73 $node = $this->drupalCreateNode(['type' => 'article']);
74 $this->drupalGet('/node/' . $node->id());
76 'comment_body[0][value]' => 'test-body',
78 $this->drupalPostForm(NULL, $edit, 'Save');
80 // Verify that an alias has been generated and that the type can no longer
82 $this->assertAliasExists(['alias' => '/comment/test-body']);
83 $this->drupalGet('/admin/config/search/path/settings');
84 $this->assertEqual(count($this->cssSelect('input[name = "enabled_entity_types[comment]"][disabled = "disabled"]')), 1);