/**
  * testCore method
  *
  * @access public
  * @return void
  */
 function testCore()
 {
     $model = App::core('models');
     $this->assertEqual(array(LIBS . 'model' . DS), $model);
     $view = App::core('views');
     $this->assertEqual(array(LIBS . 'view' . DS), $view);
     $controller = App::core('controllers');
     $this->assertEqual(array(LIBS . 'controller' . DS), $controller);
 }
Example #2
0
 /**
  * Initialization method installs Simpletest and loads all plugins
  *
  * @return void
  */
 public function initialize()
 {
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_dispatcher.php';
     $corePath = App::core('cake');
     if (isset($corePath[0])) {
         define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
     } else {
         define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
     }
     $this->_dispatcher = new CakeTestSuiteDispatcher();
     $this->_dispatcher->loadTestFramework();
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'cake_test_suite_command.php';
 }
Example #3
0
 /**
  * Gets the shell command listing.
  *
  * @return array 
  */
 protected function _getShellList()
 {
     $shellList = array();
     $corePaths = App::core('shells');
     $shellList = $this->_appendShells('CORE', $corePaths, $shellList);
     $appPaths = array_diff(App::path('shells'), $corePaths);
     $shellList = $this->_appendShells('app', $appPaths, $shellList);
     $plugins = App::objects('plugin');
     foreach ($plugins as $plugin) {
         $pluginPath = App::pluginPath($plugin) . 'console' . DS . 'shells' . DS;
         $shellList = $this->_appendShells($plugin, array($pluginPath), $shellList);
     }
     return $shellList;
 }
Example #4
0
 /**
  * Gets the shell command listing.
  *
  * @return array 
  */
 protected function _getShellList()
 {
     $shellList = array();
     $shells = App::objects('file', App::core('Console/Command'));
     $shellList = $this->_appendShells('CORE', $shells, $shellList);
     $appShells = App::objects('Console/Command', null, false);
     $shellList = $this->_appendShells('app', $appShells, $shellList);
     $plugins = CakePlugin::loaded();
     foreach ($plugins as $plugin) {
         $pluginShells = App::objects($plugin . '.Console/Command');
         $shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
     }
     return $shellList;
 }
Example #5
0
 /**
  * Initialization method installs Simpletest and loads all plugins
  *
  * @return void
  * @access public
  */
 function initialize()
 {
     $corePath = App::core('cake');
     if (isset($corePath[0])) {
         define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
     } else {
         define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
     }
     $this->__installSimpleTest();
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
     require_once CAKE . 'tests' . DS . 'lib' . DS . 'cli_reporter.php';
     $plugins = App::objects('plugin');
     foreach ($plugins as $p) {
         $this->plugins[] = Inflector::underscore($p);
     }
 }
 /**
  * Gets the shell command listing.
  *
  * @return array
  */
 protected function _getShellList()
 {
     $skipFiles = array('AppShell');
     $plugins = CakePlugin::loaded();
     $shellList = array_fill_keys($plugins, null) + array('CORE' => null, 'app' => null);
     $corePath = App::core('Console/Command');
     $shells = App::objects('file', $corePath[0]);
     $shells = array_diff($shells, $skipFiles);
     $this->_appendShells('CORE', $shells, $shellList);
     $appShells = App::objects('Console/Command', null, false);
     $appShells = array_diff($appShells, $shells, $skipFiles);
     $this->_appendShells('app', $appShells, $shellList);
     foreach ($plugins as $plugin) {
         $pluginShells = App::objects($plugin . '.Console/Command');
         $this->_appendShells($plugin, $pluginShells, $shellList);
     }
     return array_filter($shellList);
 }
