Exemplo n.º 1
0
 /**
  * Get template data.
  *
  * @return array
  */
 public function templateData()
 {
     $namespace = Configure::read('App.namespace');
     if ($this->plugin) {
         $namespace = Plugin::getNamespace($this->plugin);
     }
     return ['namespace' => $namespace];
 }
Exemplo n.º 2
0
 /**
  * Return the classname namespaced. This method checks if the class is defined on the
  * application/plugin, otherwise try to load from the CakePHP core
  *
  * @param string $class Classname
  * @param string $type Type of class
  * @param string $suffix Classname suffix
  * @return bool|string False if the class is not found or namespaced classname
  */
 public static function classname($class, $type = '', $suffix = '')
 {
     if (strpos($class, '\\') !== false) {
         return $class;
     }
     list($plugin, $name) = pluginSplit($class);
     if ($plugin) {
         $base = Plugin::getNamespace($plugin);
     } else {
         $base = Configure::read('App.namespace');
     }
     $base = rtrim($base, '\\');
     $fullname = '\\' . str_replace('/', '\\', $type . '\\' . $name) . $suffix;
     if (static::_classExistsInBase($fullname, $base)) {
         return $base . $fullname;
     }
     if ($plugin) {
         return false;
     }
     if (static::_classExistsInBase($fullname, 'Cake')) {
         return 'Cake' . $fullname;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Test that plugins don't reload using loadAll();
  *
  * @return void
  */
 public function testLoadAllWithPluginAlreadyLoaded()
 {
     Plugin::load('PluginJs', ['namespace' => 'Company\\TestPluginJs']);
     Plugin::loadAll();
     $this->assertEquals('Company\\TestPluginJs', Plugin::getNamespace('PluginJs'));
 }
Exemplo n.º 4
0
 /**
  * Looks for fixture files and instantiates the classes accordingly
  *
  * @param \Cake\TestSuite\Testcase $test The test suite to load fixtures for.
  * @return void
  * @throws \UnexpectedValueException when a referenced fixture does not exist.
  */
 protected function _loadFixtures($test)
 {
     if (empty($test->fixtures)) {
         return;
     }
     foreach ($test->fixtures as $fixture) {
         if (isset($this->_loaded[$fixture])) {
             continue;
         }
         list($type, $pathName) = explode('.', $fixture, 2);
         $path = explode('/', $pathName);
         $name = array_pop($path);
         $additionalPath = implode('\\', $path);
         if ($type === 'core') {
             $baseNamespace = 'Cake';
         } elseif ($type === 'app') {
             $baseNamespace = Configure::read('App.namespace');
         } elseif ($type === 'plugin') {
             if (strlen($additionalPath)) {
                 list($plugin, $additionalPath) = explode('.', $additionalPath);
             } else {
                 list($plugin, $name) = explode('.', $name);
             }
             $baseNamespace = Plugin::getNamespace(Inflector::camelize($plugin));
         } else {
             $name = $fixture;
         }
         $name = Inflector::camelize($name);
         $nameSegments = [$baseNamespace, 'Test\\Fixture', $additionalPath, $name . 'Fixture'];
         $className = implode('\\', array_filter($nameSegments));
         if (class_exists($className)) {
             $this->_loaded[$fixture] = new $className();
             $this->_fixtureMap[$name] = $this->_loaded[$fixture];
         } else {
             $msg = sprintf('Referenced fixture class "%s" not found. Fixture "%s" was referenced in test case "%s".', $className, $fixture, get_class($test));
             throw new \UnexpectedValueException($msg);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Locate the tasks bake will use.
  *
  * Scans the following paths for tasks that are subclasses of
  * Cake\Console\Command\Task\BakeTask:
  *
  * - Cake/Console/Command/Task/
  * - App/Console/Command/Task/
  * - Console/Command/Task for each loaded plugin
  *
  * @return void
  */
 public function loadTasks()
 {
     $tasks = [];
     $tasks = $this->_findTasks($tasks, CAKE, 'Cake');
     $tasks = $this->_findTasks($tasks, APP, Configure::read('App.namespace'));
     foreach (Plugin::loaded() as $plugin) {
         $tasks = $this->_findTasks($tasks, Plugin::path($plugin), Plugin::getNamespace($plugin), $plugin);
     }
     $this->tasks = array_values($tasks);
     parent::loadTasks();
 }
Exemplo n.º 6
0
 /**
  * Make the filename for the test case. resolve the suffixes for controllers
  * and get the plugin path if needed.
  *
  * @param string $type The Type of object you are generating tests for eg. controller
  * @param string $className The fully qualified classname of the class the test is being generated for.
  * @return string filename the test should be created on.
  */
 public function testCaseFileName($type, $className)
 {
     $path = $this->getPath();
     $namespace = Configure::read('App.namespace');
     if ($this->plugin) {
         $namespace = Plugin::getNamespace($this->plugin);
     }
     $classTail = substr($className, strlen($namespace) + 1);
     $path = $path . $classTail . 'Test.php';
     return str_replace(['/', '\\'], DS, $path);
 }