You are here

class ConfigActionsPluginBaseTest in Config Actions 8

test the ConfigActionsPluginBase class

@coversDefaultClass \Drupal\config_actions\ConfigActionsPluginBase @group config_actions

Hierarchy

Expanded class hierarchy of ConfigActionsPluginBaseTest

File

tests/src/Unit/ConfigActionsPluginBaseTest.php, line 16

Namespace

Drupal\Tests\config_actions\Unit
View source
class ConfigActionsPluginBaseTest extends UnitTestCase {

  /**
   * @var \Drupal\config_actions\ConfigActionsServiceInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $configActions;

  /**
   * Annotation data to be passed to plugin constructor.
   * @var array
   */
  protected $definition;
  public function setUp() {
    parent::setUp();
    $container = new ContainerBuilder();
    $this->configActions = $this
      ->createMock(ConfigActionsServiceInterface::class);
    $container
      ->set('config_actions', $this->configActions);
    \Drupal::setContainer($container);
    $this->definition = [
      'options' => [],
      'replace_in' => [],
      'data' => [],
    ];
  }

  /**
   * @covers ::setOptions
   * @covers ::getOption
   */
  public function testGetOption() {
    $options = [
      'source' => 'my source',
    ];
    $plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
    $plugin
      ->setOptions($options);
    $this
      ->assertEquals('my source', $plugin
      ->getOption('source'));
  }

  /**
   * @covers ::setOptions
   */
  public function testSetOptions() {
    $options = [
      'source' => 'node.type.@bundle@',
      'replace' => [
        '@bundle@' => 'article',
      ],
    ];
    $this->definition['replace_in'] = [
      'source',
    ];
    $plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
    $plugin
      ->setOptions($options);
    $this
      ->assertEquals('node.type.article', $plugin
      ->getOption('source'));
  }

  /**
   * @covers ::parseOptions
   */
  public function testParseOptions() {
    $options = [
      'id' => 'testid',
      'source' => '@id@',
    ];
    $plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
    $new_options = $plugin
      ->parseOptions($options);
    $this
      ->assertEquals('testid', $new_options['source']);
  }

  /**
   * @covers ::setOptions
   */
  public function testSimpleOptions() {
    $options = [
      'source' => 'node.type.@bundle@',
      '@bundle@' => 'article',
    ];
    $this->definition['replace_in'] = [
      'source',
    ];
    $plugin = new ConfigActionsPluginBase($options, 'test', $this->definition, $this->configActions);
    $plugin
      ->setOptions($options);
    $this
      ->assertEquals('node.type.article', $plugin
      ->getOption('source'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigActionsPluginBaseTest::$configActions protected property
ConfigActionsPluginBaseTest::$definition protected property Annotation data to be passed to plugin constructor.
ConfigActionsPluginBaseTest::setUp public function Overrides UnitTestCase::setUp
ConfigActionsPluginBaseTest::testGetOption public function @covers ::setOptions @covers ::getOption
ConfigActionsPluginBaseTest::testParseOptions public function @covers ::parseOptions
ConfigActionsPluginBaseTest::testSetOptions public function @covers ::setOptions
ConfigActionsPluginBaseTest::testSimpleOptions public function @covers ::setOptions
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.