1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Tests for filtering during feed parsing

This commit is contained in:
J. King 2021-01-11 23:12:43 -05:00
parent a4146ec129
commit 097362881b
3 changed files with 25 additions and 16 deletions

View file

@ -286,7 +286,7 @@ class Feed {
$articles = Arsse::$db->feedMatchLatest($feedID, sizeof($items))->getAll();
// perform a first pass matching the latest articles against items in the feed
[$this->newItems, $this->changedItems] = $this->matchItems($items, $articles);
if (sizeof($this->newItems) && sizeof($items) <= sizeof($articles)) {
if (sizeof($this->newItems)) {
// if we need to, perform a second pass on the database looking specifically for IDs and hashes of the new items
$ids = $hashesUT = $hashesUC = $hashesTC = [];
foreach ($this->newItems as $i) {

View file

@ -382,13 +382,22 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
public function testApplyFilterRules(): void {
\Phake::when(Arsse::$db)->feedMatchIds->thenReturn(new Result([
['id' => 7, 'guid' => '0f2a218c311e3d8105f1b075142a5d26dabf056ffc61abe77e96c8f071bbf4a7', 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 47, 'guid' => '1c19e3b9018bc246b7414ae919ddebc88d0c575129e8c4a57b84b826c00f6db5', 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 2112, 'guid' => '964db0b9292ad0c7a6c225f2e0966f3bda53486fae65db0310c97409974e65b8', 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 1, 'guid' => '436070cda5713a0d9a8fdc8652c7ab142f0550697acfd5206a16c18aee355039', 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 42, 'guid' => '1a731433a1904220ef26e731ada7262e1d5bcecae53e7b5df9e1f5713af6e5d3', 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
// these are the sixth through tenth entries in the feed; the title hashes have been omitted for brevity
['id' => 7, 'guid' => '0f2a218c311e3d8105f1b075142a5d26dabf056ffc61abe77e96c8f071bbf4a7', 'edited' => null, 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 47, 'guid' => '1c19e3b9018bc246b7414ae919ddebc88d0c575129e8c4a57b84b826c00f6db5', 'edited' => null, 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 2112, 'guid' => '964db0b9292ad0c7a6c225f2e0966f3bda53486fae65db0310c97409974e65b8', 'edited' => null, 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 1, 'guid' => '436070cda5713a0d9a8fdc8652c7ab142f0550697acfd5206a16c18aee355039', 'edited' => null, 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
['id' => 42, 'guid' => '1a731433a1904220ef26e731ada7262e1d5bcecae53e7b5df9e1f5713af6e5d3', 'edited' => null, 'url_title_hash' => "", 'url_content_hash' => '', 'title_content_hash' => ''],
]));
$f = new Feed(null, $this->base."Filtering/1");
$this->markTestIncomplete();
\Phake::when(Arsse::$db)->feedRulesGet->thenReturn([
'jack' => ['keep' => "", 'block' => '`A|W|J|S`u'],
'sam' => ['keep' => "`B|T|X`u", 'block' => '`C`u'],
]);
$f = new Feed(5, $this->base."Filtering/1");
$exp = [
'jack' => ['new' => [false, true, true, false, true], 'changed' => [7 => true, 47 => true, 2112 => false, 1 => true, 42 => false]],
'sam' => ['new' => [false, true, false, false, false], 'changed' => [7 => false, 47 => true, 2112 => false, 1 => false, 42 => false]],
];
$this->assertSame($exp, $f->filteredItems);
}
}

View file

@ -38,23 +38,23 @@
</entry>
<entry>
<id>urn:uuid:6d4c7964-43e1-11e7-92bd-4fed65d89796</id>
<title>T</title>
<category>Z</category>
<title>G</title>
<category>T</category>
</entry>
<entry>
<id>urn:uuid:6d4c7964-43e1-11e7-92bd-4fed65d89797</id>
<title>S</title>
<category>Z</category>
<title>H</title>
<category>S</category>
</entry>
<entry>
<id>urn:uuid:6d4c7964-43e1-11e7-92bd-4fed65d89798</id>
<title>R</title>
<category>Z</category>
<title>I</title>
<category>R</category>
</entry>
<entry>
<id>urn:uuid:6d4c7964-43e1-11e7-92bd-4fed65d89799</id>
<title>Q</title>
<category>Z</category>
<title>J</title>
<category>Q</category>
</entry>
</feed>
MESSAGE_BODY