Skip to content

Commit

Permalink
Merge pull request #51 from davidyell/plugin-tables
Browse files Browse the repository at this point in the history
Resolves #50
  • Loading branch information
justinyost committed Aug 2, 2017
2 parents b636da4 + f9b6d9c commit ff00f3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Controller/SitemapsController.php
Expand Up @@ -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);
Expand Down
38 changes: 37 additions & 1 deletion tests/TestCase/Controller/SitemapsControllerTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +46,8 @@ public function setUp() {
public function tearDown() {
unset($this->Pages);

Configure::clear();

parent::tearDown();
}

Expand Down Expand Up @@ -109,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;

Expand All @@ -127,4 +131,36 @@ public function testIndexAccess() {

$this->assertResponseOk();
}

/**
* 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();
}
}

0 comments on commit ff00f3f

Please sign in to comment.