|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2015 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace JobsTest\Form; |
|
12
|
|
|
|
|
13
|
|
|
use Jobs\Entity\Job; |
|
14
|
|
|
use Jobs\Form\CompanyName; |
|
15
|
|
|
use Organizations\Entity\Organization; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Tests for \Jobs\Form\CompanyName |
|
19
|
|
|
* |
|
20
|
|
|
* @covers \Jobs\Form\CompanyName |
|
21
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
22
|
|
|
* @group Jobs |
|
23
|
|
|
* @group Jobs.Form |
|
24
|
|
|
*/ |
|
25
|
|
|
class CompanyNameTest extends \PHPUnit_Framework_TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @testdox Extends \Core\Form\SummaryForm and implements \Zend\InputFilter\InputFilterProviderInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testExtendsSummaryFormAndImplementsInputFilterProviderInterface() |
|
32
|
|
|
{ |
|
33
|
|
|
$target = new CompanyName(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf('\Core\Form\SummaryForm', $target, 'Wrong parent class!'); |
|
36
|
|
|
$this->assertInstanceOf('\Zend\InputFilter\InputFilterProviderInterface', $target, 'Missing interface implementation.'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @testdox Defines default values for properties derived from \Core\Form\SummaryForm |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testDefaultPropertiesValues() |
|
43
|
|
|
{ |
|
44
|
|
|
$target = new CompanyName(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertAttributeEquals('Jobs/CompanyNameFieldset', 'baseFieldset', $target, 'baseFieldset set incorrect.'); |
|
47
|
|
|
$this->assertAttributeEquals('Companyname', 'label', $target, 'label set incorrect.'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @testdox returns a \Core\Entity\Hydrator\EntityHydrator if none is set. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testReturnsEntityHydrator() |
|
54
|
|
|
{ |
|
55
|
|
|
$target = new CompanyName(); |
|
56
|
|
|
$baseFieldsetMock = $this->getMockBuilder('\Jobs\Form\CompanyNameFieldset')->disableOriginalConstructor()->getMock(); |
|
57
|
|
|
$baseFieldsetMock->expects($this->once())->method('setHydrator')->will($this->returnSelf()); |
|
58
|
|
|
|
|
59
|
|
|
$target->setBaseFieldset($baseFieldsetMock); |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$hydrator = $target->getHydrator(); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$this->assertInstanceOf('\Core\Entity\Hydrator\EntityHydrator', $hydrator); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testReturnsInputFilterSpecificationsForItsElements() |
|
69
|
|
|
{ |
|
70
|
|
|
$formName = 'TestCompanyName'; |
|
71
|
|
|
$target = new CompanyName(); |
|
72
|
|
|
$baseFieldsetMock = $this->getMockBuilder('\Jobs\Form\CompanyNameFieldset')->disableOriginalConstructor()->getMock(); |
|
73
|
|
|
$baseFieldsetMock->expects($this->once())->method('getAttribute')->willReturn($formName); |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$target->setBaseFieldset($baseFieldsetMock); |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$expected = array( |
|
80
|
|
|
$formName => array( |
|
81
|
|
|
'type' => 'Jobs/Company' |
|
82
|
|
|
) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals($expected, $target->getInputFilterSpecification()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function provideInjectOrganizationTestData() |
|
89
|
|
|
{ |
|
90
|
|
|
$org = new Organization(); |
|
91
|
|
|
$org->setId('alreadyHereOrg'); |
|
92
|
|
|
|
|
93
|
|
|
$job = new Job(); |
|
94
|
|
|
$job->setOrganization($org); |
|
95
|
|
|
|
|
96
|
|
|
return array( |
|
97
|
|
|
array(new \stdClass, 'default'), |
|
98
|
|
|
array($job, 'default'), |
|
99
|
|
|
array(new Job(), 'one'), |
|
100
|
|
|
array(new Job(), 'more'), |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @testdox injects organization into the job entity if no hiring organizations are set. |
|
106
|
|
|
* @dataProvider provideInjectOrganizationTestData |
|
107
|
|
|
*/ |
|
108
|
|
|
public function testSetObjectInjectsOrganizationsInJobEntity($object, $setupKey) |
|
109
|
|
|
{ |
|
110
|
|
|
$mocks = $this->setupInjectOrganizationTestMocks($setupKey, $object); |
|
111
|
|
|
|
|
112
|
|
|
$actual = $mocks->target->setObject($object); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertSame($actual, $mocks->target, 'Fluent interface broken'); |
|
115
|
|
|
if ('one' == $setupKey) { |
|
116
|
|
|
$this->assertEquals(CompanyName::DISPLAY_SUMMARY, $mocks->target->getDisplayMode()); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
private function setupInjectOrganizationTestMocks($key, $object) |
|
121
|
|
|
{ |
|
122
|
|
|
$fs = $this->getMockBuilder('\Jobs\Form\CompanyNameFieldset')->disableOriginalConstructor()->getMock(); |
|
123
|
|
|
$select = $this->getMockBuilder('\Jobs\Form\HiringOrganizationSelect')->disableOriginalConstructor()->getMock(); |
|
124
|
|
|
$hydrator = $this->getMockBuilder('\Core\Entity\Hydrator\EntityHydrator')->disableOriginalConstructor()->getMock(); |
|
125
|
|
|
|
|
126
|
|
|
switch ($key) { |
|
127
|
|
|
default: |
|
128
|
|
|
$fs->expects($this->never())->method('get'); |
|
129
|
|
|
$fs->expects($this->never())->method('getHydrator'); |
|
130
|
|
|
$hydrator->expects($this->never())->method('hydrate'); |
|
131
|
|
|
break; |
|
132
|
|
|
|
|
133
|
|
|
case 'one': |
|
134
|
|
|
$orgValues = array('id1' => 'testOnlyOne'); |
|
135
|
|
|
$select->expects($this->once())->method('setValue')->with(key($orgValues)); |
|
136
|
|
|
$fs->expects($this->once())->method('getHydrator')->willReturn($hydrator); |
|
137
|
|
|
$hydrator->expects($this->once())->method('hydrate')->with(array('companyId' => key($orgValues)), $object); |
|
138
|
|
|
|
|
139
|
|
|
// fall through intentinally |
|
140
|
|
|
case 'more': |
|
141
|
|
|
$fs->expects($this->once())->method('get')->with('companyId')->willReturn($select); |
|
142
|
|
|
if (!isset($orgValues)) { |
|
143
|
|
|
$orgValues = array('id1' => 'test1', 'id2', 'test2'); |
|
144
|
|
|
} |
|
145
|
|
|
$select->expects($this->once())->method('getValueOptions')->willReturn($orgValues); |
|
146
|
|
|
break; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
$mocks = new \stdClass(); |
|
150
|
|
|
$mocks->target = new CompanyName(); |
|
151
|
|
|
$mocks->target->setBaseFieldset($fs); |
|
152
|
|
|
$mocks->baseFieldset = $fs; |
|
153
|
|
|
$mocks->selectElement = $select; |
|
154
|
|
|
$mocks->hydrator = $hydrator; |
|
155
|
|
|
|
|
156
|
|
|
return $mocks; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|