Пример #1
0
 /**
  * Reload DebugKit plugin.
  *
  * @param string $vendorDir
  */
 protected static function _reloadDebugKitPlugin($vendorDir)
 {
     $webRoot = $vendorDir . '/cakephp/debug_kit/webroot';
     $assetsDir = $vendorDir . '/cakephp/debug_kit/assets';
     if (is_dir($webRoot)) {
         //  Transport js styles.
         $debugWebroot = new Folder($webRoot);
         $debugWebroot->copy($assetsDir);
         $debugWebroot->delete($webRoot);
     }
     //  Rewrite include scripts.
     $debugFilterFile = $vendorDir . '/cakephp/debug_kit/src/Routing/Filter/DebugBarFilter.php';
     if (file_exists($debugFilterFile)) {
         $debugFilter = new File($debugFilterFile);
         $debugFilter->replaceText("Router::url('/debug_kit/js/toolbar.js')", "vPath()->url('DebugKit:assets/js/toolbar.js')");
     }
     //  Reload default DebugKit AjaxView.
     $debugViewFile = $vendorDir . '/cakephp/debug_kit/src/View/AjaxView.php';
     if (file_exists($debugViewFile)) {
         $debugView = new File($debugViewFile);
         $debugView->replaceText('use Cake\\View\\View;', '');
         $debugView->replaceText('extends View', 'extends \\Union\\App\\View\\AjaxView');
     }
 }
Пример #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 temporary 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 = ['This is the', 'welcome.php file', 'in tmp directory'];
     $replace = ['This should be a', 'welcome.tmp file', 'in the Lib directory'];
     // Replace the contents of the temporary 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();
 }