AlterDecoratorTest.php

Definition of Drupal\system\Tests\Plugin\AlterDecoratorTest.

Namespace

Drupal\system\Tests\Plugin

File

drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/AlterDecoratorTest.php
View source
<?php

/**
 * @file
 * Definition of Drupal\system\Tests\Plugin\AlterDecoratorTest.
 */
namespace Drupal\system\Tests\Plugin;

use Drupal\Component\Plugin\Exception\ExceptionInterface;
use Drupal\plugin_test\Plugin\AlterDecoratorTestPluginManager;
use Drupal\plugin_test\Plugin\TestPluginManager;
use Drupal\simpletest\WebTestBase;

/**
 * Tests that the AlterDecorator fires and respects the alter hook.
 */
class AlterDecoratorTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'plugin_test',
  );

  /**
   * Stores a plugin manager which uses the AlterDecorator.
   *
   * @var Drupal\plugin_test\Plugin\AlterDecoratorTestPluginManager;
   */
  protected $alterTestPluginManager;
  public static function getInfo() {
    return array(
      'name' => 'AlterDecorator',
      'description' => 'Tests that the AlterDecorator fires and respects the alter hook.',
      'group' => 'Plugin API',
    );
  }
  public function setUp() {
    parent::setUp();

    // Setup a plugin manager which uses the alter decorator.
    $this->alterTestPluginManager = new AlterDecoratorTestPluginManager();
  }

  /**
   * Tests getDefinitions() and getDefinition() of Drupal\Core\Plugin\Discovery\AlterDecorator.
   */
  public function testAlterDecorator() {

    // Ensure that getDefinitions() fires and changes the actual plugin definitions.
    $definitions = $this->alterTestPluginManager
      ->getDefinitions();
    foreach ($definitions as &$definition) {
      $this
        ->assertTrue($definition['altered']);
    }

    // Ensure that getDefinitions() fires and changes the actual plugin definition.
    $definition = $this->alterTestPluginManager
      ->getDefinition('user_login');
    $this
      ->assertTrue($definition['altered_single']);
  }

}

Classes

Namesort descending Description
AlterDecoratorTest Tests that the AlterDecorator fires and respects the alter hook.