示例#1
0
 public function init()
 {
     parent::init();
     // 1. Not all fixtures want to use the dev db.
     if (is_null($this->tableName)) {
         return;
     }
     // 2. We need to do this to ensure that the tables really do use the connection to the
     // dev db.
     TableRegistry::remove($this->tableName);
     $table = TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('dev')]);
     //if(!is_null($this->joinTableName)) {
     //TableRegistry::remove($this->joinTableName);
     //$n=TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('fixture')]);
     //}
     // 3. Now build the query to retrieve the source records
     $query = new Query(ConnectionManager::get('dev'), $table);
     $query->find('all');
     //if(!is_null($this->order)) $query->order($this->order);
     //if(!is_null($this->joinTableName)) $query->leftJoin($this->joinTableName,'semesters.id = sections.semester_id');
     //$c=$query->count();
     // 4. Copy the records
     /* @var \Cake\ORM\Entity $record */
     foreach ($query as $record) {
         $this->records[] = $record->toArray();
     }
     // 5. Do this again to ensure that the table uses the 'test' connection.
     TableRegistry::remove($this->tableName);
     TableRegistry::get($this->tableName, ['connection' => ConnectionManager::get('test')]);
     //if(!is_null($this->joinTableName)) {
     //TableRegistry::remove($this->joinTableName);
     //TableRegistry::get($this->joinTableName, ['connection' => ConnectionManager::get('test')]);
     //}
 }
 /**
  * tearDown() method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     ini_set('intl.default_locale', $this->default_locale);
     unset($this->Items);
     TableRegistry::remove('Items');
 }
示例#3
0
 /**
  * Override startup of the Shell
  *
  * @return void
  */
 public function startup()
 {
     parent::startup();
     if (isset($this->params['connection'])) {
         $this->connection = $this->params['connection'];
     }
     $class = Configure::read('Acl.classname');
     $className = App::classname('Acl.' . $class, 'Adapter');
     if ($class !== 'DbAcl' && !is_subclass_of($className, 'Acl\\Adapter\\DbAcl')) {
         $out = "--------------------------------------------------\n";
         $out .= __d('cake_acl', 'Error: Your current CakePHP configuration is set to an ACL implementation other than DB.') . "\n";
         $out .= __d('cake_acl', 'Please change your core config to reflect your decision to use DbAcl before attempting to use this script') . "\n";
         $out .= "--------------------------------------------------\n";
         $out .= __d('cake_acl', 'Current ACL Classname: {0}', [$class]) . "\n";
         $out .= "--------------------------------------------------\n";
         $this->err($out);
         return $this->_stop();
     }
     if ($this->command) {
         if (Configure::check('Datasource') === null) {
             $this->out(__d('cake_acl', 'Your database configuration was not found. Take a moment to create one.'));
             $this->args = null;
             return $this->DbConfig->execute();
         }
         try {
             \Cake\ORM\TableRegistry::get('Aros')->schema();
             \Cake\ORM\TableRegistry::remove('Aros');
         } catch (\Cake\Database\Exception $e) {
             $this->out(__d('cake_acl', 'Acl database tables not found. To create them, run:'));
             $this->out();
             $this->out('  bin/cake Migrations.migrations migrate -p Acl');
             $this->out();
             return $this->_stop();
         }
         $registry = new ComponentRegistry();
         $this->Acl = new AclComponent($registry);
         $controller = new Controller();
     }
 }
 public function tearDown()
 {
     TableRegistry::remove('Messages');
     TableRegistry::remove('Threads');
     TableRegistry::remove('MessageReadStatuses');
 }
 /**
  * Tests remove an instance
  *
  * @return void
  */
 public function testRemove()
 {
     Plugin::load('TestPlugin');
     $pluginTable = TableRegistry::get('TestPlugin.Comments');
     $cachedTable = TableRegistry::get('Comments');
     $this->assertTrue(TableRegistry::exists('Comments'));
     $this->assertSame($pluginTable, $cachedTable);
     TableRegistry::remove('Comments');
     $this->assertFalse(TableRegistry::exists('Comments'));
     $appTable = TableRegistry::get('Comments');
     $this->assertTrue(TableRegistry::exists('Comments'));
     $this->assertNotSame($pluginTable, $appTable);
 }
 /**
  * testRemovePlugin
  *
  * Removing a plugin-prefixed model should not affect any other
  * plugin-prefixed model, or app model.
  * Removing an app model should not affect any other
  * plugin-prefixed model.
  *
  * @return void
  */
 public function testRemovePlugin()
 {
     Plugin::load('TestPlugin');
     Plugin::load('TestPluginTwo');
     $app = TableRegistry::get('Comments');
     TableRegistry::get('TestPlugin.Comments');
     $plugin = TableRegistry::get('TestPluginTwo.Comments');
     $this->assertTrue(TableRegistry::exists('Comments'));
     $this->assertTrue(TableRegistry::exists('TestPlugin.Comments'));
     $this->assertTrue(TableRegistry::exists('TestPluginTwo.Comments'));
     TableRegistry::remove('TestPlugin.Comments');
     $this->assertTrue(TableRegistry::exists('Comments'));
     $this->assertFalse(TableRegistry::exists('TestPlugin.Comments'));
     $this->assertTrue(TableRegistry::exists('TestPluginTwo.Comments'));
     $app2 = TableRegistry::get('Comments');
     $plugin2 = TableRegistry::get('TestPluginTwo.Comments');
     $this->assertSame($app, $app2, 'Should be the same Comments object');
     $this->assertSame($plugin, $plugin2, 'Should be the same TestPluginTwo.Comments object');
     TableRegistry::remove('Comments');
     $this->assertFalse(TableRegistry::exists('Comments'));
     $this->assertFalse(TableRegistry::exists('TestPlugin.Comments'));
     $this->assertTrue(TableRegistry::exists('TestPluginTwo.Comments'));
     $plugin3 = TableRegistry::get('TestPluginTwo.Comments');
     $this->assertSame($plugin, $plugin3, 'Should be the same TestPluginTwo.Comments object');
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     unset($this->News);
     TableRegistry::remove('CkTools.News');
     parent::tearDown();
 }
 /**
  * Vrátí tabulky s chováním, které se mají indexovat
  * Return tables with behavior which should be indexed
  *
  *
  * @param bool $indexedByName Pass true if names should be returned instead of Tables
  *
  * @return array
  */
 public function getAttachedTables($indexedByName = false)
 {
     $modelPath = 'Model' . DS . 'Table';
     $modelPath = APP . $modelPath;
     $tables = [];
     foreach ((new Folder($modelPath))->find('.*.php') as $file) {
         $table = str_replace('Table.php', '', $file);
         if (TableRegistry::exists($table)) {
             TableRegistry::remove($table);
         }
         $tableTable = TableRegistry::get($table, ['options' => ['skipSimilarInitialize' => true]]);
         if ($tableTable->hasBehavior('InRelatedIndex')) {
             if ($indexedByName) {
                 $tables[$table] = $tableTable;
             } else {
                 $tables[] = $tableTable;
             }
         }
     }
     return $tables;
 }
 /**
  * Test the remove() method.
  *
  * @return void
  */
 public function testRemove()
 {
     $locator = $this->_setMockLocator();
     $locator->expects($this->once())->method('remove')->with('Test');
     TableRegistry::remove('Test');
 }