Example #7
0
/**
 * Find the paths to all the installed shell themes in the app.
 *
 * Bake themes are directories not named `skel` inside a `Console/Templates` path.
 * They are listed in this order: app -> plugin -> default
 *
 * @return array Array of bake themes that are installed.
 */
	protected function _findThemes() {
		$paths = App::path('Console');

		$plugins = App::objects('plugin');
		foreach ($plugins as $plugin) {
			$paths[] = $this->_pluginPath($plugin) . 'Console' . DS;
		}

		$core = current(App::core('Console'));
		$separator = DS === '/' ? '/' : '\\\\';
		$core = preg_replace('#shells' . $separator . '$#', '', $core);

		$Folder = new Folder($core . 'Templates' . DS . 'default');

		$contents = $Folder->read();
		$themeFolders = $contents[0];

		$paths[] = $core;

		foreach ($paths as $i => $path) {
			$paths[$i] = rtrim($path, DS) . DS;
		}

		$themes = array();
		foreach ($paths as $path) {
			$Folder = new Folder($path . 'Templates', false);
			$contents = $Folder->read();
			$subDirs = $contents[0];
			foreach ($subDirs as $dir) {
				if (empty($dir) || preg_match('@^skel$|_skel$@', $dir)) {
					continue;
				}
				$Folder = new Folder($path . 'Templates' . DS . $dir);
				$contents = $Folder->read();
				$subDirs = $contents[0];
				if (array_intersect($contents[0], $themeFolders)) {
					$templateDir = $path . 'Templates' . DS . $dir . DS;
					$themes[$dir] = $templateDir;
				}
			}
		}
		return $themes;
	}
Example #8
0
 protected function _getFiles($type)
 {
     $files = App::objects($type, null, false);
     $corePath = App::core($type);
     $coreFiles = App::objects($type, $corePath, false);
     $files = am($coreFiles, $files);
     //$paths = (array)App::path($type.'s');
     //$libFiles = App::objects($type, $paths[0] . 'lib' . DS, false);
     if (!isset($this->plugins)) {
         $this->plugins = App::objects('plugin');
     }
     if (!empty($this->plugins)) {
         foreach ($this->plugins as $plugin) {
             $pluginType = $plugin . '.' . $type;
             $pluginFiles = App::objects($pluginType, null, false);
             if (!empty($pluginFiles)) {
                 foreach ($pluginFiles as $t) {
                     $files[] = $t;
                 }
             }
         }
     }
     $files = array_unique($files);
     sort($files);
     $appIndex = array_search('App', $files);
     if ($appIndex !== false) {
         unset($files[$appIndex]);
     }
     # no test/tmp files etc (helper.test.php or helper.OLD.php)
     foreach ($files as $key => $file) {
         if (strpos($file, '.') !== false || !preg_match('/^[\\da-zA-Z_]+$/', $file)) {
             unset($files[$key]);
         }
     }
     return $files;
 }
 /**
  * setUp method
  *
  * @access public
  * @return void
  */
 function startTest()
 {
     $this->_get = $_GET;
     $_GET = array();
     $this->_post = $_POST;
     $this->_files = $_FILES;
     $this->_server = $_SERVER;
     $this->_app = Configure::read('App');
     Configure::write('App.base', false);
     Configure::write('App.baseUrl', false);
     Configure::write('App.dir', 'app');
     Configure::write('App.webroot', 'webroot');
     $this->_cache = Configure::read('Cache');
     Configure::write('Cache.disable', true);
     $this->_debug = Configure::read('debug');
     App::build(App::core());
 }
Example #10
0
 /**
  * Test that plugin/$plugin_name is only appended to the paths it should be.
  *
  * @return void
  */
 public function testPluginPathGeneration()
 {
     $this->Controller->plugin = 'TestPlugin';
     $this->Controller->name = 'TestPlugin';
     $this->Controller->viewPath = 'Tests';
     $this->Controller->action = 'index';
     $View = new TestView($this->Controller);
     $paths = $View->paths();
     $expected = array_merge(App::path('View'), App::core('View'), App::core('Console/Templates/skel/View'));
     $this->assertEquals($expected, $paths);
     $paths = $View->paths('TestPlugin');
     $pluginPath = CakePlugin::path('TestPlugin');
     $expected = array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS, $pluginPath . 'View' . DS, CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS, CAKE . 'View' . DS, CAKE . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'View' . DS);
     $this->assertEquals($expected, $paths);
 }
Example #11
0
 /**
  * test that a component beforeRender can change the controller view class.
  *
  * @return void
  */
 function testComponentBeforeRenderChangingViewClass()
 {
     $core = App::core('views');
     App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, $core[0])), true);
     $Controller =& new Controller();
     $Controller->uses = array();
     $Controller->components = array('Test');
     $Controller->constructClasses();
     $Controller->Test->viewclass = 'Theme';
     $Controller->viewPath = 'posts';
     $Controller->theme = 'test_theme';
     $result = $Controller->render('index');
     $this->assertPattern('/default test_theme layout/', $result);
     App::build();
 }
