class CategorizingPluginManagerTraitTest

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php \Drupal\Tests\Core\Plugin\CategorizingPluginManagerTraitTest

@coversDefaultClass \Drupal\Core\Plugin\CategorizingPluginManagerTrait @group Plugin @runTestsInSeparateProcesses

Hierarchy

Expanded class hierarchy of CategorizingPluginManagerTraitTest

File

core/tests/Drupal/Tests/Core/Plugin/CategorizingPluginManagerTraitTest.php, line 20

Namespace

Drupal\Tests\Core\Plugin
View source
class CategorizingPluginManagerTraitTest extends UnitTestCase {
    
    /**
     * The plugin manager to test.
     *
     * @var \Drupal\Component\Plugin\CategorizingPluginManagerInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $pluginManager;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $module_handler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
        $module_handler->expects($this->any())
            ->method('getModuleList')
            ->willReturn([
            'node' => [],
        ]);
        $module_extension_list = $this->createMock(ModuleExtensionList::class);
        $module_extension_list->expects($this->any())
            ->method('getName')
            ->willReturnCallback(function ($argument) {
            if ($argument == 'node') {
                return 'Node';
            }
            throw new UnknownExtensionException();
        });
        $this->pluginManager = new CategorizingPluginManager($module_handler, $module_extension_list);
        $this->pluginManager
            ->setStringTranslation($this->getStringTranslationStub());
    }
    
    /**
     * @covers ::getCategories
     */
    public function testGetCategories() : void {
        $this->assertSame([
            'fruits',
            'vegetables',
        ], array_values($this->pluginManager
            ->getCategories()));
    }
    
    /**
     * @covers ::getSortedDefinitions
     */
    public function testGetSortedDefinitions() : void {
        $sorted = $this->pluginManager
            ->getSortedDefinitions();
        $this->assertSame([
            'apple',
            'mango',
            'cucumber',
        ], array_keys($sorted));
    }
    
    /**
     * @covers ::getGroupedDefinitions
     */
    public function testGetGroupedDefinitions() : void {
        $grouped = $this->pluginManager
            ->getGroupedDefinitions();
        $this->assertSame([
            'fruits',
            'vegetables',
        ], array_keys($grouped));
        $this->assertSame([
            'apple',
            'mango',
        ], array_keys($grouped['fruits']));
        $this->assertSame([
            'cucumber',
        ], array_keys($grouped['vegetables']));
    }
    
    /**
     * @covers ::processDefinitionCategory
     */
    public function testProcessDefinitionCategory() : void {
        // Existing category.
        $definition = [
            'label' => 'some',
            'provider' => 'core',
            'category' => 'bag',
        ];
        $this->pluginManager
            ->processDefinition($definition, 'some');
        $this->assertSame('bag', $definition['category']);
        // No category, provider without label.
        $definition = [
            'label' => 'some',
            'provider' => 'core',
        ];
        $this->pluginManager
            ->processDefinition($definition, 'some');
        $this->assertSame('core', $definition['category']);
        // No category, provider is module with label.
        $definition = [
            'label' => 'some',
            'provider' => 'node',
        ];
        $this->pluginManager
            ->processDefinition($definition, 'some');
        $this->assertSame('Node', $definition['category']);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
CategorizingPluginManagerTraitTest::$pluginManager protected property The plugin manager to test.
CategorizingPluginManagerTraitTest::setUp protected function Overrides UnitTestCase::setUp
CategorizingPluginManagerTraitTest::testGetCategories public function @covers ::getCategories
CategorizingPluginManagerTraitTest::testGetGroupedDefinitions public function @covers ::getGroupedDefinitions
CategorizingPluginManagerTraitTest::testGetSortedDefinitions public function @covers ::getSortedDefinitions
CategorizingPluginManagerTraitTest::testProcessDefinitionCategory public function @covers ::processDefinitionCategory
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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