|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace JobsTest\Form; |
|
12
|
|
|
|
|
13
|
|
|
use Jobs\Form\OrganizationSelect; |
|
14
|
|
|
use Organizations\Entity\Organization; |
|
15
|
|
|
use Organizations\Entity\OrganizationContact; |
|
16
|
|
|
use Organizations\Entity\OrganizationName; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Tests for \Jobs\Form\OrganizationSelect |
|
20
|
|
|
* |
|
21
|
|
|
* @covers \Jobs\Form\OrganizationSelect |
|
22
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
class OrganizationSelectTest extends \PHPUnit_Framework_TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
* |
|
30
|
|
|
* @var OrganizationSelect |
|
31
|
|
|
*/ |
|
32
|
|
|
private $target; |
|
33
|
|
|
|
|
34
|
|
|
public function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->target = new OrganizationSelect(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @testdox Extends \Zend\Form\Element\Select and implements \Core\Form\HeadscriptProviderInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testExtendsSelectAndImplementsHeadscriptProviderInterface() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->assertInstanceOf('\Zend\Form\Element\Select', $this->target); |
|
45
|
|
|
$this->assertInstanceOf('\Core\Form\HeadscriptProviderInterface', $this->target); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @testdox Allow setting and getting of headscripts |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testSetAndGetHeadscripts() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertEquals([ 'Jobs/js/form.organization-select.js' ], $this->target->getHeadscripts()); |
|
55
|
|
|
$this->assertSame($this->target, $this->target->setHeadscripts([ 'script1' ]), 'Fluent interface broken on "setHeadscripts"'); |
|
56
|
|
|
$this->assertEquals([ 'script1' ], $this->target->getHeadscripts()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testSetsDefaultAttributesOnInit() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->target->init(); |
|
62
|
|
|
|
|
63
|
|
|
$atts = $this->target->getAttributes(); |
|
64
|
|
|
$this->assertArrayHasKey('data-autoinit', $atts); |
|
65
|
|
|
$this->assertArrayHasKey('data-element', $atts); |
|
66
|
|
|
$this->assertEquals('false', $atts['data-autoinit']); |
|
67
|
|
|
$this->assertEquals('organization-select', $atts['data-element']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function provideSetSelectableOrganizationsTestData() |
|
71
|
|
|
{ |
|
72
|
|
|
$org1 = new OrganizationEntityMock([ |
|
73
|
|
|
'id' => 'org1', |
|
74
|
|
|
'name' => 'Org1', |
|
75
|
|
|
'city' => 'City1', |
|
76
|
|
|
'street' => 'Street1', |
|
77
|
|
|
'number' => 'Number1', |
|
78
|
|
|
]); |
|
79
|
|
|
|
|
80
|
|
|
return [ |
|
81
|
|
|
[ [ $org1 ], false ], |
|
82
|
|
|
[ [ $org1 ], true ], |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* |
|
89
|
|
|
* @dataProvider provideSetSelectableOrganizationsTestData |
|
90
|
|
|
* |
|
91
|
|
|
* @param $orgs |
|
92
|
|
|
* @param $addEmptyOption |
|
93
|
|
|
*/ |
|
94
|
|
|
public function testSetSelectableOrganizations($orgs, $addEmptyOption) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->assertSame($this->target, $this->target->setSelectableOrganizations($orgs, $addEmptyOption), 'Fluent interface broken'); |
|
97
|
|
|
|
|
98
|
|
|
$values = $this->target->getValueOptions(); |
|
99
|
|
|
|
|
100
|
|
|
if ($addEmptyOption) { |
|
101
|
|
|
$this->assertArrayHasKey('0', $values, 'Empty option was not created'); |
|
102
|
|
|
$this->assertEquals(count($orgs) + 1, count($values)); |
|
103
|
|
|
} else { |
|
104
|
|
|
$this->assertEquals(count($orgs), count($values)); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
class OrganizationEntityMock extends Organization |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
public function __construct(array $values) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->id = $values['id']; |
|
115
|
|
|
$this->organizationName = new OrganizationName($values['name']); |
|
116
|
|
|
$contact = new OrganizationContact(); |
|
117
|
|
|
$contact->setCity($values['city'])->setStreet($values['street'])->setHouseNumber($values['number']); |
|
118
|
|
|
$this->contact = $contact; |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
} |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.