
| Current Path : /var/www/html1/bbp/web/core/modules/system/tests/src/Functional/Entity/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html1/bbp/web/core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php |
<?php
namespace Drupal\Tests\system\Functional\Entity;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that operations can be injected from the hook.
*
* @group Entity
*/
class EntityOperationsTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
protected function setUp(): void {
parent::setUp();
// Create and log in user.
$this->drupalLogin($this->drupalCreateUser(['administer permissions']));
}
/**
* Checks that hook_entity_operation_alter() can add an operation.
*
* @see entity_test_entity_operation_alter()
*/
public function testEntityOperationAlter() {
// Check that role listing contain our test_operation operation.
$this->drupalGet('admin/people/roles');
$roles = user_roles();
foreach ($roles as $role) {
$this->assertSession()->linkByHrefExists($role->toUrl()->toString() . '/test_operation');
$this->assertSession()->linkExists(new FormattableMarkup('Test Operation: @label', ['@label' => $role->label()]));
}
}
/**
* {@inheritdoc}
*/
protected function createRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) {
// The parent method uses random strings by default, which may include HTML
// entities for the entity label. Since in this test the entity label is
// used to generate a link, and AssertContentTrait::assertLink() is not
// designed to deal with links potentially containing HTML entities this
// causes random failures. Use a random HTML safe string instead.
$name = $name ?: $this->randomMachineName();
return parent::createRole($permissions, $rid, $name, $weight);
}
}