From ff59f00356fdc1f02bc83c5acd3f4220ce68f60e Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 26 May 2017 17:55:51 -0400 Subject: [PATCH] Feed tests: deduplication --- tests/Feed/TestFeed.php | 14 +++++++ .../Feed/Deduplication/Hashes-Dates1.php | 41 +++++++++++++++++++ .../Feed/Deduplication/Hashes-Dates2.php | 41 +++++++++++++++++++ .../Feed/Deduplication/Hashes-Dates3.php | 41 +++++++++++++++++++ tests/docroot/Feed/Deduplication/Hashes.php | 33 +++++++++++++++ .../Feed/Deduplication/IdenticalHashes.php | 22 +++++----- 6 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 tests/docroot/Feed/Deduplication/Hashes-Dates1.php create mode 100644 tests/docroot/Feed/Deduplication/Hashes-Dates2.php create mode 100644 tests/docroot/Feed/Deduplication/Hashes-Dates3.php create mode 100644 tests/docroot/Feed/Deduplication/Hashes.php diff --git a/tests/Feed/TestFeed.php b/tests/Feed/TestFeed.php index 0bd9bef..6fe949b 100644 --- a/tests/Feed/TestFeed.php +++ b/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() { diff --git a/tests/docroot/Feed/Deduplication/Hashes-Dates1.php b/tests/docroot/Feed/Deduplication/Hashes-Dates1.php new file mode 100644 index 0000000..364133c --- /dev/null +++ b/tests/docroot/Feed/Deduplication/Hashes-Dates1.php @@ -0,0 +1,41 @@ + "application/rss+xml", + 'content' => << + + Test feed + http://example.com/ + A basic feed for testing + + + Article The First + http://example.com/1 + Sample article 1 + Sun, 18 May 1995 15:21:36 GMT + 2002-02-19T15:21:36Z + + + Article The First + http://example.com/1 + Sample article 2 + Sun, 19 May 2002 15:21:36 GMT + 2002-04-19T15:21:36Z + + + Article The First + http://example.com/1 + Sample article 3 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + Article The Second + http://example.com/2 + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + +MESSAGE_BODY +]; \ No newline at end of file diff --git a/tests/docroot/Feed/Deduplication/Hashes-Dates2.php b/tests/docroot/Feed/Deduplication/Hashes-Dates2.php new file mode 100644 index 0000000..3f2f2a2 --- /dev/null +++ b/tests/docroot/Feed/Deduplication/Hashes-Dates2.php @@ -0,0 +1,41 @@ + "application/rss+xml", + 'content' => << + + Test feed + http://example.com/ + A basic feed for testing + + + Article The First + http://example.com/1 + Sample article 1 + Sun, 18 May 1995 15:21:36 GMT + 2002-02-19T15:21:36Z + + + Article The First! + http://example.com/1 + Sample article 1 + Sun, 19 May 2002 15:21:36 GMT + 2002-04-19T15:21:36Z + + + Article The First? + http://example.com/1 + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + Article The Second + http://example.com/2 + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + +MESSAGE_BODY +]; \ No newline at end of file diff --git a/tests/docroot/Feed/Deduplication/Hashes-Dates3.php b/tests/docroot/Feed/Deduplication/Hashes-Dates3.php new file mode 100644 index 0000000..5eec075 --- /dev/null +++ b/tests/docroot/Feed/Deduplication/Hashes-Dates3.php @@ -0,0 +1,41 @@ + "application/rss+xml", + 'content' => << + + Test feed + http://example.com/ + A basic feed for testing + + + Article The First + http://example.com/1? + Sample article 1 + Sun, 18 May 1995 15:21:36 GMT + 2002-02-19T15:21:36Z + + + Article The First + http://example.com/1 + Sample article 1 + Sun, 19 May 2002 15:21:36 GMT + 2002-04-19T15:21:36Z + + + Article The First + http://example.com/1?ook= + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + Article The Second + http://example.com/2 + Sample article 4 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z + + + +MESSAGE_BODY +]; \ No newline at end of file diff --git a/tests/docroot/Feed/Deduplication/Hashes.php b/tests/docroot/Feed/Deduplication/Hashes.php new file mode 100644 index 0000000..f0dbb11 --- /dev/null +++ b/tests/docroot/Feed/Deduplication/Hashes.php @@ -0,0 +1,33 @@ + "application/rss+xml", + 'content' => << + + Test feed + http://example.com/ + A basic feed for testing + + + Article The First + http://example.com/1 + Sample article 1 + + + Article The First + http://example.com/1? + Sample article 1 + + + Article The First + http://example.com/1?ook= + Sample article 1 + + + Article The Second + http://example.com/2 + Sample article 4 + + + +MESSAGE_BODY +]; \ No newline at end of file diff --git a/tests/docroot/Feed/Deduplication/IdenticalHashes.php b/tests/docroot/Feed/Deduplication/IdenticalHashes.php index a512631..ced4fbd 100644 --- a/tests/docroot/Feed/Deduplication/IdenticalHashes.php +++ b/tests/docroot/Feed/Deduplication/IdenticalHashes.php @@ -9,27 +9,27 @@ 1 - Sample article 2 - Sun, 19 May 2002 15:21:36 GMT - 2002-04-19T15:21:36Z + Sample article 1 + Sun, 18 May 1995 15:21:36 GMT + 2002-02-19T15:21:36Z 1 - Sample article 2 - Sun, 19 May 2002 15:21:36 GMT + Sample article 1 + Sun, 19 May 2002 15:21:36 GMT 2002-04-19T15:21:36Z 1 - Sample article 2 - Sun, 19 May 2002 15:21:36 GMT - 2002-04-19T15:21:36Z + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z 2 - Sample article 2 - Sun, 19 May 2002 15:21:36 GMT - 2002-04-19T15:21:36Z + Sample article 1 + Sun, 18 May 2000 15:21:36 GMT + 1999-05-19T15:21:36Z