From 103755cfb400e864b6312f252ac47249e4b6aa3c Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 5 Jul 2019 19:01:34 -0400 Subject: [PATCH] Test fixture for import tests --- tests/cases/ImportExport/TestImportExport.php | 76 +++++++++++++++++++ tests/lib/AbstractTest.php | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/tests/cases/ImportExport/TestImportExport.php b/tests/cases/ImportExport/TestImportExport.php index 9001b11..c1b5e14 100644 --- a/tests/cases/ImportExport/TestImportExport.php +++ b/tests/cases/ImportExport/TestImportExport.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\ImportExport; +use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Db\SQLite3\Driver; use JKingWeb\Arsse\ImportExport\AbstractImportExport; use JKingWeb\Arsse\ImportExport\Exception; @@ -15,9 +16,20 @@ use JKingWeb\Arsse\Test\Database; class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { protected $drv; protected $proc; + protected $checkTables = [ + 'arsse_folders' => ["id", "owner", "parent", "name"], + 'arsse_feeds' => ['id', 'url'], + 'arsse_subscriptions' => ["id", "owner", "folder", "feed", "title"], + 'arsse_tags' => ["id", "owner", "name"], + 'arsse_tag_members' => ["tag", "subscription", "assigned"], + ]; public function setUp() { self::clearData(); + // create a mock user manager + Arsse::$user = \Phake::mock(\JKingWeb\Arsse\User::class); + \Phake::when(Arsse::$user)->exists->thenReturn(true); + \Phake::when(Arsse::$user)->authorize->thenReturn(true); // create a mock Import/Export processor $this->proc = \Phake::partialMock(AbstractImportExport::class); // initialize an SQLite memeory database @@ -37,6 +49,8 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { 'password' => 'str', ], 'rows' => [ + ["john.doe@example.com", ""], + ["jane.doe@example.com", ""], ], ], 'arsse_folders' => [ @@ -47,6 +61,12 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { 'name' => "str", ], 'rows' => [ + [1, "john.doe@example.com", null, "Science"], + [2, "john.doe@example.com", 1, "Rocketry"], + [3, "john.doe@example.com", null, "Politics"], + [4, "john.doe@example.com", null, "Photography"], + [5, "john.doe@example.com", 3, "Local"], + [6, "john.doe@example.com", 3, "National"], ], ], 'arsse_feeds' => [ @@ -56,16 +76,29 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { 'title' => "str", ], 'rows' => [ + [1, "http://localhost:8000/Import/nasa-jpl", "NASA JPL"], + [2, "http://localhost:8000/Import/torstar", "Toronto Star"], + [3, "http://localhost:8000/Import/ars", "Ars Technica"], + [4, "http://localhost:8000/Import/cbc", "CBC News"], + [5, "http://localhost:8000/Import/citizen", "Ottawa Citizen"], + [6, "http://localhost:8000/Import/eurogamer", "Eurogamer"], ], ], 'arsse_subscriptions' => [ 'columns' => [ 'id' => "int", 'owner' => "str", + 'folder' => "int", 'feed' => "int", 'title' => "str", ], 'rows' => [ + [1, "john.doe@example.com", 2, 1, "NASA JPL"], + [2, "john.doe@example.com", 5, 2, "Toronto Star"], + [3, "john.doe@example.com", 1, 3, "Ars Technica"], + [4, "john.doe@example.com", 6, 4, "CBC News"], + [5, "john.doe@example.com", 6, 5, "Ottawa Citizen"], + [6, "john.doe@example.com", null, 6, "Eurogamer"], ], ], 'arsse_tags' => [ @@ -75,6 +108,12 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { 'name' => "str", ], 'rows' => [ + [1, "john.doe@example.com", "canada"], + [2, "john.doe@example.com", "frequent"], + [3, "john.doe@example.com", "gaming"], + [4, "john.doe@example.com", "news"], + [5, "john.doe@example.com", "tech"], + [6, "john.doe@example.com", "toronto"], ], ], 'arsse_tag_members' => [ @@ -84,9 +123,22 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { 'assigned' => "bool", ], 'rows' => [ + [1, 2, 1], + [1, 4, 1], + [1, 5, 1], + [2, 3, 1], + [2, 6, 1], + [3, 6, 1], + [4, 2, 1], + [4, 4, 1], + [4, 5, 1], + [5, 1, 1], + [5, 3, 1], + [6, 2, 1], ], ], ]; + $this->primeDatabase($this->drv, $this->data); } public function tearDown() { @@ -94,4 +146,28 @@ class TestImportExport extends \JKingWeb\Arsse\Test\AbstractTest { $this->proc = null; self::clearData(); } + + public function testMakeNoEffectiveChnages() { + $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 News", 'folder' => 6, 'tags' => ["news", "canada"]], + ], [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); + $exp = $this->primeExpectations($this->data, $this->checkTables); + $this->proc->import("john.doe@example.com", "", false, false); + $this->compareExpectations($this->drv, $exp); + $this->proc->import("john.doe@example.com", "", false, true); + $this->compareExpectations($this->drv, $exp); + } } diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index b1b79f1..30b69b0 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -203,7 +203,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { return true; } - public function primeExpectations(array $source, array $tableSpecs = null): array { + public function primeExpectations(array $source, array $tableSpecs): array { $out = []; foreach ($tableSpecs as $table => $columns) { // make sure the source has the table we want