Example #12
0
 /**
  * Return all possible paths to find view files in order
  *
  * @param string $plugin Optional plugin name to scan for view files.
  * @param boolean $cached Set to true to force a refresh of view paths.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     if ($plugin === null && $cached === true && !empty($this->__paths)) {
         return $this->__paths;
     }
     $paths = array();
     $viewPaths = App::path('views');
     $corePaths = array_flip(App::core('views'));
     if (!empty($plugin)) {
         $count = count($viewPaths);
         for ($i = 0; $i < $count; $i++) {
             if (!isset($corePaths[$viewPaths[$i]])) {
                 $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
             }
         }
         $paths[] = App::pluginPath($plugin) . 'views' . DS;
     }
     $this->__paths = array_merge($paths, $viewPaths);
     return $this->__paths;
 }
Example #13
0
 /**
  * Loads a file from app/config/configure_file.php.
  * Config file variables should be formated like:
  *  `$config['name'] = 'value';`
  * These will be used to create dynamic Configure vars. load() is also used to 
  * load stored config files created with Configure::store()
  *
  * - To load config files from app/config use `Configure::load('configure_file');`.
  * - To load config files from a plugin `Configure::load('plugin.configure_file');`.
  *
  * @link http://book.cakephp.org/view/415/load
  * @param string $fileName name of file to load, extension must be .php and only the name
  *     should be used, not the extenstion
  * @return mixed false if file not found, void if load successful
  * @access public
  */
 public function load($fileName)
 {
     $found = $plugin = $pluginPath = false;
     list($plugin, $fileName) = pluginSplit($fileName);
     if ($plugin) {
         $pluginPath = App::pluginPath($plugin);
     }
     $pos = strpos($fileName, '..');
     if ($pos === false) {
         if ($pluginPath && file_exists($pluginPath . 'config' . DS . $fileName . '.php')) {
             include $pluginPath . 'config' . DS . $fileName . '.php';
             $found = true;
         } elseif (file_exists(CONFIGS . $fileName . '.php')) {
             include CONFIGS . $fileName . '.php';
             $found = true;
         } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
             include CACHE . 'persistent' . DS . $fileName . '.php';
             $found = true;
         } else {
             foreach (App::core('cake') as $key => $path) {
                 if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
                     include $path . DS . 'config' . DS . $fileName . '.php';
                     $found = true;
                     break;
                 }
             }
         }
     }
     if (!$found) {
         return false;
     }
     if (!isset($config)) {
         $error = __("Configure::load() - no variable \$config found in %s.php", true);
         trigger_error(sprintf($error, $fileName), E_USER_WARNING);
         return false;
     }
     return Configure::write($config);
 }
