function RulesEntityIntegrationTestBase::setUp

Overrides RulesIntegrationTestBase::setUp

33 calls to RulesEntityIntegrationTestBase::setUp()
ContributedPluginDiscoveryTest::setUp in tests/src/Unit/Integration/ContributedPluginDiscoveryTest.php
EntityCreateTest::setUp in tests/src/Unit/Integration/RulesAction/EntityCreateTest.php
EntityDeleteTest::setUp in tests/src/Unit/Integration/RulesAction/EntityDeleteTest.php
EntityFetchByFieldTest::setUp in tests/src/Unit/Integration/RulesAction/EntityFetchByFieldTest.php
EntityFetchByIdTest::setUp in tests/src/Unit/Integration/RulesAction/EntityFetchByIdTest.php

... See full list

33 methods override RulesEntityIntegrationTestBase::setUp()
ContributedPluginDiscoveryTest::setUp in tests/src/Unit/Integration/ContributedPluginDiscoveryTest.php
EntityCreateTest::setUp in tests/src/Unit/Integration/RulesAction/EntityCreateTest.php
EntityDeleteTest::setUp in tests/src/Unit/Integration/RulesAction/EntityDeleteTest.php
EntityFetchByFieldTest::setUp in tests/src/Unit/Integration/RulesAction/EntityFetchByFieldTest.php
EntityFetchByIdTest::setUp in tests/src/Unit/Integration/RulesAction/EntityFetchByIdTest.php

... See full list

File

tests/src/Unit/Integration/RulesEntityIntegrationTestBase.php, line 50

Class

RulesEntityIntegrationTestBase
Base class for Rules integration tests with entities.

Namespace

Drupal\Tests\rules\Unit\Integration

Code

protected function setUp() : void {
    parent::setUp();
    $this->namespaces['Drupal\\Core\\Entity'] = $this->root . '/core/lib/Drupal/Core/Entity';
    $language = $this->prophesize(LanguageInterface::class);
    $language->getId()
        ->willReturn('en');
    $this->languageManager = $this->prophesize(LanguageManagerInterface::class);
    $this->languageManager
        ->getCurrentLanguage()
        ->willReturn($language->reveal());
    $this->languageManager
        ->getLanguages()
        ->willReturn([
        $language->reveal(),
    ]);
    // We need to support multiple entity types, including a test type:
    $type_info = [
        'test' => [
            'id' => 'test',
            'label' => 'Test',
            'entity_keys' => [
                'bundle' => 'bundle',
            ],
        ],
        'user' => [
            'id' => 'user',
            'label' => 'Test User',
            'entity_keys' => [
                'bundle' => 'user',
            ],
        ],
        'node' => [
            'id' => 'node',
            'label' => 'Test Node',
            'entity_keys' => [
                'bundle' => 'dummy',
            ],
        ],
        'path_alias' => [
            'id' => 'path_alias',
            'label' => 'URL alias',
            'entity_keys' => [
                'bundle' => 'path_alias',
            ],
        ],
    ];
    $type_array = [];
    foreach ($type_info as $type => $info) {
        $entity_type = new ContentEntityType($info);
        $type_array[$type] = $entity_type;
        $this->entityTypeManager
            ->getDefinition($type)
            ->willReturn($entity_type);
    }
    // We need a user_role mock as well.
    $role_entity_info = [
        'id' => 'user_role',
        'label' => 'Test Role',
    ];
    $role_type = new ConfigEntityType($role_entity_info);
    $type_array['user_role'] = $role_type;
    $this->entityTypeManager
        ->getDefinitions()
        ->willReturn($type_array);
    $this->entityAccess = $this->prophesize(EntityAccessControlHandlerInterface::class);
    $this->entityTypeManager
        ->getAccessControlHandler(Argument::any())
        ->willReturn($this->entityAccess
        ->reveal());
    // The base field definitions for our test entity aren't used, and would
    // require additional mocking. It doesn't appear that any of our tests rely
    // on this for any other entity type that we are mocking.
    $this->entityFieldManager
        ->getBaseFieldDefinitions(Argument::any())
        ->willReturn([]);
    // Return some dummy bundle information for now, so that the entity manager
    // does not call out to the config entity system to get bundle information.
    $this->entityTypeBundleInfo
        ->getBundleInfo(Argument::any())
        ->willReturn([
        'test' => [
            'label' => 'Test',
        ],
    ]);
    if (version_compare(\Drupal::VERSION, '10.2') >= 0) {
        $this->fieldTypeManager = new FieldTypePluginManager($this->namespaces, $this->cacheBackend, $this->moduleHandler
            ->reveal(), $this->typedDataManager);
    }
    else {
        $this->fieldTypeManager = new FieldTypePluginManager($this->namespaces, $this->cacheBackend, $this->moduleHandler
            ->reveal(), $this->typedDataManager, $this->fieldTypeCategoryManager);
    }
    $this->container
        ->set('plugin.manager.field.field_type', $this->fieldTypeManager);
    // The new ReverseContainer service needs to be present to prevent massive
    // unit test failures.
    // @see https://www.drupal.org/project/rules/issues/3346846
    $this->container
        ->set('Drupal\\Component\\DependencyInjection\\ReverseContainer', new ReverseContainer($this->container));
}