Exemplo n.º 1
0
 /**
  * Runs the drop and create commands on the fixtures if necessary.
  *
  * @param CakeTestFixture $fixture the fixture object to create
  * @param DataSource $db the datasource instance to use
  * @param boolean $drop whether drop the fixture if it is already created or not
  * @return void
  */
 protected function _setupTable($fixture, $db = null, $drop = true)
 {
     if (!$db) {
         if (!empty($fixture->useDbConfig)) {
             $db = ClassRegistry::getDataSource($fixture->useDbConfig);
         } else {
             $db = $this->_db;
         }
     }
     if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) {
         return;
     }
     $sources = $db->listSources();
     $table = $db->config['prefix'] . $fixture->table;
     if ($drop && in_array($table, $sources)) {
         $fixture->drop($db);
         $fixture->create($db);
     } elseif (!in_array($table, $sources)) {
         $fixture->create($db);
     }
 }
Exemplo n.º 2
0
 /**
  * @brief get the fixtures
  *
  * This method will first get any required fixtures from events for plugins
  * that need to load up fixtures regardless. Any fixtures you have specifically
  * loaded will then be setup. After that any fixtures for the model that is being
  * tested will be loaded and all dependencies that are found. Finally any
  * replacements that you need doing are done.
  *
  * replacements:
  *	you can replace the default fixture that is loaded automatically with
  *	your own. too do this you just pass the array with (oldfixture => newfixture).
  *	this is used when you need to load up your own data instead of some core
  *	data for example.
  *
  * @access public
  *
  * @param string $model the model that is being loaded
  * @param bool $load true will insert data, false will only load up fixtures
  *
  * @return void
  */
 public function getFixtures($model = null, $load = false)
 {
     $this->fixturesFromEvents();
     $this->getRequestsedFixtures();
     if ($model) {
         $this->fixturesForModel($model);
     }
     $this->getRequestsedFixtures('replace');
     $CakeTestFixture = new CakeTestFixture();
     $CakeTestFixture->drop($this->__testObject->db);
     $this->loadFixtures($this->__fixturesToLoad, $load);
 }
Exemplo n.º 3
0
 /**
  * Runs the drop and create commands on the fixtures if necessary
  *
  * @param CakeTestFixture $fixture the fixture object to create
  * @param DataSource $db the datasource instance to use
  * @param boolean $drop whether drop the fixture if it is already created or not
  * @return void
  */
 protected function _setupTable($fixture, $db = null, $drop = true)
 {
     if (!$db) {
         $db = $this->_db;
     }
     if (!empty($fixture->created) && $fixture->created == $db->configKeyName) {
         return;
     }
     $cacheSources = $db->cacheSources;
     $db->cacheSources = false;
     $sources = $db->listSources();
     $db->cacheSources = $cacheSources;
     $table = $db->config['prefix'] . $fixture->table;
     if ($drop && in_array($table, $sources)) {
         $fixture->drop($db);
         $fixture->create($db);
         $fixture->created = $db->configKeyName;
     } elseif (!in_array($table, $sources)) {
         $fixture->create($db);
         $fixture->created = $db->configKeyName;
     }
 }
Exemplo n.º 4
0
 /**
  * Runs the drop and create commands on the fixtures if necessary.
  *
  * @param CakeTestFixture $fixture the fixture object to create
  * @param DataSource $db the datasource instance to use
  * @param bool $drop whether drop the fixture if it is already created or not
  * @return void
  */
 protected function _setupTable($fixture, $db = null, $drop = true)
 {
     if (!$db) {
         if (!empty($fixture->useDbConfig)) {
             $db = ConnectionManager::getDataSource($fixture->useDbConfig);
         } else {
             $db = $this->_db;
         }
     }
     if (!empty($fixture->created) && in_array($db->configKeyName, $fixture->created)) {
         return;
     }
     $sources = (array) $db->listSources();
     $table = $db->config['prefix'] . $fixture->table;
     $exists = in_array($table, $sources);
     if ($drop && $exists) {
         $fixture->drop($db);
         $fixture->create($db);
     } elseif (!$exists) {
         $fixture->create($db);
     } else {
         $fixture->created[] = $db->configKeyName;
     }
 }
 /**
  * Drops the table from the test datasource
  *
  * @param DboSource $db
  * @return void
  */
 public function drop($db)
 {
     unset(static::$_tableHashes[$this->table]);
     return parent::drop($db);
 }