private function RadioactivityFunctionTestTrait::assertEnergyValues in Radioactivity 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Traits/RadioactivityFunctionTestTrait.php \Drupal\Tests\radioactivity\Traits\RadioactivityFunctionTestTrait::assertEnergyValues()
Assert field energy values.
Parameters
string $fieldName: The field to be asserted.
array $actualValues: The actual field values.
array $expectedValues: The expected field values.
string $operator: The operator to be used to compare. Allowed values: '>', '>=', '<', '<=', '=='. The actual value on the left, the expected on the right.
string $message: The assertion message.
2 calls to RadioactivityFunctionTestTrait::assertEnergyValues()
- RadioactivityFunctionTestTrait::assertFieldEnergyValue in tests/
src/ Traits/ RadioactivityFunctionTestTrait.php - Assert the energy values from a field.
- RadioactivityFunctionTestTrait::assertPageEnergyValue in tests/
src/ Traits/ RadioactivityFunctionTestTrait.php - Assert the energy values from the page.
File
- tests/
src/ Traits/ RadioactivityFunctionTestTrait.php, line 354
Class
- RadioactivityFunctionTestTrait
- Radioactivity functional test trait.
Namespace
Drupal\Tests\radioactivity\TraitsCode
private function assertEnergyValues($fieldName, array $actualValues, array $expectedValues, $operator = '==', $message = '') {
if (array_diff(array_keys($actualValues), array_keys($expectedValues))) {
throw new \RuntimeException(sprintf('Invalid number of expected values for %s.', $fieldName));
}
foreach ($actualValues as $key => $actual) {
$expected = $expectedValues[$key];
switch ($operator) {
case '>':
$result = $actual > $expected;
break;
case '>=':
$result = $actual >= $expected;
break;
case '<':
$result = $actual < $expected;
break;
case '<=':
$result = $actual <= $expected;
break;
case '==':
default:
$result = $actual == $expected;
}
$message = $message ?: ($message = sprintf('The energy value of %s is %s, but %s expected.', $fieldName, $actual, $expected));
$this
->assertTrue($result, $message);
}
}