File: FlickRFinderTest.php

package info (click to toggle)
php-arthurhoaro-web-thumbnailer 2.1.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 896 kB
  • sloc: php: 3,365; makefile: 19; sh: 9
file content (105 lines) | stat: -rw-r--r-- 3,200 bytes parent folder | download | duplicates (3)
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
<?php

declare(strict_types=1);

namespace WebThumbnailer\Finder;

use WebThumbnailer\TestCase;

class FlickRFinderTest extends TestCase
{
    /**
     * @var mixed[] Finder rules.
     */
    protected static $rules;

    /**
     * @var mixed[] Size parameter.
     */
    protected static $params;

    /**
     * Before every tests, reset rules and params.
     */
    public function setUp(): void
    {
        $this->markTestSkipped('Test cases depend on non-DFSG resource that was dropped.');
        self::$rules  = [
            'image_regex' => '<meta property=\"og:image\" content=\"(.*?)\"',
            'thumbnail_url' => '${1}',
        ];

        self::$params = [
            'size' => [
                'default' => 'large',
                'large' => [
                    'param' => 'c',
                    'maxwidth' => 800,
                    'maxheight' => 800,
                ]
            ]
        ];
    }

    /**
     * Test find() with an existing FlickR page loaded locally.
     */
    public function testFlickRFinderExistingImage(): void
    {
        $url = __DIR__ . '/../resources/flickr/flickr-image.html';
        $expected = 'https://c1.staticflickr.com/9/8657/29903845474_7d23197890_c.jpg';

        $finder = new FlickRFinder('flickr.com', $url, self::$rules, self::$params);
        $this->assertEquals($expected, $finder->find());
    }

    /**
     * Test find() with an existing FlickR page loaded locally.
     * We use the empty size to make sure it works:
     *   one of thumb size doesn't have a suffix.
     */
    public function testFlickRFinderEmptySuffix(): void
    {
        $url = __DIR__ . '/../resources/flickr/flickr-image.html';
        $expected = 'https://c1.staticflickr.com/9/8657/29903845474_7d23197890.jpg';
        self::$params['size']['large']['param'] = '';

        $finder = new FlickRFinder('flickr.com', $url, self::$rules, self::$params);
        $this->assertEquals($expected, $finder->find());
    }

    /**
     * Test find() with an existing FlickR page loaded locally.
     */
    public function testFlickRFinderProfile(): void
    {
        $url = __DIR__ . '/../resources/flickr/flickr-profile.html';
        $expected = 'https://c7.staticflickr.com/9/8562/29912456894_b3e6ddfe28_c.jpg';

        $finder = new FlickRFinder('flickr.com', $url, self::$rules, self::$params);
        $this->assertEquals($expected, $finder->find());
    }

    /**
     * Test find() with an existing FlickR page loaded locally.
     */
    public function testFlickRFinderHomepage(): void
    {
        $url = __DIR__ . '/../resources/flickr/flickr-homepage.html';
        $expected = 'https://farm4.staticflickr.com/3914/15118079089_489aa62638_c.jpg';

        $finder = new FlickRFinder('flickr.com', $url, self::$rules, self::$params);
        $this->assertEquals($expected, $finder->find());
    }

    /**
     * Load FlickR homepage, no image found.
     */
    public function testFlickRFinderNoImage(): void
    {
        $url = __DIR__ . '/../resources/flickr/flickr-doc.html';

        $finder = new FlickRFinder('flickr.com', $url, self::$rules, self::$params);
        $this->assertFalse($finder->find());
    }
}