|
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
|
|
|
|
|
15
|
|
|
namespace Dealer\Test\Loop; |
|
16
|
|
|
|
|
17
|
|
|
use Dealer\Loop\DealerLoop; |
|
18
|
|
|
use Dealer\Model\Dealer; |
|
19
|
|
|
use Dealer\Service\DealerService; |
|
20
|
|
|
use Dealer\Test\PhpUnit\Base\AbstractPropelTest; |
|
21
|
|
|
use Propel\Runtime\Util\PropelModelPager; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
23
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
24
|
|
|
|
|
25
|
|
|
class DealerLoopTest extends AbstractPropelTest |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** @var DealerLoop $loop */ |
|
29
|
|
|
protected $loop; |
|
30
|
|
|
|
|
31
|
|
|
/** @var Dealer $dealer */ |
|
32
|
|
|
protected $dealer; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Expected possible values for the order loop argument. |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected static $VALID_ORDER = [ |
|
39
|
|
|
'id', |
|
40
|
|
|
'id-reverse', |
|
41
|
|
|
'date', |
|
42
|
|
|
'date-reverse' |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
public function setUp() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->loop = new DealerLoop($this->container); |
|
48
|
|
|
|
|
49
|
|
|
$this->mockEventDispatcher = $this->getMockBuilder(EventDispatcher::class) |
|
50
|
|
|
->setMethods(['dispatch']) |
|
51
|
|
|
->getMock(); |
|
52
|
|
|
|
|
53
|
|
|
$dealerService = new DealerService(); |
|
54
|
|
|
$dealerService->setDispatcher($this->mockEventDispatcher); |
|
55
|
|
|
|
|
56
|
|
|
$this->dealer = $dealerService->createFromArray($this->dataDealerRequire(), "fr_FR"); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @inheritDoc |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function buildContainer(ContainerBuilder $container) |
|
63
|
|
|
{ |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @covers \Dealer\Loop\DealerLoop::initializeArgs() |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testHasNoMandatoryArguments() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->loop->initializeArgs([]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers \Dealer\Loop\DealerLoop::initializeArgs() |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testAcceptsAllOrderArguments() |
|
78
|
|
|
{ |
|
79
|
|
|
foreach (static::$VALID_ORDER as $order) { |
|
80
|
|
|
$this->loop->initializeArgs(["order" => $order]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers \Dealer\Loop\DealerLoop::initializeArgs() |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testAcceptsAllArguments() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->loop->initializeArgs($this->getTestArg()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @covers \Dealer\Loop\DealerLoop::buildModelCriteria() |
|
94
|
|
|
* @covers \Dealer\Loop\DealerLoop::exec() |
|
95
|
|
|
* @covers \Dealer\Loop\DealerLoop::parseResults() |
|
96
|
|
|
*/ |
|
97
|
|
|
public function testHasExpectedOutput() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->loop->initializeArgs($this->getTestArg()); |
|
100
|
|
|
$loopResult = $this->loop->exec( |
|
101
|
|
|
new PropelModelPager($this->loop->buildModelCriteria()) |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertEquals(1, $loopResult->getCount()); |
|
105
|
|
|
$loopResult->rewind(); |
|
106
|
|
|
$loopResultRow = $loopResult->current(); |
|
107
|
|
|
$this->assertEquals($this->dealer->getId(), $loopResultRow->get("ID")); |
|
108
|
|
|
$this->assertEquals($this->dealer->getCountryId(), $loopResultRow->get("COUNTRY_ID")); |
|
109
|
|
|
$this->assertEquals($this->dealer->getCity(), $loopResultRow->get("CITY")); |
|
110
|
|
|
$this->assertEquals($this->dealer->getAddress1(), $loopResultRow->get("ADDRESS1")); |
|
111
|
|
|
$this->assertEquals($this->dealer->getTitle(), $loopResultRow->get("TITLE")); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
protected function getTestArg() |
|
115
|
|
|
{ |
|
116
|
|
|
return [ |
|
117
|
|
|
"id" => $this->dealer->getId(), |
|
118
|
|
|
"country_id" => $this->dealer->getCountryId(), |
|
119
|
|
|
"city" => $this->dealer->getCity() |
|
120
|
|
|
]; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
protected function dataDealerRequire() |
|
124
|
|
|
{ |
|
125
|
|
|
return [ |
|
126
|
|
|
"title" => "Openstudio", |
|
127
|
|
|
"address1" => "5 rue jean rochon", |
|
128
|
|
|
"zipcode" => "63000", |
|
129
|
|
|
"city" => "test", |
|
130
|
|
|
"country_id" => "64", |
|
131
|
|
|
]; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|