-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathWishlistRepositoryTest.php
More file actions
201 lines (160 loc) · 8.18 KB
/
Copy pathWishlistRepositoryTest.php
File metadata and controls
201 lines (160 loc) · 8.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusWishlistPlugin\Integration\Repository;
use ApiTestCase\JsonApiTestCase;
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
use Sylius\Component\Core\Model\Channel;
use Sylius\Component\Core\Model\ShopUser;
final class WishlistRepositoryTest extends JsonApiTestCase
{
public function setUp(): void
{
parent::setUp();
$this->entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
$this->repository = $this->getContainer()->get('bitbag_sylius_wishlist_plugin.repository.wishlist');
}
public function testItFindsOneWishlistByShopUser(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user.yaml');
$shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
/** @var ?WishlistInterface $result */
$result = $this->repository->findOneByShopUser($shopUser);
$this->assertNotNull($result);
$this->assertCount(1, [$result]);
$this->assertSame('Olivier Wishlist', $result->getName());
$this->assertSame($shopUser, $result->getShopUser());
}
public function testItFindsOneWishlistByToken(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_token.yaml');
/** @var ?WishlistInterface $result */
$result = $this->repository->findByToken('token');
$this->assertNotNull($result);
$this->assertCount(1, [$result]);
$this->assertSame('Wishlist One', $result->getName());
}
public function testItFindsAllWishlistsByToken(): void
{
$this->loadFixturesFromFile('test_it_finds_all_wishlists_by_token.yaml');
/** @var array $result */
$result = $this->repository->findAllByToken('token');
$this->assertNotNull($result);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertSame('Wishlist One', $result[0]->getName());
$this->assertSame('Wishlist Two', $result[1]->getName());
}
public function testItFindsAllWishlistsByShopUser(): void
{
$this->loadFixturesFromFile('test_it_finds_all_wishlists_by_shop_user.yaml');
$shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
/** @var array $result */
$result = $this->repository->findAllByShopUser($shopUser->getId());
$this->assertNotNull($result);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertSame('Olivier Wishlist', $result[0]->getName());
$this->assertSame('Olivier Wishlist 2', $result[1]->getName());
$this->assertSame($shopUser, $result[0]->getShopUser());
$this->assertSame($shopUser, $result[1]->getShopUser());
}
public function testItFindsAllWishlistsByShopUserAndToken(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_token.yaml');
$shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
/** @var array $result */
$result = $this->repository->findAllByShopUserAndToken($shopUser->getId(), 'olivier_token');
$this->assertNotNull($result);
$this->assertIsArray($result);
$this->assertCount(4, $result);
$this->assertSame('Olivier Wishlist', $result[0]->getName());
$this->assertSame('Olivier Wishlist 2', $result[1]->getName());
$this->assertSame($shopUser, $result[0]->getShopUser());
$this->assertSame($shopUser, $result[1]->getShopUser());
$this->assertSame('Olivier token wishlist', $result[2]->getName());
$this->assertSame('Olivier token wishlist 2', $result[3]->getName());
$this->assertSame('olivier_token', $result[3]->getToken());
$this->assertSame('olivier_token', $result[3]->getToken());
}
public function testItFindsAllAnonymousWishlists(): void
{
$this->loadFixturesFromFile('test_it_finds_all_anonymous_wishlists.yaml');
/** @var array $result */
$result = $this->repository->findAllByAnonymous('token');
$this->assertNotNull($result);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertSame('Wishlist One', $result[0]->getName());
$this->assertSame('Wishlist Two', $result[1]->getName());
}
public function testItFindsOneWishlistsByShopUserAndChannel(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_channel.yaml');
$shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
$channel = $this->entityManager->getRepository(Channel::class)->findOneBy(['name' => 'name']);
/** @var ?WishlistInterface $result */
$result = $this->repository->findOneByShopUserAndChannel($shopUser, $channel);
$this->assertNotNull($result);
$this->assertInstanceOf(WishlistInterface::class, $result);
$this->assertCount(1, [$result]);
$this->assertSame('Olivier Wishlist', $result->getName());
$this->assertSame($shopUser, $result->getShopUser());
}
public function testItFindsAllAnonymousWishlistsWithChannel(): void
{
$this->loadFixturesFromFile('test_it_finds_all_anonymous_wishlists_with_channel.yaml');
$channel = $this->entityManager->getRepository(Channel::class)->findOneBy(['name' => 'name']);
/** @var array $result */
$result = $this->repository->findAllByAnonymousAndChannel('token', $channel);
$this->assertNotNull($result);
$this->assertIsArray($result);
$this->assertCount(2, $result);
$this->assertSame('Wishlist One', $result[0]->getName());
$this->assertSame('Wishlist Two', $result[1]->getName());
}
public function testItFindsOneWishlistByTokenAndName(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_token_and_name.yaml');
/** @var ?WishlistInterface $result */
$result = $this->repository->findOneByTokenAndName('token', 'Olivier Wishlist');
/** @var ?WishlistInterface $result */
$this->assertNotNull($result);
$this->assertInstanceOf(WishlistInterface::class, $result);
$this->assertCount(1, [$result]);
$this->assertSame('Olivier Wishlist', $result->getName());
$missingResult = $this->repository->findOneByTokenAndName('non_existing_token', 'Olivier Wishlist');
$this->assertNull($missingResult);
}
public function testItFindsOneWishlistByShopUserAndName(): void
{
$this->loadFixturesFromFile('test_it_finds_one_wishlist_by_shop_user_and_name.yaml');
$shopUser = $this->entityManager->getRepository(ShopUser::class)->findOneByEmail('oliver@queen.com');
/** @var ?WishlistInterface $result */
$result = $this->repository->findOneByShopUserAndName($shopUser, 'Olivier Wishlist');
/** @var ?WishlistInterface $result */
$this->assertNotNull($result);
$this->assertInstanceOf(WishlistInterface::class, $result);
$this->assertCount(1, [$result]);
$this->assertSame('Olivier Wishlist', $result->getName());
$missingResult = $this->repository->findOneByShopUserAndName($shopUser, 'Bruce Wishlist');
$this->assertNull($missingResult);
}
public function testItDeleteAllAnonymousUntilWishlists(): void
{
$this->loadFixturesFromFile('test_it_delete_all_anonymous_until_wishlists.yaml');
/** @var int $result */
$result = $this->repository->deleteAllAnonymousUntil(new \DateTime('2024-01-01 00:00:00'));
$this->assertIsInt($result);
$this->assertSame(1, $result);
$wishlists = $this->repository->findAll();
$this->assertCount(2, $wishlists);
$this->assertSame('Wishlist Two', $wishlists[0]->getName());
$this->assertSame('Olivier Wishlist', $wishlists[1]->getName());
}
}