|
1
|
|
|
<?php |
|
2
|
|
|
/*************************************************************************************/ |
|
3
|
|
|
/* This file is part of the Thelia package. */ |
|
4
|
|
|
/* */ |
|
5
|
|
|
/* Copyright (c) OpenStudio */ |
|
6
|
|
|
/* email : [email protected] */ |
|
7
|
|
|
/* web : http://www.thelia.net */ |
|
8
|
|
|
/* */ |
|
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
|
10
|
|
|
/* file that was distributed with this source code. */ |
|
11
|
|
|
/*************************************************************************************/ |
|
12
|
|
|
/*************************************************************************************/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Dealer\Test\Loop; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
use Dealer\Loop\SchedulesLoop; |
|
18
|
|
|
use Dealer\Model\Dealer; |
|
19
|
|
|
use Dealer\Model\DealerShedules; |
|
20
|
|
|
use Dealer\Service\DealerService; |
|
21
|
|
|
use Dealer\Service\SchedulesService; |
|
22
|
|
|
use Dealer\Test\PhpUnit\Base\AbstractPropelTest; |
|
23
|
|
|
use Propel\Runtime\Util\PropelModelPager; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
25
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
26
|
|
|
|
|
27
|
|
|
class SchedulesLoopTest extends AbstractPropelTest |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var SchedulesLoop $loop */ |
|
30
|
|
|
protected $loop; |
|
31
|
|
|
|
|
32
|
|
|
/** @var Dealer $dealer */ |
|
33
|
|
|
protected $dealer; |
|
34
|
|
|
|
|
35
|
|
|
/** @var DealerShedules $dealer */ |
|
36
|
|
|
protected $defaultSchedules; |
|
37
|
|
|
|
|
38
|
|
|
/** @var DealerShedules $dealer */ |
|
39
|
|
|
protected $extraSchedules; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritDoc |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function buildContainer(ContainerBuilder $container) |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Expected possible values for the order loop argument. |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected static $VALID_ORDER = [ |
|
54
|
|
|
'id', |
|
55
|
|
|
'id-reverse', |
|
56
|
|
|
'day', |
|
57
|
|
|
'day-reverse', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
public function setUp() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->loop = new SchedulesLoop($this->container); |
|
63
|
|
|
|
|
64
|
|
|
$this->mockEventDispatcher = $this->getMockBuilder(EventDispatcher::class) |
|
65
|
|
|
->setMethods(['dispatch']) |
|
66
|
|
|
->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
/* Create Test Dealer */ |
|
69
|
|
|
$dealerService = new DealerService(); |
|
70
|
|
|
$dealerService->setDispatcher($this->mockEventDispatcher); |
|
71
|
|
|
$this->dealer = $dealerService->createFromArray($this->dataDealerRequire(), "fr_FR"); |
|
72
|
|
|
|
|
73
|
|
|
/* Create Test Schedules */ |
|
74
|
|
|
$schedulesService = new SchedulesService(); |
|
75
|
|
|
$schedulesService->setDispatcher($this->mockEventDispatcher); |
|
76
|
|
|
|
|
77
|
|
|
$this->defaultSchedules = $schedulesService->createFromArray($this->dataDefaultRequire(), "fr_FR"); |
|
78
|
|
|
$this->extraSchedules = $schedulesService->createFromArray($this->dataExtraRequire(), "fr_FR"); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::initializeArgs() |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testHasNoMandatoryArguments() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->loop->initializeArgs([]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::initializeArgs() |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testAcceptsAllOrderArguments() |
|
93
|
|
|
{ |
|
94
|
|
|
foreach (static::$VALID_ORDER as $order) { |
|
95
|
|
|
$this->loop->initializeArgs(["order" => $order]); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::initializeArgs() |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testAcceptsAllDefaultArguments() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->loop->initializeArgs($this->getTestDefaultArg()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::initializeArgs() |
|
109
|
|
|
*/ |
|
110
|
|
|
public function testAcceptsAllExtraArguments() |
|
111
|
|
|
{ |
|
112
|
|
|
$this->loop->initializeArgs($this->getTestExtraArg()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::buildModelCriteria() |
|
117
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::exec() |
|
118
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::parseResults() |
|
119
|
|
|
*/ |
|
120
|
|
|
public function testHasExpectedDefaultOutput() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->loop->initializeArgs($this->getTestDefaultArg()); |
|
123
|
|
|
$loopResult = $this->loop->exec( |
|
124
|
|
|
new PropelModelPager($this->loop->buildModelCriteria()) |
|
125
|
|
|
); |
|
126
|
|
|
|
|
127
|
|
|
$this->assertEquals(1, $loopResult->getCount()); |
|
128
|
|
|
$loopResult->rewind(); |
|
129
|
|
|
$loopResultRow = $loopResult->current(); |
|
130
|
|
|
$this->assertEquals($this->defaultSchedules->getId(), $loopResultRow->get("ID")); |
|
131
|
|
|
$this->assertEquals($this->defaultSchedules->getDay(), $loopResultRow->get("DAY")); |
|
132
|
|
|
$this->assertEquals($this->defaultSchedules->getBegin(), $loopResultRow->get("BEGIN")); |
|
133
|
|
|
$this->assertEquals($this->defaultSchedules->getEnd(), $loopResultRow->get("END")); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::buildModelCriteria() |
|
138
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::exec() |
|
139
|
|
|
* @covers \Dealer\Loop\SchedulesLoop::parseResults() |
|
140
|
|
|
*/ |
|
141
|
|
|
public function testHasExpectedExtraOutput() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->loop->initializeArgs($this->getTestExtraArg()); |
|
144
|
|
|
$loopResult = $this->loop->exec( |
|
145
|
|
|
new PropelModelPager($this->loop->buildModelCriteria()) |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$this->assertEquals(1, $loopResult->getCount()); |
|
149
|
|
|
$loopResult->rewind(); |
|
150
|
|
|
$loopResultRow = $loopResult->current(); |
|
151
|
|
|
$this->assertEquals($this->extraSchedules->getId(), $loopResultRow->get("ID")); |
|
152
|
|
|
$this->assertEquals($this->extraSchedules->getDay(), $loopResultRow->get("DAY")); |
|
153
|
|
|
$this->assertEquals($this->extraSchedules->getBegin(), $loopResultRow->get("BEGIN")); |
|
154
|
|
|
$this->assertEquals($this->extraSchedules->getEnd(), $loopResultRow->get("END")); |
|
155
|
|
|
$this->assertEquals($this->extraSchedules->getPeriodBegin(), $loopResultRow->get("PERIOD_BEGIN")); |
|
156
|
|
|
$this->assertEquals($this->extraSchedules->getPeriodEnd(), $loopResultRow->get("PERIOD_END")); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
protected function getTestDefaultArg() |
|
161
|
|
|
{ |
|
162
|
|
|
return [ |
|
163
|
|
|
"id" => $this->defaultSchedules->getId(), |
|
164
|
|
|
"dealer_id" => $this->defaultSchedules->getDealerId(), |
|
165
|
|
|
"day" => $this->defaultSchedules->getDay(), |
|
166
|
|
|
"default_period" => true, |
|
167
|
|
|
]; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
protected function getTestExtraArg() |
|
171
|
|
|
{ |
|
172
|
|
|
return [ |
|
173
|
|
|
"id" => $this->extraSchedules->getId(), |
|
174
|
|
|
"dealer_id" => $this->extraSchedules->getDealerId(), |
|
175
|
|
|
"day" => $this->extraSchedules->getDay(), |
|
176
|
|
|
"default_period" => false, |
|
177
|
|
|
]; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
protected function dataDefaultRequire() |
|
181
|
|
|
{ |
|
182
|
|
|
return [ |
|
183
|
|
|
"day" => 0, |
|
184
|
|
|
"begin" => "8:00", |
|
185
|
|
|
"end" => "10:00", |
|
186
|
|
|
"dealer_id" => $this->dealer->getId() |
|
187
|
|
|
]; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
protected function dataExtraRequire() |
|
191
|
|
|
{ |
|
192
|
|
|
return [ |
|
193
|
|
|
"day" => 0, |
|
194
|
|
|
"begin" => "8:00", |
|
195
|
|
|
"end" => "10:00", |
|
196
|
|
|
"period_begin" => "2015-11-11", |
|
197
|
|
|
"period_end" => "2016-11-16", |
|
198
|
|
|
"dealer_id" => $this->dealer->getId() |
|
199
|
|
|
]; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
protected function dataDealerRequire() |
|
203
|
|
|
{ |
|
204
|
|
|
return [ |
|
205
|
|
|
"title" => "Openstudio", |
|
206
|
|
|
"address1" => "5 rue jean rochon", |
|
207
|
|
|
"zipcode" => "63000", |
|
208
|
|
|
"city" => "test", |
|
209
|
|
|
"country_id" => "64", |
|
210
|
|
|
]; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|