[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Property / TypeConverter / ArrayConverterTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter;
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 /**
18 * Test case
19 */
20 class ArrayConverterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Property\TypeConverter\ArrayConverter
24 */
25 protected $converter;
26
27 public function setUp() {
28 $this->converter = new \TYPO3\CMS\Extbase\Property\TypeConverter\ArrayConverter();
29 }
30
31 /**
32 * @test
33 */
34 public function checkMetadata() {
35 $this->assertEquals(array('array', 'string'), $this->converter->getSupportedSourceTypes(), 'Source types do not match');
36 $this->assertEquals('array', $this->converter->getSupportedTargetType(), 'Target type does not match');
37 $this->assertEquals(1, $this->converter->getPriority(), 'Priority does not match');
38 }
39
40 /**
41 * @test
42 */
43 public function convertFromDoesNotModifyTheSourceArray() {
44 $sourceArray = array('Foo' => 'Bar', 'Baz');
45 $this->assertEquals($sourceArray, $this->converter->convertFrom($sourceArray, 'array'));
46 }
47
48 /**
49 * @return array
50 */
51 public function stringToArrayDataProvider() {
52 return array(
53 'Empty string to empty array' => array('', array()),
54 );
55 }
56
57 /**
58 * @test
59 * @dataProvider stringToArrayDataProvider
60 *
61 * @param string $source
62 * @param array $expectedResult
63 */
64 public function canConvertFromEmptyString($source, $expectedResult) {
65 $this->assertEquals($expectedResult, $this->converter->convertFrom($source, 'array'));
66 }
67
68 /**
69 * @return array
70 */
71 public function canConvertFromDataProvider() {
72 return array(
73 'Can convert empty string' => array('', TRUE),
74 'Can not convert not empty string' => array('foo', FALSE),
75 'Can convert array' => array(array('foo'), TRUE),
76 );
77 }
78
79 /**
80 * @test
81 * @dataProvider canConvertFromDataProvider
82 *
83 * @param mixed $source
84 * @param boolean $expectedResult
85 */
86 public function canConvertFromReturnsCorrectBooleans($source, $expectedResult) {
87 $this->assertSame($expectedResult, $this->converter->canConvertFrom($source, 'array'));
88 }
89 }