예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * Write the files that need to be stored
  *
  * @return void
  */
 protected function _writeFiles()
 {
     $overwriteAll = false;
     if (!empty($this->params['overwrite'])) {
         $overwriteAll = true;
     }
     foreach ($this->_storage as $category => $domains) {
         foreach ($domains as $domain => $sentences) {
             $output = $this->_writeHeader();
             foreach ($sentences as $sentence => $header) {
                 $output .= $header . $sentence;
             }
             $filename = $domain . '.pot';
             if ($category === 'LC_MESSAGES') {
                 $File = new File($this->_output . $filename);
             } else {
                 new Folder($this->_output . $category, true);
                 $File = new File($this->_output . $category . DS . $filename);
             }
             $response = '';
             while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
                 $this->out();
                 $response = $this->in(__d('cake_console', 'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename), ['y', 'n', 'a'], 'y');
                 if (strtoupper($response) === 'N') {
                     $response = '';
                     while (!$response) {
                         $response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
                         $File = new File($this->_output . $response);
                         $filename = $response;
                     }
                 } elseif (strtoupper($response) === 'A') {
                     $overwriteAll = true;
                 }
             }
             $File->write($output);
             $File->close();
         }
     }
 }
예제 #3
0
 /**
  * test item() with enclosure data.
  *
  * @return void
  */
 public function testItemEnclosureLength()
 {
     if (!is_writable(WWW_ROOT)) {
         $this->markTestSkipped('Webroot is not writable.');
     }
     $testExists = is_dir(WWW_ROOT . 'tests');
     $tmpFile = WWW_ROOT . 'tests/cakephp.file.test.tmp';
     $File = new File($tmpFile, true);
     $this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
     clearstatcache();
     $item = array('title' => array('value' => 'My Title', 'cdata' => true), 'link' => 'http://www.example.com/1', 'description' => array('value' => 'descriptive words', 'cdata' => true), 'enclosure' => array('url' => '/tests/cakephp.file.test.tmp'), 'pubDate' => '2008-05-31 12:00:00', 'guid' => 'http://www.example.com/1', 'category' => array(array('value' => 'CakePHP', 'cdata' => true, 'domain' => 'http://www.cakephp.org'), array('value' => 'Bakery', 'cdata' => true)));
     $result = $this->Rss->item(null, $item);
     if (!function_exists('mime_content_type')) {
         $type = null;
     } else {
         $type = mime_content_type($tmpFile);
     }
     $expected = array('<item', '<title', '<![CDATA[My Title]]', '/title', '<link', 'http://www.example.com/1', '/link', '<description', '<![CDATA[descriptive words]]', '/description', 'enclosure' => array('url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true), 'length' => filesize($tmpFile), 'type' => $type), '<pubDate', date('r', strtotime('2008-05-31 12:00:00')), '/pubDate', '<guid', 'http://www.example.com/1', '/guid', 'category' => array('domain' => 'http://www.cakephp.org'), '<![CDATA[CakePHP]]', '/category', '<category', '<![CDATA[Bakery]]', '/category', '/item');
     if ($type === null) {
         unset($expected['enclosure']['type']);
     }
     $this->assertTags($result, $expected);
     $File->delete();
     if (!$testExists) {
         $Folder = new Folder(WWW_ROOT . 'tests');
         $Folder->delete();
     }
 }
예제 #4
0
 /**
  * testWrite method
  *
  * @return void
  */
 public function testWrite()
 {
     if (!($tmpFile = $this->_getTmpFile())) {
         return false;
     }
     if (file_exists($tmpFile)) {
         unlink($tmpFile);
     }
     $TmpFile = new File($tmpFile);
     $this->assertFalse(file_exists($tmpFile));
     $this->assertFalse(is_resource($TmpFile->handle));
     $testData = array('CakePHP\'s', ' test suite', ' was here ...', '');
     foreach ($testData as $data) {
         $r = $TmpFile->write($data);
         $this->assertTrue($r);
         $this->assertTrue(file_exists($tmpFile));
         $this->assertEquals($data, file_get_contents($tmpFile));
         $this->assertTrue(is_resource($TmpFile->handle));
         $TmpFile->close();
     }
     unlink($tmpFile);
 }
예제 #5
0
 /**
  * testDirSize method
  *
  * @return void
  */
 public function testDirSize()
 {
     $path = TMP . 'tests/';
     $Folder = new Folder($path . 'config_non_existent', true);
     $this->assertEquals(0, $Folder->dirSize());
     $File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
     $File->create();
     $File->write('something here');
     $File->close();
     $this->assertEquals(14, $Folder->dirSize());
 }
예제 #6
0
 /**
  * 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;
 }
예제 #7
0
 /**
  * Creates a file at given path
  *
  * @param string $path Where to put the file.
  * @param string $contents Content to put in the file.
  * @return bool Success
  * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::createFile
  */
 public function createFile($path, $contents)
 {
     $path = str_replace(DS . DS, DS, $path);
     $this->_io->out();
     if (is_file($path) && empty($this->params['force'])) {
         $this->_io->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path));
         $key = $this->_io->askChoice(__d('cake_console', 'Do you want to overwrite?'), ['y', 'n', 'q'], 'n');
         if (strtolower($key) === 'q') {
             $this->_io->out(__d('cake_console', '<error>Quitting</error>.'), 2);
             return $this->_stop();
         } elseif (strtolower($key) !== 'y') {
             $this->_io->out(__d('cake_console', 'Skip `%s`', $path), 2);
             return false;
         }
     } else {
         $this->out(__d('cake_console', 'Creating file %s', $path));
     }
     $File = new File($path, true);
     if ($File->exists() && $File->writable()) {
         $data = $File->prepare($contents);
         $File->write($data);
         $this->_io->out(__d('cake_console', '<success>Wrote</success> `%s`', $path));
         return true;
     }
     $this->_io->err(__d('cake_console', '<error>Could not write to `%s`</error>.', $path), 2);
     return false;
 }