|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Yproximite\Api\Service; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
|
|
7
|
|
|
use Yproximite\Api\Client\Client; |
|
8
|
|
|
use Yproximite\Api\Factory\ModelFactory; |
|
9
|
|
|
use Yproximite\Api\Model\Article\Article; |
|
10
|
|
|
use Yproximite\Api\Model\Article\Category; |
|
11
|
|
|
use Yproximite\Api\Service\ArticleService; |
|
12
|
|
|
use Yproximite\Api\Message\Article\ArticleListMessage; |
|
13
|
|
|
use Yproximite\Api\Message\Article\ArticlePostMessage; |
|
14
|
|
|
use Yproximite\Api\Message\Article\ArticlePatchMessage; |
|
15
|
|
|
use Yproximite\Api\Message\Article\CategoryListMessage; |
|
16
|
|
|
use Yproximite\Api\Message\Article\CategoryPostMessage; |
|
17
|
|
|
use Yproximite\Api\Message\Article\CategoryPatchMessage; |
|
18
|
|
|
use Yproximite\Api\Message\Article\ArticleUnpublishMessage; |
|
19
|
|
|
use Yproximite\Api\Message\Article\CategoryOverrideMessage; |
|
20
|
|
|
use Yproximite\Api\Message\Article\CategoryArticleListMessage; |
|
21
|
|
|
use Yproximite\Api\Message\Article\CategoryArticlePublishMessage; |
|
22
|
|
|
use Yproximite\Api\Message\Article\CategoryArticleUnpublishMessage; |
|
23
|
|
|
|
|
24
|
|
|
class ArticleServiceSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
function it_is_initializable() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->shouldHaveType(ArticleService::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function let(Client $client, ModelFactory $factory) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->beConstructedWith($client, $factory); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_should_get_articles( |
|
37
|
|
|
Client $client, |
|
38
|
|
|
ModelFactory $factory, |
|
39
|
|
|
ArticleListMessage $message |
|
40
|
|
|
) { |
|
41
|
|
|
$message->getSiteId()->willReturn(1); |
|
42
|
|
|
$message->build()->willReturn([]); |
|
43
|
|
|
|
|
44
|
|
|
$method = 'GET'; |
|
45
|
|
|
$path = 'sites/1/articles'; |
|
46
|
|
|
|
|
47
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
|
48
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
|
49
|
|
|
|
|
50
|
|
|
$factory->createMany(Article::class, [])->willReturn([]); |
|
51
|
|
|
|
|
52
|
|
|
$this->getArticles($message); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function it_should_post_article( |
|
56
|
|
|
Client $client, |
|
57
|
|
|
ModelFactory $factory, |
|
58
|
|
|
ArticlePostMessage $message, |
|
59
|
|
|
Article $article |
|
60
|
|
|
) { |
|
61
|
|
|
$message->getSiteId()->willReturn(1); |
|
62
|
|
|
$message->build()->willReturn([]); |
|
63
|
|
|
|
|
64
|
|
|
$method = 'POST'; |
|
65
|
|
|
$path = 'sites/1/articles'; |
|
66
|
|
|
$data = ['api_article' => []]; |
|
67
|
|
|
|
|
68
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
69
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
70
|
|
|
|
|
71
|
|
|
$factory->create(Article::class, [])->willReturn($article); |
|
72
|
|
|
|
|
73
|
|
|
$this->postArticle($message); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
function it_should_patch_article( |
|
77
|
|
|
Client $client, |
|
78
|
|
|
ModelFactory $factory, |
|
79
|
|
|
ArticlePatchMessage $message, |
|
80
|
|
|
Article $article |
|
81
|
|
|
) { |
|
82
|
|
|
$message->getId()->willReturn(2); |
|
83
|
|
|
$message->getSiteId()->willReturn(1); |
|
84
|
|
|
$message->build()->willReturn([]); |
|
85
|
|
|
|
|
86
|
|
|
$method = 'PATCH'; |
|
87
|
|
|
$path = 'sites/1/articles/2'; |
|
88
|
|
|
$data = ['api_article' => []]; |
|
89
|
|
|
|
|
90
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
91
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
92
|
|
|
|
|
93
|
|
|
$factory->create(Article::class, [])->willReturn($article); |
|
94
|
|
|
|
|
95
|
|
|
$this->patchArticle($message); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function it_should_unpublish_articles( |
|
99
|
|
|
Client $client, |
|
100
|
|
|
ModelFactory $factory, |
|
101
|
|
|
ArticleUnpublishMessage $message |
|
102
|
|
|
) { |
|
103
|
|
|
$message->getSiteId()->willReturn(1); |
|
104
|
|
|
$message->build()->willReturn([]); |
|
105
|
|
|
|
|
106
|
|
|
$method = 'POST'; |
|
107
|
|
|
$path = 'sites/1/articles/unpublish'; |
|
108
|
|
|
$data = ['api_unpublish_articles_global' => []]; |
|
109
|
|
|
|
|
110
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
111
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
112
|
|
|
|
|
113
|
|
|
$factory->createMany(Article::class, [])->willReturn([]); |
|
114
|
|
|
|
|
115
|
|
|
$this->unpublishArticles($message); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
function it_should_get_categories( |
|
119
|
|
|
Client $client, |
|
120
|
|
|
ModelFactory $factory, |
|
121
|
|
|
CategoryListMessage $message |
|
122
|
|
|
) { |
|
123
|
|
|
$message->getSiteId()->willReturn(1); |
|
124
|
|
|
$message->build()->willReturn([]); |
|
125
|
|
|
|
|
126
|
|
|
$method = 'GET'; |
|
127
|
|
|
$path = 'sites/1/categories'; |
|
128
|
|
|
|
|
129
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
|
130
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
|
131
|
|
|
|
|
132
|
|
|
$factory->createMany(Category::class, [])->willReturn([]); |
|
133
|
|
|
|
|
134
|
|
|
$this->getCategories($message); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
function it_should_post_category( |
|
138
|
|
|
Client $client, |
|
139
|
|
|
ModelFactory $factory, |
|
140
|
|
|
CategoryPostMessage $message, |
|
141
|
|
|
Category $category |
|
142
|
|
|
) { |
|
143
|
|
|
$message->getSiteId()->willReturn(1); |
|
144
|
|
|
$message->build()->willReturn([]); |
|
145
|
|
|
|
|
146
|
|
|
$method = 'POST'; |
|
147
|
|
|
$path = 'sites/1/categories'; |
|
148
|
|
|
$data = ['api_category' => []]; |
|
149
|
|
|
|
|
150
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
151
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
152
|
|
|
|
|
153
|
|
|
$factory->create(Category::class, [])->willReturn($category); |
|
154
|
|
|
|
|
155
|
|
|
$this->postCategory($message); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
function it_should_patch_category( |
|
159
|
|
|
Client $client, |
|
160
|
|
|
ModelFactory $factory, |
|
161
|
|
|
CategoryPatchMessage $message, |
|
162
|
|
|
Category $category |
|
163
|
|
|
) { |
|
164
|
|
|
$message->getId()->willReturn(2); |
|
165
|
|
|
$message->getSiteId()->willReturn(1); |
|
166
|
|
|
$message->build()->willReturn([]); |
|
167
|
|
|
|
|
168
|
|
|
$method = 'PATCH'; |
|
169
|
|
|
$path = 'sites/1/categories/2'; |
|
170
|
|
|
$data = ['api_category' => []]; |
|
171
|
|
|
|
|
172
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
173
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
174
|
|
|
|
|
175
|
|
|
$factory->create(Category::class, [])->willReturn($category); |
|
176
|
|
|
|
|
177
|
|
|
$this->patchCategory($message); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
function it_should_override_category( |
|
181
|
|
|
Client $client, |
|
182
|
|
|
ModelFactory $factory, |
|
183
|
|
|
CategoryOverrideMessage $message, |
|
184
|
|
|
Category $category |
|
185
|
|
|
) { |
|
186
|
|
|
$message->getId()->willReturn(5); |
|
187
|
|
|
$message->getSiteId()->willReturn(1); |
|
188
|
|
|
$message->build()->willReturn([]); |
|
189
|
|
|
|
|
190
|
|
|
$method = 'GET'; |
|
191
|
|
|
$path = 'sites/1/categories/5/override'; |
|
192
|
|
|
|
|
193
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
|
194
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
|
195
|
|
|
|
|
196
|
|
|
$factory->create(Category::class, [])->willReturn($category); |
|
197
|
|
|
|
|
198
|
|
|
$this->overrideCategory($message); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
function it_should_get_category_articles( |
|
202
|
|
|
Client $client, |
|
203
|
|
|
ModelFactory $factory, |
|
204
|
|
|
CategoryArticleListMessage $message |
|
205
|
|
|
) { |
|
206
|
|
|
$message->getSiteId()->willReturn(1); |
|
207
|
|
|
$message->getCategoryId()->willReturn(2); |
|
208
|
|
|
$message->build()->willReturn([]); |
|
209
|
|
|
|
|
210
|
|
|
$method = 'GET'; |
|
211
|
|
|
$path = 'sites/1/categories/2/articles'; |
|
212
|
|
|
|
|
213
|
|
|
$client->sendRequest($method, $path)->willReturn([]); |
|
214
|
|
|
$client->sendRequest($method, $path)->shouldBeCalled(); |
|
215
|
|
|
|
|
216
|
|
|
$factory->createMany(Article::class, [])->willReturn([]); |
|
217
|
|
|
|
|
218
|
|
|
$this->getCategoryArticles($message); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
function it_should_publish_category_articles( |
|
222
|
|
|
Client $client, |
|
223
|
|
|
ModelFactory $factory, |
|
224
|
|
|
CategoryArticlePublishMessage $message, |
|
225
|
|
|
Category $category |
|
226
|
|
|
) { |
|
227
|
|
|
$message->getSiteId()->willReturn(1); |
|
228
|
|
|
$message->getCategoryId()->willReturn(2); |
|
229
|
|
|
$message->build()->willReturn([]); |
|
230
|
|
|
|
|
231
|
|
|
$method = 'POST'; |
|
232
|
|
|
$path = 'sites/1/categories/2/publish_articles'; |
|
233
|
|
|
$data = ['api_publish_articles' => []]; |
|
234
|
|
|
|
|
235
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
236
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
237
|
|
|
|
|
238
|
|
|
$factory->create(Category::class, [])->willReturn($category); |
|
239
|
|
|
|
|
240
|
|
|
$this->publishCategoryArticles($message); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
function it_should_unpublish_category_articles( |
|
244
|
|
|
Client $client, |
|
245
|
|
|
ModelFactory $factory, |
|
246
|
|
|
CategoryArticleUnpublishMessage $message, |
|
247
|
|
|
Category $category |
|
248
|
|
|
) { |
|
249
|
|
|
$message->getSiteId()->willReturn(1); |
|
250
|
|
|
$message->getCategoryId()->willReturn(2); |
|
251
|
|
|
$message->build()->willReturn([]); |
|
252
|
|
|
|
|
253
|
|
|
$method = 'POST'; |
|
254
|
|
|
$path = 'sites/1/categories/2/unpublish_articles'; |
|
255
|
|
|
$data = ['api_unpublish_articles' => []]; |
|
256
|
|
|
|
|
257
|
|
|
$client->sendRequest($method, $path, $data)->willReturn([]); |
|
258
|
|
|
$client->sendRequest($method, $path, $data)->shouldBeCalled(); |
|
259
|
|
|
|
|
260
|
|
|
$factory->create(Category::class, [])->willReturn($category); |
|
261
|
|
|
|
|
262
|
|
|
$this->unpublishCategoryArticles($message); |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
|