diff --git a/tests/cases/ImportExport/TestImportExport.php b/tests/cases/ImportExport/TestImportExport.php index 40c1cd33..f5452a55 100644 --- a/tests/cases/ImportExport/TestImportExport.php +++ b/tests/cases/ImportExport/TestImportExport.php @@ -18,7 +18,7 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { protected $proc; protected $checkTables = [ 'arsse_folders' => ["id", "owner", "parent", "name"], - 'arsse_feeds' => ['id', 'url'], + 'arsse_feeds' => ["id", "url", "title"], 'arsse_subscriptions' => ["id", "owner", "folder", "feed", "title"], 'arsse_tags' => ["id", "owner", "name"], 'arsse_tag_members' => ["tag", "subscription", "assigned"], @@ -197,4 +197,68 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { $this->proc->import("john.doe@example.com", "", false, true); $this->compareExpectations($this->drv, $exp); } + + public function testModifyASubscription() { + $in = [[ + ['url' => "http://localhost:8000/Import/nasa-jpl", 'title' => "NASA JPL", 'folder' => 3, 'tags' => ["tech"]], + ['url' => "http://localhost:8000/Import/ars", 'title' => "Ars Technica", 'folder' => 2, 'tags' => ["frequent", "tech"]], + ['url' => "http://localhost:8000/Import/torstar", 'title' => "Toronto Star", 'folder' => 5, 'tags' => ["news", "canada", "toronto"]], + ['url' => "http://localhost:8000/Import/citizen", 'title' => "Ottawa Citizen", 'folder' => 6, 'tags' => ["news", "canada"]], + ['url' => "http://localhost:8000/Import/eurogamer", 'title' => "Eurogamer", 'folder' => 0, 'tags' => ["gaming", "frequent"]], + ['url' => "http://localhost:8000/Import/cbc", 'title' => "CBC", 'folder' => 0, 'tags' => ["news", "canada"]], // moved to root and renamed + ], [1 => + ['id' => 1, 'name' => "Photography", 'parent' => 0], + ['id' => 2, 'name' => "Science", 'parent' => 0], + ['id' => 3, 'name' => "Rocketry", 'parent' => 2], + ['id' => 4, 'name' => "Politics", 'parent' => 0], + ['id' => 5, 'name' => "Local", 'parent' => 4], + ['id' => 6, 'name' => "National", 'parent' => 4], + ]]; + \Phake::when($this->proc)->parse->thenReturn($in); + $this->proc->import("john.doe@example.com", "", false, true); + $exp = $this->primeExpectations($this->data, $this->checkTables); + $exp['arsse_subscriptions']['rows'][3] = [4, "john.doe@example.com", null, 4, "CBC"]; + $this->compareExpectations($this->drv, $exp); + } + + public function testImportAFeed() { + $in = [[ + ['url' => "http://localhost:8000/Import/some-feed", 'title' => "Some Feed", 'folder' => 0, 'tags' => ["frequent", "cryptic"]], //one existing tag and one new one + ], []]; + \Phake::when($this->proc)->parse->thenReturn($in); + $this->proc->import("john.doe@example.com", "", false, false); + $exp = $this->primeExpectations($this->data, $this->checkTables); + $exp['arsse_feeds']['rows'][] = [7, "http://localhost:8000/Import/some-feed", "Some feed"]; // author-supplied and user-supplied titles differ + $exp['arsse_subscriptions']['rows'][] = [7, "john.doe@example.com", null, 7, "Some Feed"]; + $exp['arsse_tags']['rows'][] = [7, "john.doe@example.com", "cryptic"]; + $exp['arsse_tag_members']['rows'][] = [2, 7, 1]; + $exp['arsse_tag_members']['rows'][] = [7, 7, 1]; + $this->compareExpectations($this->drv, $exp); + } + + public function testImportAFeedWithAnInvalidTag() { + $in = [[ + ['url' => "http://localhost:8000/Import/some-feed", 'title' => "Some Feed", 'folder' => 0, 'tags' => [""]], + ], []]; + \Phake::when($this->proc)->parse->thenReturn($in); + $this->assertException("invalidTagName", "ImportExport"); + $this->proc->import("john.doe@example.com", "", false, false); + } + + public function testReplaceData() { + $in = [[ + ['url' => "http://localhost:8000/Import/some-feed", 'title' => "Some Feed", 'folder' => 1, 'tags' => ["frequent", "cryptic"]], + ], [1 => + ['id' => 1, 'name' => "Photography", 'parent' => 0], + ]]; + \Phake::when($this->proc)->parse->thenReturn($in); + $this->proc->import("john.doe@example.com", "", false, true); + $exp = $this->primeExpectations($this->data, $this->checkTables); + $exp['arsse_feeds']['rows'][] = [7, "http://localhost:8000/Import/some-feed", "Some feed"]; // author-supplied and user-supplied titles differ + $exp['arsse_subscriptions']['rows'] = [[7, "john.doe@example.com", 4, 7, "Some Feed"]]; + $exp['arsse_tags']['rows'] = [[2, "john.doe@example.com", "frequent"], [7, "john.doe@example.com", "cryptic"]]; + $exp['arsse_tag_members']['rows'] = [[2, 7, 1], [7, 7, 1]]; + $exp['arsse_folders']['rows'] = [[4, "john.doe@example.com", null, "Photography"]]; + $this->compareExpectations($this->drv, $exp); + } } diff --git a/tests/docroot/Import/some-feed.php b/tests/docroot/Import/some-feed.php new file mode 100644 index 00000000..eec58567 --- /dev/null +++ b/tests/docroot/Import/some-feed.php @@ -0,0 +1,18 @@ + "application/rss+xml", + 'content' => << + + Some feed + http://example.com/ + Just a generic feed + + + http://localhost:8000/Import/some-feed/some-article + Some article + This feed is used only to demonstrate failure modes external to the feed itself + + + +MESSAGE_BODY +]; diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 1644b594..6334e5c5 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -173,7 +173,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { $data = $drv->prepare("SELECT $cols from $table")->run()->getAll(); $cols = array_keys($info['columns']); foreach ($info['rows'] as $index => $row) { - $this->assertCount(sizeof($cols), $row, "The number of values for array index $index does not match the number of fields"); + $this->assertCount(sizeof($cols), $row, "The number of columns in array index $index of expectations for table $table does not match its definition"); $row = array_combine($cols, $row); foreach ($data as $index => $test) { foreach ($test as $col => $value) { @@ -197,11 +197,11 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { break; } } - $this->assertContains($row, $data, "Table $table does not contain record at array index $index."); + $this->assertContains($row, $data, "Actual Table $table does not contain record at expected array index $index"); $found = array_search($row, $data, true); unset($data[$found]); } - $this->assertSame([], $data); + $this->assertSame([], $data, "Actual table $table contains extra rows not in expectations"); } return true; }