Example #14
0
 /**
  * Return all possible paths to find view files in order
  *
  * @param string $plugin Optional plugin name to scan for view files.
  * @param boolean $cached Set to true to force a refresh of view paths.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     if ($plugin === null && $cached === true && !empty($this->_paths)) {
         return $this->_paths;
     }
     $paths = array();
     $viewPaths = App::path('View');
     $corePaths = array_flip(App::core('View'));
     if (!empty($plugin)) {
         $count = count($viewPaths);
         for ($i = 0; $i < $count; $i++) {
             if (!isset($corePaths[$viewPaths[$i]])) {
                 $paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
             }
         }
         $paths = array_merge($paths, App::path('View', $plugin));
     }
     $paths = array_unique(array_merge($paths, $viewPaths, array_keys($corePaths)));
     if ($plugin !== null) {
         return $paths;
     }
     return $this->_paths = $paths;
 }
Example #15
0
 /**
  * Return all possible paths to find view files in order
  *
  * @param string $plugin Optional plugin name to scan for view files.
  * @param boolean $cached Set to true to force a refresh of view paths.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     if ($plugin === null && $cached === true && !empty($this->_paths)) {
         return $this->_paths;
     }
     $paths = array();
     $viewPaths = App::path('View');
     $corePaths = array_merge(App::core('View'), App::core('Console/Templates/skel/View'));
     if (!empty($plugin)) {
         $count = count($viewPaths);
         for ($i = 0; $i < $count; $i++) {
             if (!in_array($viewPaths[$i], $corePaths)) {
                 $paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
             }
         }
         $paths = array_merge($paths, App::path('View', $plugin));
     }
     $paths = array_unique(array_merge($paths, $viewPaths));
     // CUSTOMIZE ADD 2013/08/17 ryuring
     // >>>
     $adminThemePaths = array();
     $webroot = Configure::read('App.www_root');
     if (!empty($this->adminTheme)) {
         foreach ($paths as $path) {
             if (strpos($path, DS . 'Plugin' . DS) === false) {
                 if ($plugin) {
                     $adminThemePaths[] = $path . 'Themed' . DS . $this->adminTheme . DS . 'Plugin' . DS . $plugin . DS;
                 }
                 $adminThemePaths[] = $path . 'Themed' . DS . $this->adminTheme . DS;
             }
         }
         $adminThemePaths = array_merge(array($webroot . 'theme' . DS . $this->adminTheme . DS), $adminThemePaths);
     }
     // <<<
     if (!empty($this->theme)) {
         $themePaths = array();
         foreach ($paths as $path) {
             if (strpos($path, DS . 'Plugin' . DS) === false) {
                 if ($plugin) {
                     $themePaths[] = $path . 'Themed' . DS . $this->theme . DS . 'Plugin' . DS . $plugin . DS;
                 }
                 $themePaths[] = $path . 'Themed' . DS . $this->theme . DS;
             }
         }
         // CUSTOMIZE MODIFY 2013/08/17 ryuring
         // >>>
         //$paths = array_merge($themePaths, $paths);
         // --
         $themePaths = array_merge(array($webroot . 'theme' . DS . $this->theme . DS), $themePaths);
         $paths = array_merge($themePaths, $adminThemePaths, $paths);
         // <<<
     }
     // CUSTOMIZE ADD 2013/08/26 ryuring
     // Baserディレクトリのパスの優先順位を下げる
     // >>>
     $baserPaths = array();
     foreach ($paths as $key => $path) {
         if (strpos($path, BASER) !== false) {
             unset($paths[$key]);
             $baserPaths[] = $path;
         }
     }
     $paths = array_merge($paths, $baserPaths);
     // <<<
     $paths = array_merge($paths, $corePaths);
     if ($plugin !== null) {
         return $paths;
     }
     return $this->_paths = $paths;
 }
Example #16
0
 /**
  * Object destructor.
  *
  * Writes cache file if changes have been made to the $__map or $__paths
  *
  * @return void
  */
 public static function shutdown()
 {
     if (self::$__cache) {
         $core = App::core('cake');
         unset(self::$__paths[rtrim($core[0], DS)]);
         Cache::write('dir_map', array_filter(self::$__paths), '_cake_core_');
         Cache::write('file_map', array_filter(self::$__map), '_cake_core_');
         Cache::write('object_map', self::$__objects, '_cake_core_');
     }
 }
Example #17
0
 /**
  * test that plugin/$plugin_name is only appended to the paths it should be.
  *
  * @return void
  */
 public function testPluginPathGeneration()
 {
     $this->Controller->plugin = 'TestPlugin';
     $this->Controller->name = 'TestPlugin';
     $this->Controller->viewPath = 'Tests';
     $this->Controller->action = 'index';
     $View = new TestView($this->Controller);
     $paths = $View->paths();
     $expected = array_merge(App::path('View'), App::core('View'));
     $this->assertEqual($paths, $expected);
     $paths = $View->paths('TestPlugin');
     $pluginPath = CakePlugin::path('TestPlugin');
     $expected = array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugins' . DS . 'TestPlugin' . DS, $pluginPath . 'View' . DS, $pluginPath . 'views' . DS, $pluginPath . 'Lib' . DS . 'View' . DS, CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS, CAKE . 'View' . DS);
     $this->assertEqual($paths, $expected);
 }
Example #18
0
 /**
  * testCore method
  *
  * @access public
  * @return void
  * @todo fix test cases to pass when webroot is outside normal package directory structure
  */
 function testCore()
 {
     if (!$this->skipif(true, 'ConfigureTest::testCore() does not pass when webroot is outside normal package directory structure')) {
         return true;
     }
     $model = App::core('models');
     $this->assertEqual(array(ROOT . DS . LIBS . 'model' . DS), $model);
     $view = App::core('views');
     $this->assertEqual(array(ROOT . DS . LIBS . 'view' . DS), $view);
     $controller = App::core('controllers');
     $this->assertEqual(array(ROOT . DS . LIBS . 'controller' . DS), $controller);
 }
