aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/FeedBuilderTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-07 19:17:33 +0200
committerArthurHoaro <arthur@hoa.ro>2017-05-07 19:17:33 +0200
commit01e942d44c7194607649817216aeb5d65c6acad6 (patch)
tree15777aa1005251f119e6dd680291147117766b5b /tests/FeedBuilderTest.php
parentbc22c9a0acb095970e9494cbe8954f0612e05dc0 (diff)
parent8868f3ca461011a8fb6dd9f90b60ed697ab52fc5 (diff)
downloadShaarli-01e942d44c7194607649817216aeb5d65c6acad6.tar.gz
Shaarli-01e942d44c7194607649817216aeb5d65c6acad6.tar.zst
Shaarli-01e942d44c7194607649817216aeb5d65c6acad6.zip
Merge tag 'v0.8.4' into stable
Release v0.8.4
Diffstat (limited to 'tests/FeedBuilderTest.php')
-rw-r--r--tests/FeedBuilderTest.php77
1 files changed, 62 insertions, 15 deletions
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php
index 069b1581..06a44506 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/FeedBuilderTest.php
@@ -76,7 +76,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
76 // Test headers (RSS) 76 // Test headers (RSS)
77 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); 77 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
78 $this->assertEmpty($data['pubsubhub_url']); 78 $this->assertEmpty($data['pubsubhub_url']);
79 $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $data['last_update']); 79 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']);
80 $this->assertEquals(true, $data['show_dates']); 80 $this->assertEquals(true, $data['show_dates']);
81 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); 81 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']);
82 $this->assertEquals('http://host.tld/', $data['index_url']); 82 $this->assertEquals('http://host.tld/', $data['index_url']);
@@ -84,23 +84,30 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
84 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 84 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
85 85
86 // Test first link (note link) 86 // Test first link (note link)
87 $link = array_shift($data['links']); 87 $link = reset($data['links']);
88 $this->assertEquals('20150310_114651', $link['linkdate']); 88 $this->assertEquals(41, $link['id']);
89 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
89 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 90 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 91 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $link['iso_date']); 92 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
93 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
94 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
95 $this->assertEquals($pub, $up);
92 $this->assertContains('Stallman has a beard', $link['description']); 96 $this->assertContains('Stallman has a beard', $link['description']);
93 $this->assertContains('Permalink', $link['description']); 97 $this->assertContains('Permalink', $link['description']);
94 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 98 $this->assertContains('http://host.tld/?WDWyig', $link['description']);
95 $this->assertEquals(1, count($link['taglist'])); 99 $this->assertEquals(1, count($link['taglist']));
96 $this->assertEquals('stuff', $link['taglist'][0]); 100 $this->assertEquals('sTuff', $link['taglist'][0]);
97 101
98 // Test URL with external link. 102 // Test URL with external link.
99 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']); 103 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links'][8]['url']);
100 104
101 // Test multitags. 105 // Test multitags.
102 $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); 106 $this->assertEquals(5, count($data['links'][6]['taglist']));
103 $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); 107 $this->assertEquals('css', $data['links'][6]['taglist'][0]);
108
109 // Test update date
110 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
104 } 111 }
105 112
106 /** 113 /**
@@ -112,8 +119,10 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
112 $feedBuilder->setLocale(self::$LOCALE); 119 $feedBuilder->setLocale(self::$LOCALE);
113 $data = $feedBuilder->buildData(); 120 $data = $feedBuilder->buildData();
114 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 121 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
115 $link = array_shift($data['links']); 122 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
116 $this->assertEquals('2015-03-10T11:46:51+01:00', $link['iso_date']); 123 $link = reset($data['links']);
124 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
125 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
117 } 126 }
118 127
119 /** 128 /**
@@ -130,7 +139,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
130 $data = $feedBuilder->buildData(); 139 $data = $feedBuilder->buildData();
131 $this->assertEquals(1, count($data['links'])); 140 $this->assertEquals(1, count($data['links']));
132 $link = array_shift($data['links']); 141 $link = array_shift($data['links']);
133 $this->assertEquals('20150310_114651', $link['linkdate']); 142 $this->assertEquals(41, $link['id']);
143 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
134 } 144 }
135 145
136 /** 146 /**
@@ -146,7 +156,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
146 $data = $feedBuilder->buildData(); 156 $data = $feedBuilder->buildData();
147 $this->assertEquals(1, count($data['links'])); 157 $this->assertEquals(1, count($data['links']));
148 $link = array_shift($data['links']); 158 $link = array_shift($data['links']);
149 $this->assertEquals('20150310_114651', $link['linkdate']); 159 $this->assertEquals(41, $link['id']);
160 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
150 } 161 }
151 162
152 /** 163 /**
@@ -162,15 +173,17 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
162 $this->assertTrue($data['usepermalinks']); 173 $this->assertTrue($data['usepermalinks']);
163 // First link is a permalink 174 // First link is a permalink
164 $link = array_shift($data['links']); 175 $link = array_shift($data['links']);
165 $this->assertEquals('20150310_114651', $link['linkdate']); 176 $this->assertEquals(41, $link['id']);
177 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
166 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 178 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
167 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 179 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
168 $this->assertContains('Direct link', $link['description']); 180 $this->assertContains('Direct link', $link['description']);
169 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 181 $this->assertContains('http://host.tld/?WDWyig', $link['description']);
170 // Second link is a direct link 182 // Second link is a direct link
171 $link = array_shift($data['links']); 183 $link = array_shift($data['links']);
172 $this->assertEquals('20150310_114633', $link['linkdate']); 184 $this->assertEquals(8, $link['id']);
173 $this->assertEquals('http://host.tld/?kLHmZg', $link['guid']); 185 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
186 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
174 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); 187 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
175 $this->assertContains('Direct link', $link['description']); 188 $this->assertContains('Direct link', $link['description']);
176 $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); 189 $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
@@ -209,4 +222,38 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
209 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 222 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
210 $this->assertEquals('http://pubsubhub.io', $data['pubsubhub_url']); 223 $this->assertEquals('http://pubsubhub.io', $data['pubsubhub_url']);
211 } 224 }
225
226 /**
227 * Test buildData when Shaarli is served from a subdirectory
228 */
229 public function testBuildDataServerSubdir()
230 {
231 $serverInfo = array(
232 'HTTPS' => 'Off',
233 'SERVER_NAME' => 'host.tld',
234 'SERVER_PORT' => '8080',
235 'SCRIPT_NAME' => '/~user/shaarli/index.php',
236 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed',
237 );
238 $feedBuilder = new FeedBuilder(
239 self::$linkDB,
240 FeedBuilder::$FEED_ATOM,
241 $serverInfo,
242 null,
243 false
244 );
245 $feedBuilder->setLocale(self::$LOCALE);
246 $data = $feedBuilder->buildData();
247
248 $this->assertEquals(
249 'http://host.tld:8080/~user/shaarli/index.php?do=feed',
250 $data['self_link']
251 );
252
253 // Test first link (note link)
254 $link = array_shift($data['links']);
255 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']);
256 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']);
257 $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']);
258 }
212} 259}