diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/HttpUtils/GetHttpUrlTest.php | 27 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 7 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 9 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtilsTest.php | 134 | ||||
-rw-r--r-- | tests/TimeZoneTest.php | 2 | ||||
-rw-r--r-- | tests/Url/UrlTest.php | 16 |
6 files changed, 194 insertions, 1 deletions
diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/HttpUtils/GetHttpUrlTest.php index fd293505..ea53de5f 100644 --- a/tests/HttpUtils/GetHttpUrlTest.php +++ b/tests/HttpUtils/GetHttpUrlTest.php | |||
@@ -35,4 +35,31 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase | |||
35 | $this->assertFalse($headers); | 35 | $this->assertFalse($headers); |
36 | $this->assertFalse($content); | 36 | $this->assertFalse($content); |
37 | } | 37 | } |
38 | |||
39 | /** | ||
40 | * Test getAbsoluteUrl with relative target URL. | ||
41 | */ | ||
42 | public function testGetAbsoluteUrlWithRelative() | ||
43 | { | ||
44 | $origin = 'http://non.existent/blabla/?test'; | ||
45 | $target = '/stuff.php'; | ||
46 | |||
47 | $expected = 'http://non.existent/stuff.php'; | ||
48 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | ||
49 | |||
50 | $target = 'stuff.php'; | ||
51 | $expected = 'http://non.existent/blabla/stuff.php'; | ||
52 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Test getAbsoluteUrl with absolute target URL. | ||
57 | */ | ||
58 | public function testGetAbsoluteUrlWithAbsolute() | ||
59 | { | ||
60 | $origin = 'http://non.existent/blabla/?test'; | ||
61 | $target = 'http://other.url/stuff.php'; | ||
62 | |||
63 | $this->assertEquals($target, getAbsoluteUrl($origin, $target)); | ||
64 | } | ||
38 | } | 65 | } |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 8ffb1512..30ea4e01 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -340,6 +340,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
340 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); | 340 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); |
341 | foreach($db as $link) { | 341 | foreach($db as $link) { |
342 | $this->assertStringStartsWith($redirector, $link['real_url']); | 342 | $this->assertStringStartsWith($redirector, $link['real_url']); |
343 | $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); | ||
344 | } | ||
345 | |||
346 | $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); | ||
347 | foreach($db as $link) { | ||
348 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
349 | $this->assertFalse(strpos($link['real_url'], urlencode('://'))); | ||
343 | } | 350 | } |
344 | } | 351 | } |
345 | 352 | ||
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index 609a80cb..d1b022fd 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -84,4 +84,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
84 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; | 84 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; |
85 | $this->assertFalse(html_extract_charset($html)); | 85 | $this->assertFalse(html_extract_charset($html)); |
86 | } | 86 | } |
87 | |||
88 | /** | ||
89 | * Test count_private. | ||
90 | */ | ||
91 | public function testCountPrivateLinks() | ||
92 | { | ||
93 | $refDB = new ReferenceLinkDB(); | ||
94 | $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks())); | ||
95 | } | ||
87 | } | 96 | } |
diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtilsTest.php new file mode 100644 index 00000000..41e6d84c --- /dev/null +++ b/tests/NetscapeBookmarkUtilsTest.php | |||
@@ -0,0 +1,134 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | ||
4 | |||
5 | /** | ||
6 | * Netscape bookmark import and export | ||
7 | */ | ||
8 | class NetscapeBookmarkUtilsTest extends PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | /** | ||
11 | * @var string datastore to test write operations | ||
12 | */ | ||
13 | protected static $testDatastore = 'sandbox/datastore.php'; | ||
14 | |||
15 | /** | ||
16 | * @var ReferenceLinkDB instance. | ||
17 | */ | ||
18 | protected static $refDb = null; | ||
19 | |||
20 | /** | ||
21 | * @var LinkDB private LinkDB instance. | ||
22 | */ | ||
23 | protected static $linkDb = null; | ||
24 | |||
25 | /** | ||
26 | * Instantiate reference data | ||
27 | */ | ||
28 | public static function setUpBeforeClass() | ||
29 | { | ||
30 | self::$refDb = new ReferenceLinkDB(); | ||
31 | self::$refDb->write(self::$testDatastore); | ||
32 | self::$linkDb = new LinkDB(self::$testDatastore, true, false); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Attempt to export an invalid link selection | ||
37 | * @expectedException Exception | ||
38 | * @expectedExceptionMessageRegExp /Invalid export selection/ | ||
39 | */ | ||
40 | public function testFilterAndFormatInvalid() | ||
41 | { | ||
42 | NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, ''); | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Prepare all links for export | ||
47 | */ | ||
48 | public function testFilterAndFormatAll() | ||
49 | { | ||
50 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); | ||
51 | $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); | ||
52 | foreach ($links as $link) { | ||
53 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
54 | $this->assertEquals( | ||
55 | $date->getTimestamp(), | ||
56 | $link['timestamp'] | ||
57 | ); | ||
58 | $this->assertEquals( | ||
59 | str_replace(' ', ',', $link['tags']), | ||
60 | $link['taglist'] | ||
61 | ); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * Prepare private links for export | ||
67 | */ | ||
68 | public function testFilterAndFormatPrivate() | ||
69 | { | ||
70 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); | ||
71 | $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); | ||
72 | foreach ($links as $link) { | ||
73 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
74 | $this->assertEquals( | ||
75 | $date->getTimestamp(), | ||
76 | $link['timestamp'] | ||
77 | ); | ||
78 | $this->assertEquals( | ||
79 | str_replace(' ', ',', $link['tags']), | ||
80 | $link['taglist'] | ||
81 | ); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Prepare public links for export | ||
87 | */ | ||
88 | public function testFilterAndFormatPublic() | ||
89 | { | ||
90 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); | ||
91 | $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); | ||
92 | foreach ($links as $link) { | ||
93 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
94 | $this->assertEquals( | ||
95 | $date->getTimestamp(), | ||
96 | $link['timestamp'] | ||
97 | ); | ||
98 | $this->assertEquals( | ||
99 | str_replace(' ', ',', $link['tags']), | ||
100 | $link['taglist'] | ||
101 | ); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Do not prepend notes with the Shaarli index's URL | ||
107 | */ | ||
108 | public function testFilterAndFormatDoNotPrependNoteUrl() | ||
109 | { | ||
110 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); | ||
111 | $this->assertEquals( | ||
112 | '?WDWyig', | ||
113 | $links[0]['url'] | ||
114 | ); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Prepend notes with the Shaarli index's URL | ||
119 | */ | ||
120 | public function testFilterAndFormatPrependNoteUrl() | ||
121 | { | ||
122 | $indexUrl = 'http://localhost:7469/shaarli/'; | ||
123 | $links = NetscapeBookmarkUtils::filterAndFormat( | ||
124 | self::$linkDb, | ||
125 | 'public', | ||
126 | true, | ||
127 | $indexUrl | ||
128 | ); | ||
129 | $this->assertEquals( | ||
130 | $indexUrl . '?WDWyig', | ||
131 | $links[0]['url'] | ||
132 | ); | ||
133 | } | ||
134 | } | ||
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index b219030a..2976d116 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php | |||
@@ -67,7 +67,6 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase | |||
67 | { | 67 | { |
68 | $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); | 68 | $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); |
69 | $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); | 69 | $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); |
70 | $this->assertTrue(isTimeZoneValid('UTC', 'UTC')); | ||
71 | } | 70 | } |
72 | 71 | ||
73 | /** | 72 | /** |
@@ -78,5 +77,6 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase | |||
78 | $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); | 77 | $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); |
79 | $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); | 78 | $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); |
80 | $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); | 79 | $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); |
80 | $this->assertFalse(isTimeZoneValid('UTC', 'UTC')); | ||
81 | } | 81 | } |
82 | } | 82 | } |
diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php index a64a73ea..4bf53b2d 100644 --- a/tests/Url/UrlTest.php +++ b/tests/Url/UrlTest.php | |||
@@ -85,6 +85,7 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
85 | $this->assertUrlIsCleaned('?utm_term=1n4l'); | 85 | $this->assertUrlIsCleaned('?utm_term=1n4l'); |
86 | 86 | ||
87 | $this->assertUrlIsCleaned('?xtor=some-url'); | 87 | $this->assertUrlIsCleaned('?xtor=some-url'); |
88 | $this->assertUrlIsCleaned('?PHPSESSID=012345678910111213'); | ||
88 | } | 89 | } |
89 | 90 | ||
90 | /** | 91 | /** |
@@ -181,4 +182,19 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
181 | $url = new Url('ftp://save.tld/mysave'); | 182 | $url = new Url('ftp://save.tld/mysave'); |
182 | $this->assertFalse($url->isHttp()); | 183 | $this->assertFalse($url->isHttp()); |
183 | } | 184 | } |
185 | |||
186 | /** | ||
187 | * Test IndToAscii. | ||
188 | */ | ||
189 | function testIndToAscii() | ||
190 | { | ||
191 | $ind = 'http://www.académie-française.fr/'; | ||
192 | $expected = 'http://www.xn--acadmie-franaise-npb1a.fr/'; | ||
193 | $url = new Url($ind); | ||
194 | $this->assertEquals($expected, $url->idnToAscii()); | ||
195 | |||
196 | $notInd = 'http://www.academie-francaise.fr/'; | ||
197 | $url = new Url($notInd); | ||
198 | $this->assertEquals($notInd, $url->idnToAscii()); | ||
199 | } | ||
184 | } | 200 | } |