From 59f9c8b819727cfcd721b69b0f8bbf186eeffaef Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 1 Aug 2017 12:52:58 +0100 Subject: [PATCH 1/3] Configure should be cleared between test cases --- tests/TestCase/Controller/SitemapsControllerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/TestCase/Controller/SitemapsControllerTest.php b/tests/TestCase/Controller/SitemapsControllerTest.php index 49580ea..9648409 100644 --- a/tests/TestCase/Controller/SitemapsControllerTest.php +++ b/tests/TestCase/Controller/SitemapsControllerTest.php @@ -44,6 +44,8 @@ public function setUp() { public function tearDown() { unset($this->Pages); + Configure::clear(); + parent::tearDown(); } @@ -127,4 +129,9 @@ public function testIndexAccess() { $this->assertResponseOk(); } + + public function testLoadingPluginTables() + { + + } } From d91671a62d178c07a8b0431110e5842ef5cc283d Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 1 Aug 2017 13:09:24 +0100 Subject: [PATCH 2/3] Fixed loading plugin table instances, and added a test case --- src/Controller/SitemapsController.php | 4 +- .../Controller/SitemapsControllerTest.php | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Controller/SitemapsController.php b/src/Controller/SitemapsController.php index c5a63b8..7ce9488 100644 --- a/src/Controller/SitemapsController.php +++ b/src/Controller/SitemapsController.php @@ -25,8 +25,8 @@ public function index() { } foreach ($tablesToList as $table) { - $this->loadModel($table); - $data[$table] = $this->{$table}->find('forSitemap'); + $tableInstance = $this->loadModel($table); + $data[$table] = $tableInstance->find('forSitemap'); } $this->set('data', $data); diff --git a/tests/TestCase/Controller/SitemapsControllerTest.php b/tests/TestCase/Controller/SitemapsControllerTest.php index 9648409..c46851f 100644 --- a/tests/TestCase/Controller/SitemapsControllerTest.php +++ b/tests/TestCase/Controller/SitemapsControllerTest.php @@ -5,6 +5,8 @@ namespace Sitemap\Test\TestCase\Controller; use Cake\Core\Configure; +use Cake\Database\Schema\TableSchema; +use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\TestSuite\IntegrationTestCase; use Sitemap\Controller\SitemapsController; @@ -130,8 +132,35 @@ public function testIndexAccess() { $this->assertResponseOk(); } - public function testLoadingPluginTables() - { - - } + /** + * Test that the index method can execute finds on namespaced plugin tables + * + * @return void + */ + public function testLoadingPluginTables() { + $exampleTableName = 'Example/Plugin.Posts'; + Configure::write('Sitemap.tables', [$exampleTableName]); + + $tableInstance = new Table([ + 'registryAlias' => 'Example/Plugin.Posts', + 'alias' => 'Posts', + 'table' => 'posts', + 'schema' => new TableSchema('posts', [ + 'id' => ['type' => 'integer'], + 'title' => ['type' => 'string'], + ]), + ]); + $tableInstance->addBehavior('Sitemap.Sitemap'); + + $Controller = $this->getMockBuilder(SitemapsController::class) + ->setMethods(['loadModel']) + ->getMock(); + + $Controller->expects($this->once()) + ->method('loadModel') + ->with($exampleTableName) + ->willReturn($tableInstance); + + $Controller->index(); + } } From f9b6d9c31a90ab9e754271767a6ba05154907e8b Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 1 Aug 2017 14:29:33 +0100 Subject: [PATCH 3/3] Fix existing test to return correct value from loadModel --- tests/TestCase/Controller/SitemapsControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Controller/SitemapsControllerTest.php b/tests/TestCase/Controller/SitemapsControllerTest.php index c46851f..7d998ec 100644 --- a/tests/TestCase/Controller/SitemapsControllerTest.php +++ b/tests/TestCase/Controller/SitemapsControllerTest.php @@ -113,7 +113,7 @@ public function testIndexWithModels() { $Controller->expects($this->once()) ->method('loadModel') ->with('Pages') - ->will($this->returnValue(true)); + ->willReturn($this->Pages); $Controller->Pages = $this->Pages;