class ConvertBooleanTest in Tamper 8
Tests the convert boolean plugin.
@coversDefaultClass \Drupal\tamper\Plugin\Tamper\ConvertBoolean @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\ConvertBooleanTest
- class \Drupal\Tests\tamper\Unit\Plugin\Tamper\TamperPluginTestBase
Expanded class hierarchy of ConvertBooleanTest
File
- tests/
src/ Unit/ Plugin/ Tamper/ ConvertBooleanTest.php, line 13
Namespace
Drupal\Tests\tamper\Unit\Plugin\TamperView source
class ConvertBooleanTest extends TamperPluginTestBase {
/**
* {@inheritdoc}
*/
protected function instantiatePlugin() {
$config = [
ConvertBoolean::SETTING_TRUTH_VALUE => 'A',
ConvertBoolean::SETTING_FALSE_VALUE => 'B',
ConvertBoolean::SETTING_MATCH_CASE => FALSE,
ConvertBoolean::SETTING_NO_MATCH => 'No match',
ConvertBoolean::SETTING_OTHER_TEXT => '',
];
return new ConvertBoolean($config, 'convert_boolean', [], $this
->getMockSourceDefinition());
}
/**
* Test convert to boolean basic functionality.
*/
public function testConvertBooleanBasicFunctionality() {
$this
->assertEquals(TRUE, $this->plugin
->tamper('A'));
$this
->assertEquals(TRUE, $this->plugin
->tamper('a'));
$this
->assertEquals(FALSE, $this->plugin
->tamper('B'));
$this
->assertEquals(FALSE, $this->plugin
->tamper('b'));
$this
->assertEquals('No match', $this->plugin
->tamper('c'));
$this
->assertEquals('No match', $this->plugin
->tamper('C'));
}
/**
* Test convert to boolean no match false case.
*/
public function testConvertBooleanNoMatchFalse() {
$config = [
ConvertBoolean::SETTING_TRUTH_VALUE => 'A',
ConvertBoolean::SETTING_FALSE_VALUE => 'B',
ConvertBoolean::SETTING_MATCH_CASE => FALSE,
ConvertBoolean::SETTING_NO_MATCH => 'pass',
ConvertBoolean::SETTING_OTHER_TEXT => '',
];
$plugin = new ConvertBoolean($config, 'convert_boolean', [], $this
->getMockSourceDefinition());
$this
->assertEquals(TRUE, $plugin
->tamper('A'));
$this
->assertEquals(TRUE, $plugin
->tamper('a'));
$this
->assertEquals(FALSE, $plugin
->tamper('B'));
$this
->assertEquals(FALSE, $plugin
->tamper('b'));
$this
->assertEquals('c', $plugin
->tamper('c'));
$this
->assertEquals('C', $plugin
->tamper('C'));
}
/**
* Test convert to boolean no match true case.
*/
public function testConvertBooleanNoMatchTrue() {
$config = [
ConvertBoolean::SETTING_TRUTH_VALUE => 'A',
ConvertBoolean::SETTING_FALSE_VALUE => 'B',
ConvertBoolean::SETTING_MATCH_CASE => TRUE,
ConvertBoolean::SETTING_NO_MATCH => 'No match',
ConvertBoolean::SETTING_OTHER_TEXT => '',
];
$plugin = new ConvertBoolean($config, 'convert_boolean', [], $this
->getMockSourceDefinition());
$this
->assertEquals(TRUE, $plugin
->tamper('A'));
$this
->assertNotEquals(TRUE, $plugin
->tamper('a'));
$this
->assertEquals(FALSE, $plugin
->tamper('B'));
$this
->assertNotEquals(FALSE, $plugin
->tamper('b'));
}
/**
* Test convert to boolean no match true case.
*/
public function testConvertBooleanNoMatchNull() {
$config = [
ConvertBoolean::SETTING_TRUTH_VALUE => 'A',
ConvertBoolean::SETTING_FALSE_VALUE => 'B',
ConvertBoolean::SETTING_MATCH_CASE => TRUE,
ConvertBoolean::SETTING_NO_MATCH => NULL,
ConvertBoolean::SETTING_OTHER_TEXT => '',
];
$plugin = new ConvertBoolean($config, 'convert_boolean', [], $this
->getMockSourceDefinition());
$this
->assertEquals(TRUE, $plugin
->tamper('A'));
$this
->assertEquals(NULL, $plugin
->tamper('a'));
$this
->assertEquals(FALSE, $plugin
->tamper('B'));
$this
->assertEquals(NULL, $plugin
->tamper('b'));
$this
->assertEquals(NULL, $plugin
->tamper('c'));
$this
->assertEquals(NULL, $plugin
->tamper('C'));
}
/**
* Test convert to boolean other text case.
*/
public function testConvertBooleanOtherText() {
$config = [
ConvertBoolean::SETTING_TRUTH_VALUE => 'A',
ConvertBoolean::SETTING_FALSE_VALUE => 'B',
ConvertBoolean::SETTING_MATCH_CASE => TRUE,
ConvertBoolean::SETTING_NO_MATCH => 'other text',
ConvertBoolean::SETTING_OTHER_TEXT => 'other text',
];
$plugin = new ConvertBoolean($config, 'convert_boolean', [], $this
->getMockSourceDefinition());
$this
->assertEquals('other text', $plugin
->tamper('a'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConvertBooleanTest:: |
protected | function |
Instantiates a plugin. Overrides TamperPluginTestBase:: |
|
ConvertBooleanTest:: |
public | function | Test convert to boolean basic functionality. | |
ConvertBooleanTest:: |
public | function | Test convert to boolean no match false case. | |
ConvertBooleanTest:: |
public | function | Test convert to boolean no match true case. | |
ConvertBooleanTest:: |
public | function | Test convert to boolean no match true case. | |
ConvertBooleanTest:: |
public | function | Test convert to boolean other text case. | |
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. | |
TamperPluginTestBase:: |
protected | property | The tamper plugin under test. | |
TamperPluginTestBase:: |
protected | function | Returns a mocked source definition. | |
TamperPluginTestBase:: |
protected | function |
Overrides UnitTestCase:: |
3 |
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. |