3 namespace Drupal\Tests\system\Functional\Entity;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests that operations can be injected from the hook.
12 class EntityOperationsTest extends BrowserTestBase {
19 public static $modules = ['entity_test'];
21 protected function setUp() {
24 // Create and log in user.
25 $this->drupalLogin($this->drupalCreateUser(['administer permissions']));
29 * Checks that hook_entity_operation_alter() can add an operation.
31 * @see entity_test_entity_operation_alter()
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()]));
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);