EntityOperationsTest.php

Same filename in this branch
  1. 11.x core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
Same filename in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
  2. 9 core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php
  3. 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
  4. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php
  5. 10 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php
  6. 10 core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php

Namespace

Drupal\Tests\system\Functional\Entity

File

core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\system\Functional\Entity;

use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;

/**
 * Tests that operations can be injected from the hook.
 *
 * @group Entity
 */
class EntityOperationsTest extends BrowserTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'entity_test',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    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() : void {
        // Check that role listing contain our test_operation operation.
        $this->drupalGet('admin/people/roles');
        $roles = Role::loadMultiple();
        foreach ($roles as $role) {
            $this->assertSession()
                ->linkByHrefExists($role->toUrl()
                ->toString() . '/test_operation');
            $this->assertSession()
                ->linkExists('Test Operation: ' . $role->label());
        }
    }

}

Classes

Title Deprecated Summary
EntityOperationsTest Tests that operations can be injected from the hook.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.