1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
4
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
5
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
6
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
7
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
8
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace MpaCustomDoctrineHydratorTest\Factory; |
12
|
|
|
|
13
|
|
|
use MpaCustomDoctrineHydrator\Form\Element\Date; |
14
|
|
|
use MpaCustomDoctrineHydratorTest\Util\ServiceManagerFactory; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Zend\Form\Element\Date as ZendDate; |
17
|
|
|
|
18
|
|
|
class DateElementFactoryTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
protected $serviceManager; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
\Locale::setDefault('fr-CH'); |
25
|
|
|
$this->serviceManager = ServiceManagerFactory::getServiceManager(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testWeCanGrabTheElementByItsFactory() |
29
|
|
|
{ |
30
|
|
|
$formElementManager = $this->serviceManager->get('FormElementManager'); |
31
|
|
|
|
32
|
|
|
$this->assertInstanceOf( |
33
|
|
|
Date::class, |
34
|
|
|
$formElementManager->get('MpaCustomDoctrineHydrator\Form\Element\Date') |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testZendFormElementDateIsOverriddenByAlias() |
39
|
|
|
{ |
40
|
|
|
$formElementManager = $this->serviceManager->get('FormElementManager'); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf( |
43
|
|
|
Date::class, |
44
|
|
|
$formElementManager->get('Zend\Form\Element\Date') |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testElementNamesOverrideZfOnes() |
49
|
|
|
{ |
50
|
|
|
$formElementManager = $this->serviceManager->get('FormElementManager'); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf(Date::class, $formElementManager->get('Date')); |
53
|
|
|
$this->assertInstanceOf(Date::class, $formElementManager->get('Zend\Form\Element\Date')); |
54
|
|
|
$this->assertInstanceOf(Date::class, $formElementManager->get(ZendDate::class)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testHasAPlaceholderAsAttribute() |
58
|
|
|
{ |
59
|
|
|
$formElementManager = $this->serviceManager->get('FormElementManager'); |
60
|
|
|
$element = $formElementManager->get('Date'); |
61
|
|
|
|
62
|
|
|
$this->assertEquals('jj.mm.aaaa', $element->getAttribute('placeholder')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testFactorySetsAFormatForDateTime() |
66
|
|
|
{ |
67
|
|
|
$formElementManager = $this->serviceManager->get('FormElementManager'); |
68
|
|
|
$element = $formElementManager->get('Date'); |
69
|
|
|
|
70
|
|
|
$this->assertEquals('d.m.Y', $element->getFormat()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|