getMock('Cake\Console\ConsoleOutput', array(), array(), '', false); $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false); $this->Task = $this->getMock('Cake\Console\Command\Task\ProjectTask', array('in', 'err', 'createFile', '_stop'), array($out, $out, $in) ); $this->Task->path = TMP; } /** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); $Folder = new Folder($this->Task->path . 'BakeTestApp'); $Folder->delete(); unset($this->Task); } /** * creates a test project that is used for testing project task. * * @return void */ protected function _setupTestProject() { $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); $this->Task->bake($this->Task->path . 'BakeTestApp'); } /** * test bake with an absolute path. * * @return void */ public function testExecuteWithAbsolutePath() { $this->markTestIncomplete('Need to figure this out'); $path = $this->Task->args[0] = TMP . 'BakeTestApp'; $this->Task->params['skel'] = CAKE . 'Console/Templates/skel'; $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); $this->Task->execute(); $this->assertTrue(is_dir($this->Task->args[0]), 'No project dir'); $File = new File($path . DS . 'Config/paths.php'); $contents = $File->read(); $this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents); } /** * Copy the TestApp route file so it can be modified. * * @return void */ protected function _cloneRoutes() { $File = new File(TEST_APP . 'TestApp/Config/routes.php'); $contents = $File->read(); mkdir(TMP . 'BakeTestApp/Config/', 0777, true); $File = new File(TMP . 'BakeTestApp/Config/routes.php'); $File->write($contents); } /** * test getPrefix method, and that it returns Routing.prefix or writes to config file. * * @return void */ public function testGetPrefix() { Configure::write('Routing.prefixes', array('admin')); $result = $this->Task->getPrefix(); $this->assertEquals('admin_', $result); $this->_cloneRoutes(); Configure::write('Routing.prefixes', null); $this->Task->appPath = TMP . 'BakeTestApp/'; Configure::write('Routing.prefixes', null); $this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin')); $result = $this->Task->getPrefix(); $this->assertEquals('super_duper_admin_', $result); } /** * test cakeAdmin() writing routes.php * * @return void */ public function testCakeAdmin() { $this->_cloneRoutes(); Configure::write('Routing.prefixes', null); $this->Task->appPath = TMP . 'BakeTestApp/'; $result = $this->Task->cakeAdmin('my_prefix'); $this->assertTrue($result); $this->assertEquals(Configure::read('Routing.prefixes'), array('my_prefix')); } /** * test getting the prefix with more than one prefix setup * * @return void */ public function testGetPrefixWithMultiplePrefixes() { Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi')); $this->Task->appPath = $this->Task->path . 'BakeTestApp/'; $this->Task->expects($this->once())->method('in')->will($this->returnValue(2)); $result = $this->Task->getPrefix(); $this->assertEquals('ninja_', $result); } }