‪TYPO3CMS  9.5
IntegerConverterTest.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 ‪IntegerConverterTest extends UnitTestCase
23 {
27  protected ‪$converter;
28 
29  protected function ‪setUp()
30  {
31  $this->converter = new \TYPO3\CMS\Extbase\Property\TypeConverter\IntegerConverter();
32  }
33 
37  public function ‪checkMetadata()
38  {
39  $this->assertEquals(['integer', 'string'], $this->converter->getSupportedSourceTypes(), 'Source types do not match');
40  $this->assertEquals('integer', $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(15, $this->converter->convertFrom('15', 'integer'));
50  }
51 
55  public function ‪convertFromDoesNotModifyIntegers()
56  {
57  $source = 123;
58  $this->assertSame($source, $this->converter->convertFrom($source, 'integer'));
59  }
60 
65  {
66  $this->assertNull($this->converter->convertFrom('', 'integer'));
67  }
68 
73  {
74  $this->assertInstanceOf(\‪TYPO3\CMS\‪Extbase\Error\Error::class, $this->converter->convertFrom('not numeric', 'integer'));
75  }
76 
81  {
82  $this->assertTrue($this->converter->canConvertFrom('15', 'integer'));
83  }
84 
89  {
90  $this->assertTrue($this->converter->canConvertFrom(123, 'integer'));
91  }
92 
97  {
98  $this->assertTrue($this->converter->canConvertFrom('', 'integer'));
99  }
100 
105  {
106  $this->assertTrue($this->converter->canConvertFrom(null, 'integer'));
107  }
108 
113  {
114  $this->assertEquals([], $this->converter->getSourceChildPropertiesToBeConverted('myString'));
115  }
116 }
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\setUp
‪setUp()
Definition: IntegerConverterTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric
‪convertFromReturnsAnErrorIfSpecifiedStringIsNotNumeric()
Definition: IntegerConverterTest.php:71
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromReturnsNullIfEmptyStringSpecified
‪convertFromReturnsNullIfEmptyStringSpecified()
Definition: IntegerConverterTest.php:63
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForANumericStringSource
‪canConvertFromShouldReturnTrueForANumericStringSource()
Definition: IntegerConverterTest.php:79
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\$converter
‪TYPO3 CMS Extbase Property TypeConverterInterface $converter
Definition: IntegerConverterTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter
Definition: ArrayConverterTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForAnEmptyValue
‪canConvertFromShouldReturnTrueForAnEmptyValue()
Definition: IntegerConverterTest.php:95
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\checkMetadata
‪checkMetadata()
Definition: IntegerConverterTest.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForAnIntegerSource
‪canConvertFromShouldReturnTrueForAnIntegerSource()
Definition: IntegerConverterTest.php:87
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest
Definition: IntegerConverterTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromDoesNotModifyIntegers
‪convertFromDoesNotModifyIntegers()
Definition: IntegerConverterTest.php:54
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray
‪getSourceChildPropertiesToBeConvertedShouldReturnEmptyArray()
Definition: IntegerConverterTest.php:111
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\canConvertFromShouldReturnTrueForANullValue
‪canConvertFromShouldReturnTrueForANullValue()
Definition: IntegerConverterTest.php:103
‪TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\IntegerConverterTest\convertFromShouldCastTheStringToInteger
‪convertFromShouldCastTheStringToInteger()
Definition: IntegerConverterTest.php:46