Esempio n. 1
0
 /**
  * Run the html string through tidy, and return the (raw) errors. pass back a reference to the
  * normalized string so that the error messages can be linked to the line that caused them.
  *
  * @param string $in ''
  * @param string &$out ''
  * @return string
  */
 public function tidyErrors($in = '', &$out = '')
 {
     $out = preg_replace('@>\\s*<@s', ">\n<", $in);
     // direct access? windows etc
     if (function_exists('tidy_parse_string')) {
         $tidy = tidy_parse_string($out, array(), 'UTF8');
         $tidy->cleanRepair();
         $errors = $tidy->errorBuffer . "\n";
         return $errors;
     }
     // cli
     $File = new File(rtrim(TMP, DS) . DS . rand() . '.html', true);
     $File->write($out);
     $path = $File->pwd();
     $errors = $path . '.err';
     $this->_exec("tidy -eq -utf8 -f {$errors} {$path}");
     $File->delete();
     if (!file_exists($errors)) {
         return '';
     }
     $Error = new File($errors);
     $errors = $Error->read();
     $Error->delete();
     return $errors;
 }
Esempio n. 2
0
 /**
  * Tests that no path is being set for passed file paths that
  * do not exist.
  *
  * @return void
  */
 public function testNoPartialPathBeingSetForNonExistentPath()
 {
     $TmpFile = new File('/non/existent/file');
     $this->assertNull($TmpFile->pwd());
     $this->assertNull($TmpFile->path);
 }
 /**
  * Prepares install from remote URL.
  *
  * @return bool True on success
  */
 protected function _getFromUrl()
 {
     try {
         $http = new Client(['redirect' => 3]);
         // follow up to 3 redirections
         $response = $http->get($this->params['source'], [], ['headers' => ['X-Requested-With' => 'XMLHttpRequest']]);
     } catch (\Exception $ex) {
         $response = false;
         $this->err(__d('installer', 'Could not download the package. Details: {0}', $ex->getMessage()));
         return false;
     }
     if ($response && $response->isOk()) {
         $this->params['source'] = TMP . substr(md5($this->params['source']), 24) . '.zip';
         $file = new File($this->params['source']);
         $responseBody = $response->body();
         if (is_readable($file->pwd())) {
             $file->delete();
         }
         if (!empty($responseBody) && $file->create() && $file->write($responseBody, 'w+', true)) {
             $file->close();
             return $this->_getFromFile();
             $this->err(__d('installer', 'Unable to extract the package.'));
             return false;
         }
         $this->err(__d('installer', 'Unable to download the file, check write permission on "{0}" directory.', [TMP]));
         return false;
     }
     $this->err(__d('installer', 'Could not download the package, no .ZIP file was found at the given URL.'));
     return false;
 }
Esempio n. 4
0
 /**
  * Test mime()
  *
  * @return void
  */
 public function testMime()
 {
     $this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
     $path = TEST_APP . 'webroot/img/cake.power.gif';
     $file = new File($path);
     $expected = 'image/gif';
     if (function_exists('mime_content_type') && mime_content_type($file->pwd()) === false) {
         $expected = false;
     }
     $this->assertEquals($expected, $file->mime());
 }