diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index 76eb63a58d0..4c6b38611b4 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -1,7 +1,5 @@ _processed[get_class($test)] = true; } +/** + * Get the loaded fixtures. + * + * @return array + */ + public function loaded() { + return $this->_loaded; + } + /** * Add aliaes for all non test prefixed connections. * @@ -130,9 +137,9 @@ protected function _loadFixtures($test) { continue; } - list($type, $name) = explode('.', $fixture, 2); - $path = explode('/', $name); - $base = array_pop($path); + list($type, $pathName) = explode('.', $fixture, 2); + $path = explode('/', $pathName); + $name = array_pop($path); $additionalPath = implode('\\', $path); if ($type === 'core') { @@ -140,23 +147,27 @@ protected function _loadFixtures($test) { } elseif ($type === 'app') { $baseNamespace = Configure::read('App.namespace'); } elseif ($type === 'plugin') { - list($plugin, $additionalPath) = explode('.', $additionalPath); - $baseNamespace = Plugin::getNamespace($plugin); + if (strlen($additionalPath)) { + list($plugin, $additionalPath) = explode('.', $additionalPath); + } else { + list($plugin, $name) = explode('.', $name); + } + $baseNamespace = Plugin::getNamespace(Inflector::camelize($plugin)); } else { - $base = $fixture; + $name = $fixture; } - $base = Inflector::camelize($base); + $name = Inflector::camelize($name); $nameSegments = [ $baseNamespace, 'Test\Fixture', $additionalPath, - $base . 'Fixture' + $name . 'Fixture' ]; $className = implode('\\', array_filter($nameSegments)); if (class_exists($className)) { $this->_loaded[$fixture] = new $className(); - $this->_fixtureMap[$base] = $this->_loaded[$fixture]; + $this->_fixtureMap[$name] = $this->_loaded[$fixture]; } else { $msg = sprintf( 'Referenced fixture class "%s" not found. Fixture "%s" was referenced in test case "%s".', diff --git a/tests/TestCase/TestSuite/FixtureManagerTest.php b/tests/TestCase/TestSuite/FixtureManagerTest.php new file mode 100644 index 00000000000..34aa24a9169 --- /dev/null +++ b/tests/TestCase/TestSuite/FixtureManagerTest.php @@ -0,0 +1,72 @@ +manager = new FixtureManager(); + } + +/** + * Test loading core fixtures. + * + * @return void + */ + public function testFixturizeCore() { + $test = $this->getMock('Cake\TestSuite\TestCase'); + $test->fixtures = ['core.article']; + $this->manager->fixturize($test); + $fixtures = $this->manager->loaded(); + $this->assertCount(1, $fixtures); + $this->assertArrayHasKey('core.article', $fixtures); + $this->assertInstanceOf('Cake\Test\Fixture\ArticleFixture', $fixtures['core.article']); + } + +/** + * Test loading app fixtures. + * + * @return void + */ + public function testFixturizePlugin() { + Plugin::load('TestPlugin'); + + $test = $this->getMock('Cake\TestSuite\TestCase'); + $test->fixtures = ['plugin.test_plugin.article']; + $this->manager->fixturize($test); + $fixtures = $this->manager->loaded(); + $this->assertCount(1, $fixtures); + $this->assertArrayHasKey('plugin.test_plugin.article', $fixtures); + $this->assertInstanceOf( + 'TestPlugin\Test\Fixture\ArticleFixture', + $fixtures['plugin.test_plugin.article'] + ); + } + +} diff --git a/tests/test_app/Plugin/TestPlugin/Test/Fixture/ArticleFixture.php b/tests/test_app/Plugin/TestPlugin/Test/Fixture/ArticleFixture.php new file mode 100644 index 00000000000..85c2a64cbc0 --- /dev/null +++ b/tests/test_app/Plugin/TestPlugin/Test/Fixture/ArticleFixture.php @@ -0,0 +1,45 @@ + ['type' => 'integer'], + 'author_id' => ['type' => 'integer', 'null' => true], + 'title' => ['type' => 'string', 'null' => true], + 'body' => 'text', + '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]] + ); + +/** + * records property + * + * @var array + */ + public $records = [ + ['author_id' => 1, 'title' => 'Plugin Article', 'body' => 'Plugin Article Body'], + ]; + +}