/** * Tests the YAML file discovery. */ public function testDiscovery() { vfsStreamWrapper::register(); $root = new vfsStreamDirectory('modules'); vfsStreamWrapper::setRoot($root); $url = vfsStream::url('modules'); mkdir($url . '/test_1'); file_put_contents($url . '/test_1/test_1.test.yml', 'name: test'); file_put_contents($url . '/test_1/test_2.test.yml', 'name: test'); mkdir($url . '/test_2'); file_put_contents($url . '/test_2/test_3.test.yml', 'name: test'); // Write an empty YAML file. file_put_contents($url . '/test_2/test_4.test.yml', ''); // Set up the directories to search. $directories = array('test_1' => $url . '/test_1', 'test_2' => $url . '/test_1', 'test_3' => $url . '/test_2', 'test_4' => $url . '/test_2'); $discovery = new YamlDiscovery('test', $directories); $data = $discovery->findAll(); $this->assertEquals(count($data), count($directories)); $this->assertArrayHasKey('test_1', $data); $this->assertArrayHasKey('test_2', $data); $this->assertArrayHasKey('test_3', $data); $this->assertArrayHasKey('test_4', $data); foreach (array('test_1', 'test_2', 'test_3') as $key) { $this->assertArrayHasKey('name', $data[$key]); $this->assertEquals($data[$key]['name'], 'test'); } $this->assertSame(array(), $data['test_4']); }
/** * {@inheritdoc} */ public function getDefinitions() { $plugins = $this->discovery->findAll(); // Flatten definitions into what's expected from plugins. $definitions = array(); foreach ($plugins as $provider => $list) { foreach ($list as $id => $definition) { // Add TranslatableMarkup. foreach ($this->translatableProperties as $property => $context_key) { if (isset($definition[$property])) { $options = []; // Move the t() context from the definition to the translation // wrapper. if ($context_key && isset($definition[$context_key])) { $options['context'] = $definition[$context_key]; unset($definition[$context_key]); } $definition[$property] = new TranslatableMarkup($definition[$property], [], $options); } } // Add ID and provider. $definitions[$id] = $definition + array('provider' => $provider, 'id' => $id); } } return $definitions; }
/** * {@inheritdoc} */ public function getDefinitions() { $plugins = $this->discovery->findAll(); // Flatten definitions into what's expected from plugins. $definitions = array(); foreach ($plugins as $provider => $list) { foreach ($list as $id => $definition) { $definitions[$id] = $definition + array('provider' => $provider, 'id' => $id); } } return $definitions; }
/** * Retrieves all defined routes from .routing.yml files. * * @return array * The defined routes, keyed by provider. */ protected function getRouteDefinitions() { if (!isset($this->yamlDiscovery)) { $this->yamlDiscovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories()); } return $this->yamlDiscovery->findAll(); }
/** * Tests the YAML file discovery. */ public function testDiscovery() { $base_path = __DIR__ . '/Fixtures'; // Set up the directories to search. $directories = array('test_1' => $base_path . '/test_1', 'test_2' => $base_path . '/test_2', 'test_3' => $base_path . '/test_2'); $discovery = new YamlDiscovery('test', $directories); $data = $discovery->findAll(); $this->assertEquals(count($data), count($directories)); $this->assertArrayHasKey('test_1', $data); $this->assertArrayHasKey('test_2', $data); $this->assertArrayHasKey('test_3', $data); foreach ($data as $item) { $this->assertArrayHasKey('name', $item); $this->assertEquals($item['name'], 'test'); } }
/** * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. */ public function testRebuildIfNeeded() { $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE)); $this->lock->expects($this->once())->method('release')->with('router_rebuild'); $this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array())); $this->routeBuilder->setRebuildNeeded(); // This will trigger a successful rebuild. $this->assertTrue($this->routeBuilder->rebuildIfNeeded()); // This will not trigger a rebuild. $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); }
/** * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. */ public function testRebuildIfNecessary() { $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE)); $this->lock->expects($this->once())->method('release')->with('router_rebuild'); $this->routeBuilderIndicator->expects($this->once())->method('setRebuildNeeded'); $this->routeBuilderIndicator->expects($this->once())->method('setRebuildDone'); $this->routeBuilderIndicator->expects($this->exactly(2))->method('isRebuildNeeded')->will($this->onConsecutiveCalls(TRUE, FALSE)); $this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array())); $this->routeBuilder->setRebuildNeeded(); // This will trigger a successful rebuild. $this->assertTrue($this->routeBuilder->rebuildIfNeeded()); // This will not trigger a rebuild. $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); }
/** * {@inheritdoc} */ public function getPluginTypes() { if (is_null($this->pluginTypes)) { $this->pluginTypes = []; // Get the plugin type definitions. $plugin_types_data_discovery = new YamlDiscovery('plugin_type', $this->moduleHandler->getModuleDirectories()); $plugin_type_definitions_by_module = $plugin_types_data_discovery->findAll(); // For every definition, set defaults and instantiate an object. foreach ($plugin_type_definitions_by_module as $module => $plugin_type_definitions) { $plugin_type_definition_defaults = ['provider' => $module]; foreach ($plugin_type_definitions as $plugin_type_id => $plugin_type_definition) { $plugin_type_definition += $plugin_type_definition_defaults; if ($plugin_type_definition['provider'] == 'core' || $this->moduleHandler->moduleExists($plugin_type_definition['provider'])) { $plugin_type_definition['id'] = $plugin_type_id; /** @var \Drupal\plugin\PluginType\PluginTypeInterface $class */ $class = isset($plugin_type_definition['class']) ? $plugin_type_definition['class'] : PluginType::class; $plugin_type = $class::createFromDefinition($this->container, $plugin_type_definition); $this->pluginTypes[$plugin_type_id] = $plugin_type; } } } } return $this->pluginTypes; }
/** * Retrieves all defined routes from .routing.yml files. * * @return array * The defined routes, keyed by provider. */ protected function getRouteDefinitions() { // Always instantiate a new YamlDiscovery object so that we always search on // the up-to-date list of modules. $discovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories()); return $discovery->findAll(); }
/** * {@inheritdoc} */ protected function getRouteDefinitions() { return $this->yamlDiscovery->findAll(); }