class RequiredTest in Tamper 8
Test the required plugin.
@coversDefaultClass \Drupal\tamper\Plugin\Tamper\Required @group tamper
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\tamper\Unit\Plugin\Tamper\TamperPluginTestBase
- class \Drupal\Tests\tamper\Unit\Plugin\Tamper\RequiredTest
- class \Drupal\Tests\tamper\Unit\Plugin\Tamper\TamperPluginTestBase
Expanded class hierarchy of RequiredTest
File
- tests/
src/ Unit/ Plugin/ Tamper/ RequiredTest.php, line 14
Namespace
Drupal\Tests\tamper\Unit\Plugin\TamperView source
class RequiredTest extends TamperPluginTestBase {
/**
* Instantiates a plugin.
*
* @return \Drupal\tamper\TamperInterface
* A tamper plugin.
*/
protected function instantiatePlugin() {
return $this
->getRequiredPlugin();
}
/**
* Plugin instance, configured to require empty values.
*
* @var \Drupal\tamper\Plugin\Tamper\Required
*/
protected $invertedPlugin;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->invertedPlugin = $this
->getInvertedPlugin();
parent::setUp();
}
/**
* Test required with a string.
*/
public function testRequiredWithSingleValue() {
$this
->assertEquals('Expected', $this->plugin
->tamper('Expected'));
}
/**
* Test required with a string.
*/
public function testInvertedRequiredWithSingleValue() {
$this
->expectException(SkipTamperItemException::class);
$this->invertedPlugin
->tamper('Expected');
}
/**
* Test required with empty string.
*/
public function testRequiredWithEmptyString() {
$this
->expectException(SkipTamperItemException::class);
$this->plugin
->tamper('');
}
/**
* Test required with empty string.
*/
public function testInvertedRequiredWithEmptyString() {
$this
->assertEquals('', $this->invertedPlugin
->tamper(''));
}
/**
* Test required with an array.
*/
public function testRequiredWithMultipleValues() {
$expected = [
'foo' => 'bar',
'zip' => '',
'baz' => FALSE,
];
$this
->assertEquals($expected, $this->plugin
->tamper($expected));
}
/**
* Test required with an array.
*/
public function testInvertedRequiredWithMultipleValues() {
$this
->expectException(SkipTamperItemException::class);
$expected = [
'foo' => 'bar',
'zip' => '',
'baz' => FALSE,
];
$this->invertedPlugin
->tamper($expected);
}
/**
* Test required with false.
*/
public function testRequiredWithBool() {
$this
->expectException(SkipTamperItemException::class);
$this->plugin
->tamper(FALSE);
}
/**
* Test required with false.
*/
public function testInvertedRequiredWithBool() {
$this
->assertEquals(FALSE, $this->invertedPlugin
->tamper(FALSE));
}
/**
* Test required with empty array.
*/
public function testRequiredWithEmptyArray() {
$this
->expectException(SkipTamperItemException::class);
$this->plugin
->tamper([]);
}
/**
* Test required with empty array.
*/
public function testInvertedRequiredWithEmptyArray() {
$this
->assertArrayEquals([], $this->invertedPlugin
->tamper([]));
}
/**
* Test required with empty array.
*/
public function testRequiredWithNull() {
$this
->expectException(SkipTamperItemException::class);
$this->plugin
->tamper(NULL);
}
/**
* Test required with null.
*/
public function testInvertedRequiredWithNull() {
$this
->assertEquals(NULL, $this->invertedPlugin
->tamper(NULL));
}
/**
* Get a plugin configured to require items.
*
* @return \Drupal\tamper\Plugin\Tamper\Required
* Plugin instance.
*/
protected function getRequiredPlugin() {
$config = [
Required::SETTING_INVERT => FALSE,
];
$plugin = new Required($config, 'required', [], $this
->getMockSourceDefinition());
return $plugin;
}
/**
* Get a plugin configured to require empty items.
*
* @return \Drupal\tamper\Plugin\Tamper\Required
* Plugin instance.
*/
protected function getInvertedPlugin() {
$config = [
Required::SETTING_INVERT => TRUE,
];
$plugin = new Required($config, 'required', [], $this
->getMockSourceDefinition());
return $plugin;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RequiredTest:: |
protected | property | Plugin instance, configured to require empty values. | |
RequiredTest:: |
protected | function | Get a plugin configured to require empty items. | |
RequiredTest:: |
protected | function | Get a plugin configured to require items. | |
RequiredTest:: |
protected | function |
Instantiates a plugin. Overrides TamperPluginTestBase:: |
|
RequiredTest:: |
protected | function |
Overrides TamperPluginTestBase:: |
|
RequiredTest:: |
public | function | Test required with false. | |
RequiredTest:: |
public | function | Test required with empty array. | |
RequiredTest:: |
public | function | Test required with empty string. | |
RequiredTest:: |
public | function | Test required with an array. | |
RequiredTest:: |
public | function | Test required with null. | |
RequiredTest:: |
public | function | Test required with a string. | |
RequiredTest:: |
public | function | Test required with false. | |
RequiredTest:: |
public | function | Test required with empty array. | |
RequiredTest:: |
public | function | Test required with empty string. | |
RequiredTest:: |
public | function | Test required with an array. | |
RequiredTest:: |
public | function | Test required with empty array. | |
RequiredTest:: |
public | function | Test required with a string. | |
TamperPluginTestBase:: |
protected | property | The tamper plugin under test. | |
TamperPluginTestBase:: |
protected | function | Returns a mocked source definition. | |
TamperPluginTestBase:: |
public | function | @covers ::buildConfigurationForm | |
TamperPluginTestBase:: |
public | function | @covers ::defaultConfiguration | |
TamperPluginTestBase:: |
public | function | @covers ::getConfiguration | |
TamperPluginTestBase:: |
public | function | @covers ::getPluginDefinition | |
TamperPluginTestBase:: |
public | function | @covers ::getPluginId | |
TamperPluginTestBase:: |
public | function | @covers ::multiple | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |