Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Plugin / Discovery / AnnotatedClassDiscoveryTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Plugin\Discovery;
4
5 use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
6
7 /**
8  * Tests that plugins are correctly discovered using annotated classes.
9  *
10  * @group Plugin
11  */
12 class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
13
14   protected function setUp() {
15     parent::setUp();
16     $this->expectedDefinitions = [
17       'apple' => [
18         'id' => 'apple',
19         'label' => 'Apple',
20         'color' => 'green',
21         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Apple',
22         'provider' => 'plugin_test',
23       ],
24       'banana' => [
25         'id' => 'banana',
26         'label' => 'Banana',
27         'color' => 'yellow',
28         'uses' => [
29           'bread' => t('Banana bread'),
30           'loaf' => [
31             'singular' => '@count loaf',
32             'plural' => '@count loaves',
33             'context' => NULL,
34           ],
35         ],
36         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Banana',
37         'provider' => 'plugin_test',
38       ],
39       'cherry' => [
40         'id' => 'cherry',
41         'label' => 'Cherry',
42         'color' => 'red',
43         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry',
44         'provider' => 'plugin_test',
45       ],
46       'kale' => [
47         'id' => 'kale',
48         'label' => 'Kale',
49         'color' => 'green',
50         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Kale',
51         'provider' => 'plugin_test',
52       ],
53       'orange' => [
54         'id' => 'orange',
55         'label' => 'Orange',
56         'color' => 'orange',
57         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Orange',
58         'provider' => 'plugin_test',
59       ],
60       'big_apple' => [
61         'id' => 'big_apple',
62         'label' => 'Big Apple',
63         'color' => 'green',
64         'class' => 'Drupal\plugin_test_extended\Plugin\plugin_test\fruit\BigApple',
65         'provider' => 'plugin_test_extended',
66       ],
67       'extending_non_installed_class' => [
68         'id' => 'extending_non_installed_class',
69         'label' => 'A plugin whose class is extending from a non-installed module class',
70         'color' => 'pink',
71         'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\ExtendingNonInstalledClass',
72         'provider' => 'plugin_test',
73       ],
74     ];
75
76     $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src';
77     $base_directory2 = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test_extended/src';
78     $namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory, 'Drupal\plugin_test_extended' => $base_directory2]);
79
80     $annotation_namespaces = ['Drupal\plugin_test\Plugin\Annotation', 'Drupal\plugin_test_extended\Plugin\Annotation'];
81     $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces, 'Drupal\Component\Annotation\Plugin', $annotation_namespaces);
82     $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
83   }
84
85 }