1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2016 Jan Eichhorn <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApaiIO\Test\Operations\Types; |
19
|
|
|
|
20
|
|
|
use ApaiIO\Operations\Lookup; |
21
|
|
|
|
22
|
|
|
class LookupTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
public function testSetter() |
25
|
|
|
{ |
26
|
|
|
$lookup = new Lookup(); |
27
|
|
|
$lookup->setItemId('B1234'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @expectedException \Exception |
32
|
|
|
*/ |
33
|
|
|
public function testSettersNegative() |
34
|
|
|
{ |
35
|
|
|
$lookup = new Lookup(); |
36
|
|
|
$lookup->setItemIds([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testMultiItemSet() |
40
|
|
|
{ |
41
|
|
|
$lookup = new Lookup(); |
42
|
|
|
$lookup->setItemIds([1, 2, 3, 4]); |
43
|
|
|
|
44
|
|
|
$itemQuery = $lookup->getItemId(); |
45
|
|
|
|
46
|
|
|
$this->assertSame('1,2,3,4', $itemQuery); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetName() |
50
|
|
|
{ |
51
|
|
|
$lookup = new Lookup(); |
52
|
|
|
$this->assertEquals('ItemLookup', $lookup->getName()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetIdType() |
56
|
|
|
{ |
57
|
|
|
$lookup = new Lookup(); |
58
|
|
|
$valididTypes = [ |
59
|
|
|
'ASIN', |
60
|
|
|
'SKU', |
61
|
|
|
'UPC', |
62
|
|
|
'EAN', |
63
|
|
|
'ISBN', |
64
|
|
|
Lookup::TYPE_ASIN, |
65
|
|
|
Lookup::TYPE_SKU, |
66
|
|
|
Lookup::TYPE_UPC, |
67
|
|
|
Lookup::TYPE_EAN, |
68
|
|
|
Lookup::TYPE_ISBN |
69
|
|
|
]; |
70
|
|
|
foreach ($valididTypes as $valididType) { |
71
|
|
|
$lookup->setIdType($valididType); |
72
|
|
|
$this->assertEquals($valididType, $lookup->getIdType()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @dataProvider providerSetIdTypeAffectsSearchIndex |
78
|
|
|
* |
79
|
|
|
* @param string $idType |
80
|
|
|
* @param string|null $expectedSearchIndex |
81
|
|
|
*/ |
82
|
|
|
public function testSetIdTypeAffectsSearchIndex($idType, $expectedSearchIndex) |
83
|
|
|
{ |
84
|
|
|
$lookup = new Lookup(); |
85
|
|
|
$lookup->setIdType($idType); |
86
|
|
|
|
87
|
|
|
$parameters = $lookup->getOperationParameter(); |
88
|
|
|
|
89
|
|
|
if ($expectedSearchIndex === null) { |
90
|
|
|
$this->assertArrayNotHasKey('SearchIndex', $parameters); |
91
|
|
|
} else { |
92
|
|
|
$this->assertSame($expectedSearchIndex, $parameters['SearchIndex']); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function providerSetIdTypeAffectsSearchIndex() |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
[Lookup::TYPE_ASIN, null], |
103
|
|
|
[Lookup::TYPE_SKU, 'All'], |
104
|
|
|
[Lookup::TYPE_UPC, 'All'], |
105
|
|
|
[Lookup::TYPE_EAN, 'All'], |
106
|
|
|
[Lookup::TYPE_ISBN, 'All'] |
107
|
|
|
]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @expectedException InvalidArgumentException |
112
|
|
|
*/ |
113
|
|
|
public function testExceptionWhenPassingWrongIdType() |
114
|
|
|
{ |
115
|
|
|
$lookup = new Lookup(); |
116
|
|
|
$lookup->setIdType('Invalid IdType'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testGetSearchIndex() |
120
|
|
|
{ |
121
|
|
|
$lookup = new Lookup(); |
122
|
|
|
$this->assertEquals(null, $lookup->getSearchIndex()); |
123
|
|
|
$lookup->setSearchIndex('Appliances'); |
124
|
|
|
$this->assertEquals('Appliances', $lookup->getSearchIndex()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testConditionGetterAndSetter() |
128
|
|
|
{ |
129
|
|
|
$lookup = new Lookup(); |
130
|
|
|
$this->assertEquals(null, $lookup->getCondition()); |
131
|
|
|
$lookup->setCondition('All'); |
132
|
|
|
$this->assertEquals('All', $lookup->getCondition()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGetItemId() |
136
|
|
|
{ |
137
|
|
|
$lookup = new Lookup(); |
138
|
|
|
$this->assertEquals(null, $lookup->getItemId()); |
139
|
|
|
$lookup->setItemId('B0117IJ4LE'); |
140
|
|
|
$this->assertEquals('B0117IJ4LE', $lookup->getItemId()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testGetCondition() |
144
|
|
|
{ |
145
|
|
|
$lookup = new Lookup(); |
146
|
|
|
$this->assertEquals(null, $lookup->getCondition()); |
147
|
|
|
$lookup->setCondition('Used'); |
148
|
|
|
$this->assertEquals('Used', $lookup->getCondition()); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|