/** * 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); }
/** * testReplaceText method * * @return void */ public function testReplaceText() { $TestFile = new File(TEST_APP . 'vendor/welcome.php'); $TmpFile = new File(TMP . 'tests' . DS . 'cakephp.file.test.tmp'); // Copy the test file to the temporary location $TestFile->copy($TmpFile->path, true); // Replace the contents of the tempory file $result = $TmpFile->replaceText('welcome.php', 'welcome.tmp'); $this->assertTrue($result); // Double check $expected = 'This is the welcome.tmp file in vendors directory'; $contents = $TmpFile->read(); $this->assertContains($expected, $contents); $search = array('This is the', 'welcome.php file', 'in tmp directory'); $replace = array('This should be a', 'welcome.tmp file', 'in the Lib directory'); // Replace the contents of the tempory file $result = $TmpFile->replaceText($search, $replace); $this->assertTrue($result); // Double check $expected = 'This should be a welcome.tmp file in vendors directory'; $contents = $TmpFile->read(); $this->assertContains($expected, $contents); $TmpFile->delete(); }
/** * Enables Configure::read('Routing.prefixes') in /app/Config/routes.php * * @param string $name Name to use as admin routing * @return bool Success */ public function cakeAdmin($name) { $path = $this->appPath ?: APP; $path .= 'Config/'; $File = new File($path . 'routes.php'); $contents = $File->read(); if (preg_match('%(\\s*[/]*Configure::write\\(\'Routing.prefixes\',[\\s\'a-z,\\)\\(\\]\\[]*\\);)%', $contents, $match)) { $result = str_replace($match[0], "\n" . 'Configure::write(\'Routing.prefixes\', [\'' . $name . '\']);', $contents); if ($File->write($result)) { Configure::write('Routing.prefixes', [$name]); return true; } } return false; }
/** * Read the file contents and return a base64 version of the file contents. * * @param string $path The absolute path to the file to read. * @return string File contents in base64 encoding */ protected function _readFile($path) { $File = new File($path); return chunk_split(base64_encode($File->read())); }
/** * Update the app's bootstrap.php file. * * @param string $plugin Name of plugin * @return void */ protected function _modifyBootstrap($plugin) { $bootstrap = new File($this->bootstrap, false); $contents = $bootstrap->read(); if (!preg_match("@\n\\s*Plugin::loadAll@", $contents)) { $bootstrap->append("\nPlugin::load('{$plugin}', ['bootstrap' => false, 'routes' => false]);\n"); $this->out(''); $this->out(sprintf('%s modified', $this->bootstrap)); } }