public function FractionTargetTest::testPrepareValueFraction in Fraction 8
Same name and namespace in other branches
- 2.x tests/src/Unit/Feeds/Target/FractionTargetTest.php \Drupal\Tests\fraction\Unit\Feeds\Target\FractionTargetTest::testPrepareValueFraction()
@covers ::prepareValue
File
- tests/
src/ Unit/ Feeds/ Target/ FractionTargetTest.php, line 25
Class
- FractionTargetTest
- @coversDefaultClass \Drupal\fraction\Feeds\Target\FractionTarget @group feeds
Namespace
Drupal\Tests\fraction\Unit\Feeds\TargetCode
public function testPrepareValueFraction() {
$method = $this
->getMethod('Drupal\\fraction\\Feeds\\Target\\FractionTarget', 'prepareTarget')
->getClosure();
$configuration = [
'feed_type' => $this
->createMock('Drupal\\feeds\\FeedTypeInterface'),
'target_definition' => $method($this
->getMockFieldDefinition()),
'type' => 'fraction',
];
$target = new FractionTarget($configuration, 'fraction', []);
$method = $this
->getProtectedClosure($target, 'prepareValue');
// Test a basic fraction: 1/2.
$values = [
'value' => '1/2',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '1');
$this
->assertSame($values['denominator'], '2');
// Test that a zero numerator results in an empty fraction.
$values = [
'value' => '0/1',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '');
$this
->assertSame($values['denominator'], '');
// Test that a zero denominator results in an empty fraction.
$values = [
'value' => '1/0',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '');
$this
->assertSame($values['denominator'], '');
// Test that a negative numerator works.
$values = [
'value' => '-1/2',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '-1');
$this
->assertSame($values['denominator'], '2');
// Test that a negative denominator results in an empty fraction.
$values = [
'value' => '1/-2',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '');
$this
->assertSame($values['denominator'], '');
// Test that a decimal value results in an empty fraction.
$values = [
'value' => '1.0',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '');
$this
->assertSame($values['denominator'], '');
// Test that a non-numeric value results in an empty fraction.
$values = [
'value' => 'te/st',
];
$method(0, $values);
$this
->assertSame($values['numerator'], '');
$this
->assertSame($values['denominator'], '');
}