Version 1
[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   use CommentTestTrait;
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = array('node', 'pathauto', 'comment');
24
25   /**
26    * Admin user.
27    *
28    * @var \Drupal\user\UserInterface
29    */
30   protected $adminUser;
31
32   /**
33    * {inheritdoc}
34    */
35   function setUp() {
36     parent::setUp();
37
38     $this->drupalCreateContentType(array('type' => 'article'));
39     $this->addDefaultCommentField('node', 'article');
40
41     $permissions = array(
42       'administer pathauto',
43       'administer url aliases',
44       'create url aliases',
45       'administer nodes',
46       'post comments',
47     );
48     $this->adminUser = $this->drupalCreateUser($permissions);
49     $this->drupalLogin($this->adminUser);
50   }
51
52   /**
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.
56    */
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);
63
64     // Enable the entity type and create a pattern for it.
65     $this->drupalGet('/admin/config/search/path/settings');
66     $edit = [
67       'enabled_entity_types[comment]' => TRUE,
68     ];
69     $this->drupalPostForm(NULL, $edit, 'Save configuration');
70     $this->createPattern('comment', '/comment/[comment:body]');
71
72     // Create a node, a comment type and a comment entity.
73     $node = $this->drupalCreateNode(['type' => 'article']);
74     $this->drupalGet('/node/' . $node->id());
75     $edit = [
76       'comment_body[0][value]' => 'test-body',
77     ];
78     $this->drupalPostForm(NULL, $edit, 'Save');
79
80     // Verify that an alias has been generated and that the type can no longer
81     // be disabled.
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);
85   }
86
87 }