function DataConvertTest::executeAction

Shortcut method to execute the convert action and to avoid duplicate code.

Parameters

mixed $value: The value to be converted.

string $target_type: The target type $value should be converted to.

null|string $rounding_behavior: Definition for the rounding direction.

Return value

\Drupal\Core\TypedData\TypedDataInterface The raw conversion result as a typed data object.

7 calls to DataConvertTest::executeAction()
DataConvertTest::testConvertToFloat in tests/src/Unit/Integration/RulesAction/DataConvertTest.php
Test the conversion to float.
DataConvertTest::testConvertToInteger in tests/src/Unit/Integration/RulesAction/DataConvertTest.php
Test the conversion and rounding to integer.
DataConvertTest::testConvertToString in tests/src/Unit/Integration/RulesAction/DataConvertTest.php
Test the conversion to text.
DataConvertTest::testInvalidRoundingBehavior in tests/src/Unit/Integration/RulesAction/DataConvertTest.php
Test the behavior if rounding behavior is used with non integers.
DataConvertTest::testInvalidRoundingBehaviorException in tests/src/Unit/Integration/RulesAction/DataConvertTest.php
Test the behavior if nonsense rounding_behaviors is set.

... See full list

File

tests/src/Unit/Integration/RulesAction/DataConvertTest.php, line 191

Class

DataConvertTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\DataConvert @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

protected function executeAction($value, $target_type, $rounding_behavior = NULL) {
    $this->action
        ->setContextValue('value', $value);
    $this->action
        ->setContextValue('target_type', $target_type);
    if (!empty($rounding_behavior)) {
        $this->action
            ->setContextValue('rounding_behavior', $rounding_behavior);
    }
    $this->action
        ->refineContextDefinitions([]);
    $this->action
        ->execute();
    $result = $this->action
        ->getProvidedContext('conversion_result');
    return $result->getContextData();
}