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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
<?php
declare(strict_types=1);
namespace Shaarli\NetscapeBookmarkParser\Tests\Unit\Encoder;
use Shaarli\NetscapeBookmarkParser\Encoder\NetscapeBookmarkDecoder;
use PHPUnit\Framework\TestCase;
/**
* Ensure Shaarli exports are properly parsed.
*
* @see https://github.com/shaarli/Shaarli
*/
class ParseShaarliBookmarksTest extends TestCase
{
public const FIXTURE_DIRECTORY = __DIR__ . '/../../Fixtures/Encoder/';
// phpcs:disable Generic.Files.LineLength
public const EXPECTED_1 = [
[
'name' => "Kouign'amann recipes",
'image' => null,
'url' => '?lY47tw',
'tags' => [
'breton',
'recipe',
'kouign',
'amann',
'traditional',
'caramel',
'butter',
],
'description' => ""Is there anything more fabulous than something created through the wonder and miracle of caramelization?"\n\n- http://www.davidlebovitz.com/2005/08/long-live-the-k/\n- http://www.bonappetit.com/recipe/kouign-amann\n\n"It is strictly forbidden to think about diet while you're making a Kouign Amann"",
'dateCreated' => 1459371397,
'public' => true,
],
[
'name' => 'The Most Important Object In Computer Graphics History Is This Teapot - Facts So Romantic - Nautilus',
'image' => null,
'url' => 'http://nautil.us/blog/the-most-important-object-in-computer-graphics-history-is-this-teapot',
'tags' => [
'teapot',
'computer',
'generation',
'graphics',
'3d',
],
'description' => null,
'dateCreated' => 1459371358,
'public' => true,
],
[
'name' => 'PHP - Testing Your Privates',
'image' => null,
'url' => 'https://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html',
'tags' => [
'php',
'class',
'test',
'unitary',
'private',
],
'description' => null,
'dateCreated' => 1459371224,
'public' => false,
],
[
'name' => 'Mine Turtle Instructions by StormL on DeviantArt',
'image' => null,
'url' => 'http://storml.deviantart.com/art/Mine-Turtle-Instructions-302477240?q=in%3Ascraps%20sort%3Atime%20gallery%3Astorml&qo=1',
'tags' => [
'mine',
'turtle',
'asdf',
'paper',
'craft',
],
'description' => 'Schematics: http://www.deviantart.com/users/outgoing?http://www.mediafire.com/?bx19xdd95ed4ap6',
'dateCreated' => 1459371140,
'public' => true,
],
[
'name' => ' Shaarli: the personal, minimalist, super-fast, no-database delicious clone',
'image' => null,
'url' => 'https://github.com/shaarli/Shaarli/wiki',
'tags' => [
'opensource',
'software',
],
'description' => "Welcome to Shaarli! This is your first public bookmark. To edit or delete me, you must first login.\n\nTo learn how to use Shaarli, consult the link "Help/documentation" at the bottom of this page.\n\nYou use the community supported version of the original Shaarli project, by Sebastien Sauvage.",
'dateCreated' => 1459370973,
'public' => true,
],
[
'name' => 'My secret stuff... - Pastebin.com',
'image' => null,
'url' => 'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=',
'tags' => [
'secretstuff',
],
'description' => "Shhhh! I'm a private link only YOU can see. You can delete me too.",
'dateCreated' => 1459370913,
'public' => false,
],
];
public const EXPECTED_2 = [
[
'name' => 'Markdown - code',
'image' => null,
'url' => '?Z-mb0g',
'tags' => [
'markdown',
'php',
'code',
],
'description' => "PHP stuff:\n\n <?php\n phpinfo();\n ?>\n\nPython stuff:\n\n import logging\n import os\n\n if __name__ == '__main__':\n logging.info("Current directory: %s", os.getcwd())",
'dateCreated' => 1463262544,
'public' => true,
],
[
'name' => 'Markdown - lists',
'image' => null,
'url' => '?9PvbnA',
'tags' => [
'markdown',
],
'description' => "Standard:\n* item1\n* item2\n* item3\n\nNested:\n- item1\n - item1.1\n - item1.2\n- item2",
'dateCreated' => 1463262338,
'public' => true,
],
[
'name' => 'Markdown - headers and quotes',
'image' => null,
'url' => '?GIvbSw',
'tags' => [
'markdown',
],
'description' => "A First Level Header\n====================\n\nA Second Level Header\n---------------------\n\nNow is the time for all good men to come to\nthe aid of their country. This is just a\nregular paragraph.\n\nThe quick brown fox jumped over the lazy\ndog's back.\n\n### Header 3\n\n> This is a blockquote.\n> \n> This is the second paragraph in the blockquote.\n>\n> ## This is an H2 in a blockquote",
'dateCreated' => 1463262269,
'public' => true,
],
];
// phpcs:enable
public const EXPECTED_3 = [
[
'name' => 'A Pen by Rodrigo Muniz.',
'image' => null,
'url' => 'https://gist.github.com/rodrigomuniz/8408734',
'tags' => [
'css',
],
'description' => 'simple on/off button',
'dateCreated' => 1470640652,
'public' => false,
],
[
'name' => 'URL Rewriting for Beginners - Web Development in Brighton - Added Bytes',
'image' => null,
'url' => 'https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/',
'tags' => [
'apache',
],
'description' => null,
'dateCreated' => 1469950052,
'public' => true,
],
];
/**
* @var NetscapeBookmarkDecoder|null
*/
private $decoder;
/**
* Parse bookmarks as exported by Shaarli - no plugin enabled.
*/
public function testParseNoPlugins(): void
{
$content = \file_get_contents(self::FIXTURE_DIRECTORY . 'input/shaarli.htm');
$result = $this->decoder->decode($content);
$this->assertSame(self::EXPECTED_1, $result);
}
/**
* Parse bookmarks as exported by Shaarli - Markdown plugin enabled.
*/
public function testParseMarkdown(): void
{
$content = \file_get_contents(self::FIXTURE_DIRECTORY . 'input/shaarli_markdown.htm');
$result = $this->decoder->decode($content);
$this->assertSame(self::EXPECTED_2, $result);
}
/**
* Parse bookmarks as exported by Shaarli legacy.
*/
public function testParseLegacy(): void
{
$content = \file_get_contents(self::FIXTURE_DIRECTORY . 'input/shaarli_legacy.htm');
$result = $this->decoder->decode($content);
$this->assertSame(self::EXPECTED_3, $result);
}
// --------------------------------------------------
// Setup / Tear Down
// --------------------------------------------------
protected function setUp(): void
{
$this->decoder = new NetscapeBookmarkDecoder();
}
protected function tearDown(): void
{
$this->decoder = null;
}
}
|