|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Product; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\ImageCollection; |
|
8
|
|
|
use LauLamanApps\IzettleApi\API\Product\Category; |
|
9
|
|
|
use LauLamanApps\IzettleApi\API\Product\CategoryCollection; |
|
10
|
|
|
use LauLamanApps\IzettleApi\API\Product\Product; |
|
11
|
|
|
use LauLamanApps\IzettleApi\API\Product\Variant; |
|
12
|
|
|
use LauLamanApps\IzettleApi\API\Product\VariantCollection; |
|
13
|
|
|
use Money\Money; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Ramsey\Uuid\Uuid; |
|
16
|
|
|
|
|
17
|
|
|
/** * @small */ |
|
18
|
|
|
final class ProductTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @test |
|
22
|
|
|
* @dataProvider getDiscountData |
|
23
|
|
|
*/ |
|
24
|
|
|
public function new( |
|
25
|
|
|
string $name, |
|
26
|
|
|
string $description, |
|
27
|
|
|
CategoryCollection $categories, |
|
28
|
|
|
ImageCollection $imageCollection, |
|
29
|
|
|
VariantCollection $variants, |
|
30
|
|
|
string $externalReference |
|
31
|
|
|
): void { |
|
32
|
|
|
$product = Product::new( |
|
33
|
|
|
$name, |
|
34
|
|
|
$description, |
|
35
|
|
|
$categories, |
|
36
|
|
|
$imageCollection, |
|
37
|
|
|
$variants, |
|
38
|
|
|
$externalReference |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$createData = json_decode($product->getCreateData(), true); |
|
42
|
|
|
self::assertTrue(Uuid::isValid($createData['uuid'])); |
|
43
|
|
|
self::assertSame($name, $createData['name']); |
|
44
|
|
|
self::assertSame($description, $createData['description']); |
|
45
|
|
|
self::assertSame($imageCollection->getCreateDataArray(), $createData['imageLookupKeys']); |
|
46
|
|
|
self::assertSame($externalReference, $createData['externalReference']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @test |
|
51
|
|
|
* @expectedException \LauLamanApps\IzettleApi\Client\Exceptions\CantCreateProductException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function cantCreateProductWithoutVariant(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$product = Product::new( |
|
56
|
|
|
'name3', |
|
57
|
|
|
'description3', |
|
58
|
|
|
new CategoryCollection(), |
|
59
|
|
|
new ImageCollection(), |
|
60
|
|
|
new VariantCollection(), |
|
61
|
|
|
'externalReference3' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$product->getCreateData(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getDiscountData(): array |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
|
|
[ |
|
71
|
|
|
'name1', |
|
72
|
|
|
'description1', |
|
73
|
|
|
new CategoryCollection(), |
|
74
|
|
|
new ImageCollection(), |
|
75
|
|
|
new VariantCollection([ |
|
76
|
|
|
Variant::new( |
|
77
|
|
|
null, |
|
78
|
|
|
null, |
|
79
|
|
|
null, |
|
80
|
|
|
null, |
|
81
|
|
|
1, |
|
82
|
|
|
null, |
|
83
|
|
|
Money::EUR(500), |
|
84
|
|
|
null, |
|
85
|
|
|
12 |
|
86
|
|
|
) |
|
87
|
|
|
]), |
|
88
|
|
|
'externalReference1' |
|
89
|
|
|
], |
|
90
|
|
|
[ |
|
91
|
|
|
'name2', |
|
92
|
|
|
'description2', |
|
93
|
|
|
new CategoryCollection([Category::new('')]), |
|
94
|
|
|
new ImageCollection(), |
|
95
|
|
|
new VariantCollection([ |
|
96
|
|
|
Variant::new( |
|
97
|
|
|
null, |
|
98
|
|
|
null, |
|
99
|
|
|
null, |
|
100
|
|
|
null, |
|
101
|
|
|
1, |
|
102
|
|
|
null, |
|
103
|
|
|
Money::EUR(500), |
|
104
|
|
|
Money::EUR(100), |
|
105
|
|
|
12 |
|
106
|
|
|
) |
|
107
|
|
|
]), |
|
108
|
|
|
'externalReference2' |
|
109
|
|
|
] |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|