X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FFeedBuilderTest.php;h=ea1dde25cd09674775b4f5f2effcdb8a0d8f8e33;hb=c3dfd8995921083ff7250c25d0b6ab1184b91aff;hp=c9ff397d153e928c87ef1276f22307af62b63607;hpb=f63632a6fb84594b8aeacb387a5cd17b4a841d2c;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php index c9ff397d..ea1dde25 100644 --- a/tests/FeedBuilderTest.php +++ b/tests/FeedBuilderTest.php @@ -84,8 +84,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); // Test first link (note link) - $link = array_shift($data['links']); - $this->assertEquals('20150310_114651', $link['linkdate']); + $link = reset($data['links']); + $this->assertEquals(41, $link['id']); + $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']); $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); $this->assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); @@ -99,14 +100,14 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('sTuff', $link['taglist'][0]); // Test URL with external link. - $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']); + $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links'][8]['url']); // Test multitags. - $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); - $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); + $this->assertEquals(5, count($data['links'][6]['taglist'])); + $this->assertEquals('css', $data['links'][6]['taglist'][0]); // Test update date - $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); + $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); } /** @@ -119,9 +120,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $data = $feedBuilder->buildData(); $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); - $link = array_shift($data['links']); + $link = reset($data['links']); $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); - $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); + $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); } /** @@ -138,7 +139,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $data = $feedBuilder->buildData(); $this->assertEquals(1, count($data['links'])); $link = array_shift($data['links']); - $this->assertEquals('20150310_114651', $link['linkdate']); + $this->assertEquals(41, $link['id']); + $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']); } /** @@ -154,7 +156,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $data = $feedBuilder->buildData(); $this->assertEquals(1, count($data['links'])); $link = array_shift($data['links']); - $this->assertEquals('20150310_114651', $link['linkdate']); + $this->assertEquals(41, $link['id']); + $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']); } /** @@ -170,15 +173,17 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $this->assertTrue($data['usepermalinks']); // First link is a permalink $link = array_shift($data['links']); - $this->assertEquals('20150310_114651', $link['linkdate']); + $this->assertEquals(41, $link['id']); + $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']); $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); $this->assertEquals('http://host.tld/?WDWyig', $link['url']); $this->assertContains('Direct link', $link['description']); $this->assertContains('http://host.tld/?WDWyig', $link['description']); // Second link is a direct link $link = array_shift($data['links']); - $this->assertEquals('20150310_114633', $link['linkdate']); - $this->assertEquals('http://host.tld/?kLHmZg', $link['guid']); + $this->assertEquals(8, $link['id']); + $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114633'), $link['created']); + $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); $this->assertContains('Direct link', $link['description']); $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); @@ -217,4 +222,38 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); $this->assertEquals('http://pubsubhub.io', $data['pubsubhub_url']); } + + /** + * Test buildData when Shaarli is served from a subdirectory + */ + public function testBuildDataServerSubdir() + { + $serverInfo = array( + 'HTTPS' => 'Off', + 'SERVER_NAME' => 'host.tld', + 'SERVER_PORT' => '8080', + 'SCRIPT_NAME' => '/~user/shaarli/index.php', + 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', + ); + $feedBuilder = new FeedBuilder( + self::$linkDB, + FeedBuilder::$FEED_ATOM, + $serverInfo, + null, + false + ); + $feedBuilder->setLocale(self::$LOCALE); + $data = $feedBuilder->buildData(); + + $this->assertEquals( + 'http://host.tld:8080/~user/shaarli/index.php?do=feed', + $data['self_link'] + ); + + // Test first link (note link) + $link = array_shift($data['links']); + $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']); + $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']); + $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']); + } }