‪TYPO3CMS  9.5
FloatConverterTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪FloatConverterTest extends UnitTestCase
23 {
27  protected ‪$converter;
28 
29  protected function ‪setUp()
30  {
31  $this->converter = new \TYPO3\CMS\Extbase\Property\TypeConverter\FloatConverter();
32  }
33 
37  public function ‪checkMetadata()
38  {
39  $this->assertEquals(['float', 'integer', 'string'], $this->converter->getSupportedSourceTypes(), 'Source types do not match');
40  $this->assertEquals('float', $this->converter->getSupportedTargetType(), 'Target type does not match');
41  $this->assertEquals(10, $this->converter->getPriority(), 'Priority does not match');
42  }
43 
48  {
49  $this->assertSame(1.5, $this->converter->convertFrom('1.5', 'float'));
50  }
51 
56  {
57  $this->assertNull($this->converter->convertFrom('', 'float'));
58  }
59 
63  public function ‪convertFromShouldAcceptIntegers()
64  {
65  $this->assertSame((float)123, $this->converter->convertFrom(123, 'float'));
66  }
67 
72  {
73  $mockMappingConfiguration = $this->createMock(\‪TYPO3\CMS\‪Extbase\Property\PropertyMappingConfigurationInterface::class);
74  $mockMappingConfiguration
75  ->expects($this->at(0))
76  ->method('getConfigurationValue')
77  ->with(\‪TYPO3\CMS\‪Extbase\Property\TypeConverter\FloatConverter::class, \‪TYPO3\CMS\‪Extbase\Property\TypeConverter\FloatConverter::CONFIGURATION_THOUSANDS_SEPARATOR)
78  ->willReturn('.');
79  $mockMappingConfiguration
80  ->expects($this->at(1))
81  ->method('getConfigurationValue')
82  ->with(\‪TYPO3\CMS\‪Extbase\Property\TypeConverter\FloatConverter::class, \‪TYPO3\CMS\‪Extbase\Property\TypeConverter\FloatConverter::CONFIGURATION_DECIMAL_POINT)
83  ->willReturn(',');
84  $this->assertSame(1024.42, $this->converter->convertFrom('1.024,42', 'float', [], $mockMappingConfiguration));
85  }
86 
91  {
92  $this->assertInstanceOf(\‪TYPO3\CMS\‪Extbase\Error\Error::class, $this->converter->convertFrom('not numeric', 'float'));
93  }
94 
98  public function ‪canConvertFromShouldReturnTrue()
99  {
100  $this->assertTrue($this->converter->canConvertFrom('1.5', 'float'));
101  }
102 
107  {
108  $this->assertTrue($this->converter->canConvertFrom('', 'integer'));
109  }
110 
115  {
116  $this->assertTrue($this->converter->canConvertFrom(null, 'integer'));
117  }
118 
123  {
124  $this->assertEquals([], $this->converter->getSourceChildPropertiesToBeConverted('myString'));
125  }
126 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrueForAnEmptyValue
‪canConvertFromShouldReturnTrueForAnEmptyValue()
Definition: FloatConverterTest.php:105
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsNullIfEmptyStringSpecified
‪convertFromReturnsNullIfEmptyStringSpecified()
Definition: FloatConverterTest.php:54
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrue
‪canConvertFromShouldReturnTrue()
Definition: FloatConverterTest.php:97
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldRespectConfiguration
‪convertFromShouldRespectConfiguration()
Definition: FloatConverterTest.php:70
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldAcceptIntegers
‪convertFromShouldAcceptIntegers()
Definition: FloatConverterTest.php:62
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter
Definition: ArrayConverterTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\canConvertFromShouldReturnTrueForANullValue
‪canConvertFromShouldReturnTrueForANullValue()
Definition: FloatConverterTest.php:113
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\checkMetadata
‪checkMetadata()
Definition: FloatConverterTest.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric
‪convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric()
Definition: FloatConverterTest.php:89
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest
Definition: FloatConverterTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\convertFromShouldCastTheStringToFloat
‪convertFromShouldCastTheStringToFloat()
Definition: FloatConverterTest.php:46
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray
‪getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray()
Definition: FloatConverterTest.php:121
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\$converter
‪TYPO3 CMS Extbase Property TypeConverterInterface $converter
Definition: FloatConverterTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\FloatConverterTest\setUp
‪setUp()
Definition: FloatConverterTest.php:28