1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\FormBundle\Tests\Entity\PageParts; |
4
|
|
|
|
5
|
|
|
use ArrayObject; |
6
|
|
|
use Kunstmaan\FormBundle\Entity\PageParts\SingleLineTextPagePart; |
7
|
|
|
use Kunstmaan\FormBundle\Form\SingleLineTextPagePartAdminType; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests for SingleLineTextPagePart |
13
|
|
|
*/ |
14
|
|
|
class SingleLineTextPagePartTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var SingleLineTextPagePart |
18
|
|
|
*/ |
19
|
|
|
protected $object; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Sets up the fixture, for example, opens a network connection. |
23
|
|
|
* This method is called before a test is executed. |
24
|
|
|
*/ |
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->object = new SingleLineTextPagePart(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSetGetRegex() |
31
|
|
|
{ |
32
|
|
|
$object = $this->object; |
33
|
|
|
$regex = '.*example.*'; |
34
|
|
|
$object->setRegex($regex); |
35
|
|
|
$this->assertEquals($regex, $object->getRegex()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSetErrorMessageRegex() |
39
|
|
|
{ |
40
|
|
|
$object = $this->object; |
41
|
|
|
$message = 'Some example error message'; |
42
|
|
|
$object->setErrorMessageRegex($message); |
43
|
|
|
$this->assertEquals($message, $object->getErrorMessageRegex()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetDefaultView() |
47
|
|
|
{ |
48
|
|
|
$stringValue = $this->object->getDefaultView(); |
49
|
|
|
$this->assertNotNull($stringValue); |
50
|
|
|
$this->assertInternalType('string', $stringValue); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testAdaptForm() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$object = $this->object; |
56
|
|
|
$object->setRequired(true); |
57
|
|
|
$object->setRegex('.*example.*'); |
58
|
|
|
|
59
|
|
|
$formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder') |
60
|
|
|
->disableOriginalConstructor() |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
$formBuilder->expects($this->any()) |
64
|
|
|
->method('getData') |
65
|
|
|
->willReturn([]); |
66
|
|
|
|
67
|
|
|
$fields = new ArrayObject(); |
68
|
|
|
|
69
|
|
|
$object->setErrorMessageRequired('required'); |
70
|
|
|
$object->setErrorMessageRegex('regex'); |
71
|
|
|
$this->assertEquals(count($fields), 0); |
72
|
|
|
/* @var FormBuilderInterface $formBuilder */ |
73
|
|
|
$object->adaptForm($formBuilder, $fields, 0); |
74
|
|
|
$this->assertTrue(count($fields) > 0); |
75
|
|
|
$this->assertTrue($object->getRequired()); |
76
|
|
|
|
77
|
|
|
$this->assertEquals('required', $object->getErrorMessageRequired()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetDefaultAdminType() |
81
|
|
|
{ |
82
|
|
|
$this->assertEquals(SingleLineTextPagePartAdminType::class, $this->object->getDefaultAdminType()); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.