示例#1
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();
     }
 }
示例#2
0
 /**
  * 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();
 }