getMock('Cake\Console\ConsoleIo', [], [], '', false); $this->Task = $this->getMock('Cake\Shell\Task\TemplateTask', array('in', 'err', 'createFile', '_stop', 'clear'), array($io) ); } /** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); unset($this->Task); } /** * test finding templates installed in * * @return void */ public function testFindingInstalledTemplatesForBake() { $consoleLibs = CAKE . 'Template' . DS; $this->Task->initialize(); $this->assertPathEquals($this->Task->templatePaths['default'], $consoleLibs . 'Bake/default/'); } /** * test using an invalid template name. * * @expectedException \RuntimeException * @expectedExceptionMessage Unable to locate "nope" bake template * @return void */ public function testGetTemplatePathInvalid() { $defaultTemplate = CAKE . 'Template/Bake/default/'; $this->Task->templatePaths = ['default' => $defaultTemplate]; $this->Task->params['template'] = 'nope'; $this->Task->getTemplatePath(); } /** * test getting the correct template name. Ensure that with only one template, or a template param * that the user is not bugged. If there are more, find and return the correct template name * * @return void */ public function testGetTemplatePath() { $defaultTemplate = CAKE . 'Template/Bake/default/'; $this->Task->templatePaths = ['default' => $defaultTemplate]; $result = $this->Task->getTemplatePath(); $this->assertEquals($defaultTemplate, $result); $this->Task->templatePaths = ['other' => '/some/path', 'default' => $defaultTemplate]; $this->Task->params['template'] = 'other'; $result = $this->Task->getTemplatePath(); $this->assertEquals('/some/path', $result); $this->Task->params = array(); $result = $this->Task->getTemplatePath(); $this->assertEquals($defaultTemplate, $result); $this->assertEquals('default', $this->Task->params['template']); } /** * test generate * * @return void */ public function testGenerate() { $this->Task->initialize(); $this->Task->expects($this->any())->method('in')->will($this->returnValue(1)); $result = $this->Task->generate('classes', 'test_object', array('test' => 'foo')); $expected = "I got rendered\nfoo"; $this->assertTextEquals($expected, $result); } /** * test generate with a missing template in the chosen template. * ensure fallback to default works. * * @return void */ public function testGenerateWithTemplateFallbacks() { $this->Task->initialize(); $this->Task->params['template'] = 'test'; $this->Task->set(array( 'name' => 'Article', 'model' => 'Article', 'table' => 'articles', 'import' => false, 'records' => false, 'schema' => '', 'namespace' => '' )); $result = $this->Task->generate('classes', 'fixture'); $this->assertRegExp('/ArticleFixture extends .*TestFixture/', $result); } }