Example #19
0
/**
 * Update the properties moved to CakeRequest.
 *
 * @return void
 */
	public function request() {
		$views = array_diff(App::path('views'), App::core('views'));
		$controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP));
		$components = array_diff(App::path('components'), App::core('components'));

		$this->_paths = array_merge($views, $controllers, $components);

		if (!empty($this->params['plugin'])) {
			$pluginPath = App::pluginPath($this->params['plugin']);
			$this->_paths = array(
				$pluginPath . 'controllers' . DS,
				$pluginPath . 'controllers' . DS . 'components' .DS,
				$pluginPath . 'views' . DS,
			);
		}
		$patterns = array(
			array(
				'$this->data -> $this->request->data',
				'/(\$this->data\b(?!\())/',
				'$this->request->data'
			),
			array(
				'$this->params -> $this->request->params',
				'/(\$this->params\b(?!\())/',
				'$this->request->params'
			),
			array(
				'$this->webroot -> $this->request->webroot',
				'/(\$this->webroot\b(?!\())/',
				'$this->request->webroot'
			),
			array(
				'$this->base -> $this->request->base',
				'/(\$this->base\b(?!\())/',
				'$this->request->base'
			),
			array(
				'$this->here -> $this->request->here',
				'/(\$this->here\b(?!\())/',
				'$this->request->here'
			),
			array(
				'$this->action -> $this->request->action',
				'/(\$this->action\b(?!\())/',
				'$this->request->action'
			),
		);
		$this->_filesRegexpUpdate($patterns);
	}
