File: ParseGoogleBookmarksTest.php

package info (click to toggle)
php-netscape-bookmark-parser 4.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: php: 3,592; makefile: 49; sh: 3
file content (122 lines) | stat: -rw-r--r-- 3,755 bytes parent folder | download
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
<?php

declare(strict_types=1);

namespace Shaarli\NetscapeBookmarkParser\Tests\Unit\Encoder;

use PHPUnit\Framework\TestCase;
use Shaarli\NetscapeBookmarkParser\Encoder\NetscapeBookmarkDecoder;

/**
 * Ensure Google Bookmarks exports are properly parsed.
 *
 * The reference data has been dumped with Google Bookmarks on 2018-10-01
 */
class ParseGoogleBookmarksTest extends TestCase
{
    public const FIXTURE_DIRECTORY = __DIR__ . '/../../Fixtures/Encoder/';

    // phpcs:disable Generic.Files.LineLength
    public const EXPECTED = [
        [
            'name'        => 'WordHippo | Comprehensive Thesaurus for Synonyms and Antonyms',
            'image'       => null,
            'url'         => 'https://www.wordhippo.com/',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1515515697,
            'public'      => null,
        ],
        [
            'name'        => 'powershell - Move files into alphabetically named folders - Stack Overflow',
            'image'       => null,
            'url'         => 'https://stackoverflow.com/questions/20180072/move-files-into-alphabetically-named-folders',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1519067075,
            'public'      => null,
        ],
        [
            'name'        => 'Free Lien Search',
            'image'       => null,
            'url'         => 'http://www.searchq.com/',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1523996185,
            'public'      => null,
        ],
        [
            'name'        => 'OpenNIC Project',
            'image'       => null,
            'url'         => 'https://www.opennic.org/',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1529505663,
            'public'      => null,
        ],
        [
            'name'        => 'Kubo and the Two Strings (2016) - IMDb',
            'image'       => null,
            'url'         => 'https://www.imdb.com/title/tt4302938/',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1532442262,
            'public'      => null,
        ],
        [
            'name'        => 'Home | NextAce',
            'image'       => null,
            'url'         => 'https://nextace.com/',
            'tags'        => [
                'unlabeled',
            ],
            'description' => null,
            'dateCreated' => 1523996194,
            'public'      => null,
        ],
    ];
    // phpcs:enable

    /**
     * @var NetscapeBookmarkDecoder|null
     */
    private $decoder;

    /**
     * Parse nested Google Bookmarks (directories and subdirectories).
     */
    public function testParseNested(): void
    {
        if (PHP_INT_SIZE == 4) {
            $this->markTestSkipped('Test input data timestamps too large for 32-bit systems.');
        }
        $content = \file_get_contents(self::FIXTURE_DIRECTORY . 'input/google_bookmarks_nested.htm');
        $result = $this->decoder->decode($content);

        $this->assertSame(self::EXPECTED, $result);
    }

    // --------------------------------------------------
    // Setup / Tear Down
    // --------------------------------------------------

    protected function setUp(): void
    {
        $this->decoder = new NetscapeBookmarkDecoder();
    }

    protected function tearDown(): void
    {
        $this->decoder = null;
    }
}