Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / Tests / PathautoEnablingEntityTypesTest.php
1 <?php
2
3 namespace Drupal\pathauto\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6 use Drupal\comment\Tests\CommentTestTrait;
7
8 /**
9  * Tests pathauto settings form.
10  *
11  * @group pathauto
12  */
13 class PathautoEnablingEntityTypesTest extends WebTestBase {
14
15   use PathautoTestHelperTrait;
16
17   use CommentTestTrait;
18
19   /**
20    * Modules to enable.
21    *
22    * @var array
23    */
24   public static $modules = array('node', 'pathauto', 'comment');
25
26   /**
27    * Admin user.
28    *
29    * @var \Drupal\user\UserInterface
30    */
31   protected $adminUser;
32
33   /**
34    * {@inheritdoc}
35    */
36   function setUp() {
37     parent::setUp();
38
39     $this->drupalCreateContentType(array('type' => 'article'));
40     $this->addDefaultCommentField('node', 'article');
41
42     $permissions = array(
43       'administer pathauto',
44       'administer url aliases',
45       'create url aliases',
46       'administer nodes',
47       'post comments',
48     );
49     $this->adminUser = $this->drupalCreateUser($permissions);
50     $this->drupalLogin($this->adminUser);
51   }
52
53   /**
54    * A suite of tests to verify if the feature to enable and disable the
55    * ability to define alias patterns for a given entity type works. Test with
56    * the comment module, as it is not enabled by default.
57    */
58   function testEnablingEntityTypes() {
59     // Verify that the comment entity type is not available when trying to add
60     // a new pattern, nor "broken".
61     $this->drupalGet('/admin/config/search/path/patterns/add');
62     $this->assertEqual(count($this->cssSelect('option[value = "canonical_entities:comment"]:contains(Comment)')), 0);
63     $this->assertEqual(count($this->cssSelect('option:contains(Broken)')), 0);
64
65     // Enable the entity type and create a pattern for it.
66     $this->drupalGet('/admin/config/search/path/settings');
67     $edit = [
68       'enabled_entity_types[comment]' => TRUE,
69     ];
70     $this->drupalPostForm(NULL, $edit, 'Save configuration');
71     $this->createPattern('comment', '/comment/[comment:body]');
72
73     // Create a node, a comment type and a comment entity.
74     $node = $this->drupalCreateNode(['type' => 'article']);
75     $this->drupalGet('/node/' . $node->id());
76     $edit = [
77       'comment_body[0][value]' => 'test-body',
78     ];
79     $this->drupalPostForm(NULL, $edit, 'Save');
80
81     // Verify that an alias has been generated and that the type can no longer
82     // be disabled.
83     $this->assertAliasExists(['alias' => '/comment/test-body']);
84     $this->drupalGet('/admin/config/search/path/settings');
85     $this->assertEqual(count($this->cssSelect('input[name = "enabled_entity_types[comment]"][disabled = "disabled"]')), 1);
86   }
87
88 }