Example #20
0
 /**
  * testListObjects method
  *
  * @return void
  */
 public function testListObjects()
 {
     $result = App::objects('class', CAKE . 'Routing', false);
     $this->assertTrue(in_array('Dispatcher', $result));
     $this->assertTrue(in_array('Router', $result));
     App::build(array('Model/Behavior' => App::core('Model/Behavior'), 'Controller' => App::core('Controller'), 'Controller/Component' => App::core('Controller/Component'), 'View' => App::core('View'), 'Model' => App::core('Model'), 'View/Helper' => App::core('View/Helper')), App::RESET);
     $result = App::objects('behavior', null, false);
     $this->assertTrue(in_array('TreeBehavior', $result));
     $result = App::objects('Model/Behavior', null, false);
     $this->assertTrue(in_array('TreeBehavior', $result));
     $result = App::objects('controller', null, false);
     $this->assertTrue(in_array('PagesController', $result));
     $result = App::objects('Controller', null, false);
     $this->assertTrue(in_array('PagesController', $result));
     $result = App::objects('component', null, false);
     $this->assertTrue(in_array('AuthComponent', $result));
     $result = App::objects('Controller/Component', null, false);
     $this->assertTrue(in_array('AuthComponent', $result));
     $result = App::objects('view', null, false);
     $this->assertTrue(in_array('MediaView', $result));
     $result = App::objects('View', null, false);
     $this->assertTrue(in_array('MediaView', $result));
     $result = App::objects('helper', null, false);
     $this->assertTrue(in_array('HtmlHelper', $result));
     $result = App::objects('View/Helper', null, false);
     $this->assertTrue(in_array('HtmlHelper', $result));
     $result = App::objects('model', null, false);
     $this->assertTrue(in_array('AcoAction', $result));
     $result = App::objects('Model', null, false);
     $this->assertTrue(in_array('AcoAction', $result));
     $result = App::objects('file');
     $this->assertFalse($result);
     $result = App::objects('file', 'non_existing_configure');
     $expected = array();
     $this->assertEquals($expected, $result);
     $result = App::objects('NonExistingType');
     $this->assertEquals($result, array());
     App::build(array('plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS)));
     $result = App::objects('plugin', null, false);
     $this->assertTrue(in_array('Cache', $result));
     $this->assertTrue(in_array('Log', $result));
     App::build();
 }
Example #21
0
 /**
  * Shortens file paths by replacing the application base path with 'APP', and the CakePHP core
  * path with 'CORE'.
  *
  * @param string $path Path to shorten
  * @return string Normalized path
  * @access public
  * @static
  */
 function trimPath($path)
 {
     if (!defined('CAKE_CORE_INCLUDE_PATH') || !defined('APP')) {
         return $path;
     }
     if (strpos($path, APP) === 0) {
         return str_replace(APP, 'APP' . DS, $path);
     } elseif (strpos($path, CAKE_CORE_INCLUDE_PATH) === 0) {
         return str_replace(CAKE_CORE_INCLUDE_PATH, 'CORE', $path);
     } elseif (strpos($path, ROOT) === 0) {
         return str_replace(ROOT, 'ROOT', $path);
     }
     $corePaths = App::core('cake');
     foreach ($corePaths as $corePath) {
         if (strpos($path, $corePath) === 0) {
             return str_replace($corePath, 'CORE' . DS . 'cake' . DS, $path);
         }
     }
     return $path;
 }
 /**
  * Replace cakeError with built-in exceptions.
  * NOTE: this ignores calls where you've passed your own secondary parameters to cakeError().
  * @return void
  */
 public function exceptions()
 {
     $controllers = array_diff(App::path('controllers'), App::core('controllers'), array(APP));
     $components = array_diff(App::path('components'), App::core('components'));
     $this->_paths = array_merge($controllers, $components);
     if (!empty($this->params['plugin'])) {
         $pluginPath = App::pluginPath($this->params['plugin']);
         $this->_paths = array($pluginPath . 'controllers' . DS, $pluginPath . 'controllers' . DS . 'components' . DS);
     }
     $patterns = array(array('$this->cakeError("error400") -> throw new BadRequestException()', '/(\\$this->cakeError\\(["\']error400["\']\\));/', 'throw new BadRequestException();'), array('$this->cakeError("error404") -> throw new NotFoundException()', '/(\\$this->cakeError\\(["\']error404["\']\\));/', 'throw new NotFoundException();'), array('$this->cakeError("error500") -> throw new InternalErrorException()', '/(\\$this->cakeError\\(["\']error500["\']\\));/', 'throw new InternalErrorException();'));
     $this->_filesRegexpUpdate($patterns);
 }
Example #23
0
 /**
  * Return all possible paths to find view files in order
  *
  * @param string $plugin Optional plugin name to scan for view files.
  * @param boolean $cached Set to true to force a refresh of view paths.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     if ($plugin === null && $cached === true && !empty($this->_paths)) {
         return $this->_paths;
     }
     $paths = array();
     $viewPaths = App::path('View');
     $corePaths = array_merge(App::core('View'), App::core('Console/Templates/skel/View'));
     if (!empty($plugin)) {
         $count = count($viewPaths);
         for ($i = 0; $i < $count; $i++) {
             if (!in_array($viewPaths[$i], $corePaths)) {
                 $paths[] = $viewPaths[$i] . 'Plugin' . DS . $plugin . DS;
             }
         }
         $paths = array_merge($paths, App::path('View', $plugin));
     }
     $paths = array_unique(array_merge($paths, $viewPaths));
     if (!empty($this->theme)) {
         $theme = Inflector::camelize($this->theme);
         $themePaths = array();
         foreach ($paths as $path) {
             if (strpos($path, DS . 'Plugin' . DS) === false) {
                 if ($plugin) {
                     $themePaths[] = $path . 'Themed' . DS . $theme . DS . 'Plugin' . DS . $plugin . DS;
                 }
                 $themePaths[] = $path . 'Themed' . DS . $theme . DS;
             }
         }
         $paths = array_merge($themePaths, $paths);
     }
     $paths = array_merge($paths, $corePaths);
     if ($plugin !== null) {
         return $paths;
     }
     return $this->_paths = $paths;
 }
Example #24
0
 /**
  * Looks for fixture files and instantiates the classes accordingly
  *
  * @param array $fixtures the fixture names to load using the notation {type}.{name}
  * @return void
  */
 protected function _loadFixtures($fixtures)
 {
     foreach ($fixtures as $index => $fixture) {
         $fixtureFile = null;
         $fixtureIndex = $fixture;
         if (isset($this->_loaded[$fixture])) {
             continue;
         }
         if (strpos($fixture, 'core.') === 0) {
             $fixture = substr($fixture, strlen('core.'));
             foreach (App::core('cake') as $key => $path) {
                 $fixturePaths[] = $path . 'tests' . DS . 'fixtures';
             }
         } elseif (strpos($fixture, 'app.') === 0) {
             $fixture = substr($fixture, strlen('app.'));
             $fixturePaths = array(TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures');
         } elseif (strpos($fixture, 'plugin.') === 0) {
             $parts = explode('.', $fixture, 3);
             $pluginName = $parts[1];
             $fixture = $parts[2];
             $fixturePaths = array(App::pluginPath($pluginName) . 'tests' . DS . 'fixtures', TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures');
         } else {
             $fixturePaths = array(TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures', TEST_CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures');
         }
         foreach ($fixturePaths as $path) {
             if (is_readable($path . DS . $fixture . '_fixture.php')) {
                 $fixtureFile = $path . DS . $fixture . '_fixture.php';
                 break;
             }
         }
         if (isset($fixtureFile)) {
             require_once $fixtureFile;
             $fixtureClass = Inflector::camelize($fixture) . 'Fixture';
             $this->_loaded[$fixtureIndex] = new $fixtureClass($this->_db);
             $this->_fixtureMap[$fixtureClass] = $this->_loaded[$fixtureIndex];
         }
     }
 }
Example #25
0
if (!defined('WWW_ROOT')) {
	define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
	if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
		define('APP_PATH', null);
		define('CORE_PATH', null);
	} else {
		define('APP_PATH', ROOT . DS . APP_DIR . DS);
		define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
	}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
	trigger_error("CakePHP core could not be found.  Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php.  It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}

$corePath = App::core('cake');
if (isset($corePath[0])) {
	define('TEST_CAKE_CORE_INCLUDE_PATH', rtrim($corePath[0], DS) . DS);
} else {
	define('TEST_CAKE_CORE_INCLUDE_PATH', CAKE_CORE_INCLUDE_PATH);
}

if (Configure::read('debug') < 1) {
	die(__('Debug setting does not allow access to this url.', true));
}

require_once CAKE_TESTS_LIB . 'cake_test_suite_dispatcher.php';

$Dispatcher = new CakeTestSuiteDispatcher();
$Dispatcher->dispatch();
Example #26
0
 /**
  * Tries to find and include a file for a cache engine and returns object instance
  *
  * @param $name Name of the engine (without 'Engine')
  * @return mixed $engine object or null
  * @access private
  */
 function __loadEngine($name, $plugin = null)
 {
     if ($plugin) {
         return App::import('Lib', $plugin . '.cache' . DS . $name, false);
     } else {
         $core = App::core();
         $path = $core['libs'][0] . 'cache' . DS . strtolower($name) . '.php';
         if (file_exists($path)) {
             require $path;
             return true;
         }
         return App::import('Lib', 'cache' . DS . $name, false);
     }
 }
Example #27
0
 /**
  * Gets the option parser instance and configures it.
  *
  * @return ConsoleOptionParser
  */
 public function getOptionParser()
 {
     $parser = parent::getOptionParser();
     $parser->description(__d('cake_console', 'Generate a new CakePHP project skeleton.'))->addArgument('name', array('help' => __d('cake_console', 'Application directory to make, if it starts with "/" the path is absolute.')))->addOption('empty', array('boolean' => true, 'help' => __d('cake_console', 'Create empty files in each of the directories. Good if you are using git')))->addOption('theme', array('short' => 't', 'help' => __d('cake_console', 'Theme to use when baking code.')))->addOption('skel', array('default' => current(App::core('Console')) . 'Templates' . DS . 'skel', 'help' => __d('cake_console', 'The directory layout to use for the new application skeleton.' . ' Defaults to cake/Console/Templates/skel of CakePHP used to create the project.')));
     return $parser;
 }
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @param string $project Project path
  */
 public function execute()
 {
     $project = null;
     if (isset($this->args[0])) {
         $project = $this->args[0];
     }
     if ($project && isset($_SERVER['PWD'])) {
         $project = $_SERVER['PWD'] . DS . $project;
     }
     if (empty($this->params['skel'])) {
         $core = App::core('shells');
         $skelPath = dirname($core[0]) . DS . 'templates' . DS . 'skel';
         if (is_dir($skelPath) === true) {
             $this->params['skel'] = $skelPath;
         }
     }
     while (!$project) {
         $prompt = __("What is the full path for this app including the app directory name?\n Example:");
         $default = APP_PATH . 'myapp';
         $project = $this->in($prompt . $default, null, $default);
     }
     if ($project) {
         $response = false;
         while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
             $prompt = __('<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
             $response = $this->in($prompt, array('y', 'n'), 'n');
             if (strtolower($response) === 'n') {
                 $response = $project = false;
             }
         }
     }
     $success = true;
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->createHome($path)) {
             $this->out(__(' * Welcome page created'));
         } else {
             $this->err(__('The Welcome page was <error>NOT</error> created'));
             $success = false;
         }
         if ($this->securitySalt($path) === true) {
             $this->out(__(' * Random hash key created for \'Security.salt\''));
         } else {
             $this->err(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', CONFIGS . 'core.php'));
             $success = false;
         }
         if ($this->securityCipherSeed($path) === true) {
             $this->out(__(' * Random seed created for \'Security.cipherSeed\''));
         } else {
             $this->err(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', CONFIGS . 'core.php'));
             $success = false;
         }
         if ($this->corePath($path) === true) {
             $this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
             $this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
             $this->out(__('   * <warning>Remember to check these value after moving to production server</warning>'));
         } else {
             $this->err(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' . DS . 'index.php'));
             $success = false;
         }
         if ($this->consolePath($path) === true) {
             $this->out(__(' * app/console/cake.php path set.'));
         } else {
             $this->err(__('Unable to set console path for app/console.'));
             $success = false;
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(__('Could not set permissions on %s', $path . DS . 'tmp'));
             $this->out(__('chmod -R 0777 %s', $path . DS . 'tmp'));
             $success = false;
         }
         if ($success) {
             $this->out(__('<success>Project baked successfully!</success>'));
         } else {
             $this->out(__('Project baked but with <warning>some issues.</warning>.'));
         }
         return $path;
     }
 }
Example #29
0
 /**
  * Load fixtures specified in var $fixtures.
  *
  * @return void
  * @access protected
  */
 function _loadFixtures()
 {
     if (!isset($this->fixtures) || empty($this->fixtures)) {
         return;
     }
     if (!is_array($this->fixtures)) {
         $this->fixtures = array_map('trim', explode(',', $this->fixtures));
     }
     $this->_fixtures = array();
     foreach ($this->fixtures as $index => $fixture) {
         $fixtureFile = null;
         if (strpos($fixture, 'core.') === 0) {
             $fixture = substr($fixture, strlen('core.'));
             foreach (App::core('cake') as $key => $path) {
                 $fixturePaths[] = $path . 'tests' . DS . 'fixtures';
             }
         } elseif (strpos($fixture, 'app.') === 0) {
             $fixture = substr($fixture, strlen('app.'));
             $fixturePaths = array(TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures');
         } elseif (strpos($fixture, 'plugin.') === 0) {
             $parts = explode('.', $fixture, 3);
             $pluginName = $parts[1];
             $fixture = $parts[2];
             $fixturePaths = array(App::pluginPath($pluginName) . 'tests' . DS . 'fixtures', TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures');
         } else {
             $fixturePaths = array(TESTS . 'fixtures', VENDORS . 'tests' . DS . 'fixtures', TEST_CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures');
         }
         foreach ($fixturePaths as $path) {
             if (is_readable($path . DS . $fixture . '_fixture.php')) {
                 $fixtureFile = $path . DS . $fixture . '_fixture.php';
                 break;
             }
         }
         if (isset($fixtureFile)) {
             require_once $fixtureFile;
             $fixtureClass = Inflector::camelize($fixture) . 'Fixture';
             $this->_fixtures[$this->fixtures[$index]] =& new $fixtureClass($this->db);
             $this->_fixtureClassMap[Inflector::camelize($fixture)] = $this->fixtures[$index];
         }
     }
     if (empty($this->_fixtures)) {
         unset($this->_fixtures);
     }
 }
Example #30
0
 /**
  * Object destructor.
  *
  * Writes cache file if changes have been made to the $__map or $__paths
  *
  * @return void
  * @access private
  */
 function __destruct()
 {
     if ($this->__resetCache() === true) {
         $core = App::core('cake');
         unset($this->__paths[rtrim($core[0], DS)]);
         Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
         Cache::write('file_map', array_filter($this->__map), '_cake_core_');
         Cache::write('object_map', $this->__objects, '_cake_core_');
     }
 }