|
3 | 3 | namespace Swader\Diffbot\Test\Entity; |
4 | 4 |
|
5 | 5 | use Swader\Diffbot\Entity\Article; |
6 | | -use Swader\Diffbot\Factory\Entity; |
7 | 6 | use Swader\Diffbot\Test\ResponseProvider; |
8 | 7 |
|
9 | 8 | class ArticleTest extends ResponseProvider |
10 | 9 | { |
11 | | - /** @var array */ |
12 | | - protected $responses = []; |
13 | | - |
14 | | - protected $files = [ |
| 10 | + protected static $staticFiles = [ |
15 | 11 | 'Articles/diffbot-sitepoint-basic.json', |
16 | 12 | // http%3A%2F%2Fwww.sitepoint.com%2Fdiffbot-crawling-visual-machine-learning |
17 | 13 | 'Articles/diffbot-sitepoint-extended.json', |
18 | 14 | 'Articles/apple-watch-verge-basic.json', |
19 | 15 | // http%3A%2F%2Fwww.theverge.com%2Fa%2Fapple-watch-review |
20 | | - 'Articles/apple-watch-verge-extended.json' |
| 16 | + 'Articles/apple-watch-verge-extended.json', |
| 17 | + 'Articles/15-11-07/diffbot-sitepoint-basic.json', |
21 | 18 | ]; |
22 | 19 |
|
23 | | - protected function ei($file) |
24 | | - { |
25 | | - $ef = new Entity(); |
26 | | - |
27 | | - return $ef->createAppropriateIterator($this->prepareResponses()[$file]); |
28 | | - } |
29 | | - |
30 | | - public function returnFiles() |
31 | | - { |
32 | | - $files = []; |
33 | | - foreach ($this->files as $file) { |
34 | | - $files[] = [$file]; |
35 | | - } |
36 | | - |
37 | | - return $files; |
38 | | - } |
39 | | - |
40 | 20 | /** |
41 | 21 | * @dataProvider returnFiles |
| 22 | + * @param $file |
42 | 23 | */ |
43 | 24 | public function testType($file) |
44 | 25 | { |
@@ -303,4 +284,89 @@ public function testDiscussion($file, $articles) |
303 | 284 | } |
304 | 285 | } |
305 | 286 | } |
| 287 | + |
| 288 | + public function siteNameProvider() |
| 289 | + { |
| 290 | + return [ |
| 291 | + ['Articles/15-11-07/diffbot-sitepoint-basic.json', 'SitePoint'], |
| 292 | + ]; |
| 293 | + } |
| 294 | + |
| 295 | + /** |
| 296 | + * @dataProvider siteNameProvider |
| 297 | + * @param $file |
| 298 | + * @param $value1 |
| 299 | + */ |
| 300 | + public function testSiteName($file, $value1) |
| 301 | + { |
| 302 | + $value1 = (is_array($value1)) ? $value1 : [$value1]; |
| 303 | + /** @var Article $entity */ |
| 304 | + foreach ($this->ei($file) as $i => $entity) { |
| 305 | + $this->assertEquals($value1[$i], $entity->getSiteName()); |
| 306 | + } |
| 307 | + } |
| 308 | + |
| 309 | + public function publisherCountryProvider() |
| 310 | + { |
| 311 | + return [ |
| 312 | + ['Articles/15-11-07/diffbot-sitepoint-basic.json', 'Australia'], |
| 313 | + ]; |
| 314 | + } |
| 315 | + |
| 316 | + /** |
| 317 | + * @dataProvider publisherCountryProvider |
| 318 | + * @param $file |
| 319 | + * @param $value1 |
| 320 | + */ |
| 321 | + public function testPublisherCountry($file, $value1) |
| 322 | + { |
| 323 | + $value1 = (is_array($value1)) ? $value1 : [$value1]; |
| 324 | + /** @var Article $entity */ |
| 325 | + foreach ($this->ei($file) as $i => $entity) { |
| 326 | + $this->assertEquals($value1[$i], $entity->getPublisherCountry()); |
| 327 | + } |
| 328 | + } |
| 329 | + |
| 330 | + public function publisherRegionProvider() |
| 331 | + { |
| 332 | + return [ |
| 333 | + ['Articles/15-11-07/diffbot-sitepoint-basic.json', 'Australia and New Zealand'], |
| 334 | + ]; |
| 335 | + } |
| 336 | + |
| 337 | + /** |
| 338 | + * @dataProvider publisherRegionProvider |
| 339 | + * @param $file |
| 340 | + * @param $value1 |
| 341 | + */ |
| 342 | + public function testPublisherRegion($file, $value1) |
| 343 | + { |
| 344 | + $value1 = (is_array($value1)) ? $value1 : [$value1]; |
| 345 | + /** @var Article $entity */ |
| 346 | + foreach ($this->ei($file) as $i => $entity) { |
| 347 | + $this->assertEquals($value1[$i], $entity->getPublisherRegion()); |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + public function estimatedDateProvider() |
| 352 | + { |
| 353 | + return [ |
| 354 | + ['Articles/15-11-07/diffbot-sitepoint-basic.json', '2014年7月27日 00:00:00 GMT'], |
| 355 | + ]; |
| 356 | + } |
| 357 | + |
| 358 | + /** |
| 359 | + * @dataProvider estimatedDateProvider |
| 360 | + * @param $file |
| 361 | + * @param $value1 |
| 362 | + */ |
| 363 | + public function testEstimatedDate($file, $value1) |
| 364 | + { |
| 365 | + $value1 = (is_array($value1)) ? $value1 : [$value1]; |
| 366 | + /** @var Article $entity */ |
| 367 | + foreach ($this->ei($file) as $i => $entity) { |
| 368 | + $this->assertEquals($value1[$i], $entity->getEstimatedDate()); |
| 369 | + } |
| 370 | + } |
| 371 | + |
306 | 372 | } |
0 commit comments