Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / src / Functional / Entity / EntityOperationsTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Entity;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests that operations can be injected from the hook.
9  *
10  * @group Entity
11  */
12 class EntityOperationsTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['entity_test'];
20
21   protected function setUp() {
22     parent::setUp();
23
24     // Create and log in user.
25     $this->drupalLogin($this->drupalCreateUser(['administer permissions']));
26   }
27
28   /**
29    * Checks that hook_entity_operation_alter() can add an operation.
30    *
31    * @see entity_test_entity_operation_alter()
32    */
33   public function testEntityOperationAlter() {
34     // Check that role listing contain our test_operation operation.
35     $this->drupalGet('admin/people/roles');
36     $roles = user_roles();
37     foreach ($roles as $role) {
38       $this->assertLinkByHref($role->url() . '/test_operation');
39       $this->assertLink(format_string('Test Operation: @label', ['@label' => $role->label()]));
40     }
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   protected function createRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) {
47     // WebTestBase::drupalCreateRole() by default uses random strings which may
48     // include HTML entities for the entity label. Since in this test the entity
49     // label is used to generate a link, and AssertContentTrait::assertLink() is
50     // not designed to deal with links potentially containing HTML entities this
51     // causes random failures. Use a random HTML safe string instead.
52     $name = $name ?: $this->randomMachineName();
53     return parent::createRole($permissions, $rid, $name, $weight);
54   }
55
56 }