Browse Source

Feed tests: deduplication

microsub
J. King 7 years ago
parent
commit
ff59f00356
  1. 14
      tests/Feed/TestFeed.php
  2. 41
      tests/docroot/Feed/Deduplication/Hashes-Dates1.php
  3. 41
      tests/docroot/Feed/Deduplication/Hashes-Dates2.php
  4. 41
      tests/docroot/Feed/Deduplication/Hashes-Dates3.php
  5. 33
      tests/docroot/Feed/Deduplication/Hashes.php
  6. 22
      tests/docroot/Feed/Deduplication/IdenticalHashes.php

14
tests/Feed/TestFeed.php

@ -20,6 +20,7 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
}
function testDeduplicateFeedItems() {
// duplicates with dates lead to the newest match being kept
$t = strtotime("2002-05-19T15:21:36Z");
$f = new Feed(null, $this->base."Deduplication/Permalink-Dates");
$this->assertCount(2, $f->newItems);
@ -30,6 +31,19 @@ class TestFeed extends \PHPUnit\Framework\TestCase {
$f = new Feed(null, $this->base."Deduplication/IdenticalHashes");
$this->assertCount(2, $f->newItems);
$this->assertTime($t, $f->newItems[0]->updatedDate);
$f = new Feed(null, $this->base."Deduplication/Hashes-Dates1"); // content differs
$this->assertCount(2, $f->newItems);
$this->assertTime($t, $f->newItems[0]->updatedDate);
$f = new Feed(null, $this->base."Deduplication/Hashes-Dates2"); // title differs
$this->assertCount(2, $f->newItems);
$this->assertTime($t, $f->newItems[0]->updatedDate);
$f = new Feed(null, $this->base."Deduplication/Hashes-Dates3"); // URL differs
$this->assertCount(2, $f->newItems);
$this->assertTime($t, $f->newItems[0]->updatedDate);
// duplicates without dates lead to the topmost entry being kept
$f = new Feed(null, $this->base."Deduplication/Hashes");
$this->assertCount(2, $f->newItems);
$this->assertSame("http://example.com/1", $f->newItems[0]->url);
}
function testHandleCacheHeadersOn304() {

41
tests/docroot/Feed/Deduplication/Hashes-Dates1.php

@ -0,0 +1,41 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<title>Article The First</title>
<link>http://example.com/1</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 1995 15:21:36 GMT</pubDate>
<atom:updated>2002-02-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1</link>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> <!-- This is the correct item and date -->
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1</link>
<description>Sample article 3</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The Second</title>
<link>http://example.com/2</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>
MESSAGE_BODY
];

41
tests/docroot/Feed/Deduplication/Hashes-Dates2.php

@ -0,0 +1,41 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<title>Article The First</title>
<link>http://example.com/1</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 1995 15:21:36 GMT</pubDate>
<atom:updated>2002-02-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First!</title>
<link>http://example.com/1</link>
<description>Sample article 1</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> <!-- This is the correct item and date -->
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First?</title>
<link>http://example.com/1</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The Second</title>
<link>http://example.com/2</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>
MESSAGE_BODY
];

41
tests/docroot/Feed/Deduplication/Hashes-Dates3.php

@ -0,0 +1,41 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<title>Article The First</title>
<link>http://example.com/1?</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 1995 15:21:36 GMT</pubDate>
<atom:updated>2002-02-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1</link>
<description>Sample article 1</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> <!-- This is the correct item and date -->
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1?ook=</link>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
<item>
<title>Article The Second</title>
<link>http://example.com/2</link>
<description>Sample article 4</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>
MESSAGE_BODY
];

33
tests/docroot/Feed/Deduplication/Hashes.php

@ -0,0 +1,33 @@
<?php return [
'mime' => "application/rss+xml",
'content' => <<<MESSAGE_BODY
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Test feed</title>
<link>http://example.com/</link>
<description>A basic feed for testing</description>
<item>
<title>Article The First</title>
<link>http://example.com/1</link> <!-- This is the correct item -->
<description>Sample article 1</description>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1?</link>
<description>Sample article 1</description>
</item>
<item>
<title>Article The First</title>
<link>http://example.com/1?ook=</link>
<description>Sample article 1</description>
</item>
<item>
<title>Article The Second</title>
<link>http://example.com/2</link>
<description>Sample article 4</description>
</item>
</channel>
</rss>
MESSAGE_BODY
];

22
tests/docroot/Feed/Deduplication/IdenticalHashes.php

@ -9,27 +9,27 @@
<item>
<guid>1</guid>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> <!-- This is the correct item and date -->
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 1995 15:21:36 GMT</pubDate>
<atom:updated>2002-02-19T15:21:36Z</atom:updated>
</item>
<item>
<guid>1</guid>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
<description>Sample article 1</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate> <!-- This is the correct item and date -->
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
</item>
<item>
<guid>1</guid>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
<item>
<guid>2</guid>
<description>Sample article 2</description>
<pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
<atom:updated>2002-04-19T15:21:36Z</atom:updated>
<description>Sample article 1</description>
<pubDate>Sun, 18 May 2000 15:21:36 GMT</pubDate>
<atom:updated>1999-05-19T15:21:36Z</atom:updated>
</item>
</channel>
</rss>

Loading…
Cancel
Save