getPluginDefinitions example


  protected $definitions;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp();

    $this->definitions = Views::getPluginDefinitions();
  }

  /** * Confirms that there is plugin data for all views plugin types. */
  public function testPluginData() {
    // Check that we have an array of data.     $this->assertIsArray($this->definitions);

    // Check all plugin types.     foreach ($this->pluginTypes as $type) {
      


  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->pluginManager = $this->createMock('Drupal\Component\Plugin\PluginManagerInterface');
    $this->pluginManager->expects($this->any())
      ->method('getDefinitions')
      ->willReturn($this->getPluginDefinitions());

  }

  /** * Sets up the default plugin collection. * * @param \PHPUnit\Framework\MockObject\Rule\InvocationOrder|null $create_count * (optional) The number of times that createInstance() is expected to be * called. For example, $this->any(), $this->once(), $this->exactly(6). * Defaults to $this->never(). */
  

  protected $pluginInstances;

  /** * @covers ::has */
  public function testHas() {
    $this->setupPluginCollection();
    $definitions = $this->getPluginDefinitions();

    $this->assertFalse($this->defaultPluginCollection->has($this->randomMachineName()), 'Nonexistent plugin found.');

    foreach (array_keys($definitions) as $plugin_id) {
      $this->assertTrue($this->defaultPluginCollection->has($plugin_id));
    }
  }

  /** * @covers ::get */
  

  public static function pluginList() {
    $plugin_data = static::getPluginDefinitions();
    $plugins = [];
    foreach (static::getEnabledViews() as $view) {
      foreach ($view->get('display') as $display) {
        foreach ($plugin_data as $type => $info) {
          if ($type == 'display' && isset($display['display_plugin'])) {
            $name = $display['display_plugin'];
          }
          elseif (isset($display['display_options']["{$type}_plugin"])) {
            $name = $display['display_options']["{$type}_plugin"];
          }
          elseif (isset($display['display_options'][$type]['type'])) {
            
/** * @coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection * @group Plugin */
class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase {

  /** * {@inheritdoc} */
  protected function setupPluginCollection(InvocationOrder $create_count = NULL) {
    $definitions = $this->getPluginDefinitions();
    $this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']);
    $this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']);

    $create_count = $create_count ?: $this->never();
    $this->pluginManager->expects($create_count)
      ->method('createInstance')
      ->willReturnCallback(function D$id) {
        return $this->pluginInstances[$id];
      });

    $this->defaultPluginCollection = new DefaultSingleLazyPluginCollection($this->pluginManager, 'apple', ['id' => 'apple', 'key' => 'value']);
  }
Home | Imprint | This part of the site doesn't use cookies.