You are here

class UserProtectionBaseUnitTest in User protect 8

@coversDefaultClass \Drupal\userprotect\Plugin\UserProtection\UserProtectionBase @group userprotect

Hierarchy

Expanded class hierarchy of UserProtectionBaseUnitTest

File

tests/src/Unit/Plugin/UserProtection/UserProtectionBaseUnitTest.php, line 11

Namespace

Drupal\Tests\userprotect\Unit\Plugin\UserProtection
View source
class UserProtectionBaseUnitTest extends UnitTestCase {

  /**
   * The module handler used for testing.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The userprotect method plugin under test.
   *
   * @var \Drupal\userprotect\Plugin\UserProtection\Mail
   */
  protected $plugin;

  /**
   * The definition of the user protection plugin under test.
   *
   * @var array
   */
  protected $pluginDefinition = [
    'id' => 'dummy',
    'label' => 'Dummy',
    'description' => 'This is a dummy plugin definition.',
    'provider' => '',
    'status' => FALSE,
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->moduleHandler = $this
      ->createMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $this->plugin = $this
      ->getMockBuilder('\\Drupal\\userprotect\\Plugin\\UserProtection\\UserProtectionBase')
      ->setConstructorArgs([
      [],
      '',
      $this->pluginDefinition,
      $this->moduleHandler,
    ])
      ->setMethods([
      't',
    ])
      ->getMock();
    $this->plugin
      ->expects($this
      ->any())
      ->method('t')
      ->will($this
      ->returnArgument(0));
  }

  /**
   * @covers ::label
   */
  public function testLabel() {
    $this
      ->assertSame('Dummy', $this->plugin
      ->label());
  }

  /**
   * @covers ::description
   */
  public function testDescription() {
    $this
      ->assertSame('This is a dummy plugin definition.', $this->plugin
      ->description());
  }

  /**
   * @covers ::setConfiguration
   * @covers ::getConfiguration
   */
  public function testGetConfiguration() {
    $configuration = [
      'status' => TRUE,
    ];
    $this
      ->assertInstanceOf('\\Drupal\\userprotect\\Plugin\\UserProtection\\UserProtectionInterface', $this->plugin
      ->setConfiguration($configuration));
    $saved_configuration = $this->plugin
      ->getConfiguration();
    $this
      ->assertSame($configuration['status'], $saved_configuration['status']);
  }

  /**
   * @covers ::defaultConfiguration
   */
  public function testDefaultConfiguration() {
    $this
      ->assertIsArray($this->plugin
      ->defaultConfiguration());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
UserProtectionBaseUnitTest::$moduleHandler protected property The module handler used for testing.
UserProtectionBaseUnitTest::$plugin protected property The userprotect method plugin under test.
UserProtectionBaseUnitTest::$pluginDefinition protected property The definition of the user protection plugin under test.
UserProtectionBaseUnitTest::setUp public function Overrides UnitTestCase::setUp
UserProtectionBaseUnitTest::testDefaultConfiguration public function @covers ::defaultConfiguration
UserProtectionBaseUnitTest::testDescription public function @covers ::description
UserProtectionBaseUnitTest::testGetConfiguration public function @covers ::setConfiguration @covers ::getConfiguration
UserProtectionBaseUnitTest::testLabel public function @covers ::label