Ejemplo n.º 1
0
 /**
  * Loads "reference fixtures" defined in {@link referenceFixtures()} and
  * sets up some special environment variables before proceeding.
  */
 public static function setUpBeforeClass()
 {
     if (!YII_UNIT_TESTING) {
         throw new CException('YII_UNIT_TESTING must be set to true');
     }
     Yii::app()->cache->flush();
     self::setUpAppEnvironment();
     // Load "reference fixtures", needed for reference, which do not need
     // to be reloaded after every single test method:
     $testClass = get_called_class();
     if (X2_TEST_DEBUG_LEVEL > 0) {
         /**/
         println($testClass);
     }
     $refFix = call_user_func("{$testClass}::referenceFixtures");
     $fm = Yii::app()->getComponent('fixture');
     self::$_referenceFixtureRows = array();
     self::$_referenceFixtureRecords = array();
     if (is_array($refFix)) {
         Yii::import('application.components.X2Settings.*');
         $fm->load($refFix);
         if (self::$loadFixtures || self::$loadFixturesForClassOnly) {
             foreach ($refFix as $alias => $table) {
                 $tableName = is_array($table) ? $table[0] : $table;
                 self::$_referenceFixtureRows[$alias] = $fm->getRows($alias);
                 if (strpos($tableName, ':') !== 0) {
                     foreach (self::$_referenceFixtureRows[$alias] as $rowAlias => $row) {
                         $model = CActiveRecord::model($tableName);
                         $key = $model->getTableSchema()->primaryKey;
                         if (is_string($key)) {
                             $pk = $row[$key];
                         } else {
                             foreach ($key as $k) {
                                 $pk[$k] = $row[$k];
                             }
                         }
                         self::$_referenceFixtureRecords[$alias][$rowAlias] = $model->findByPk($pk);
                     }
                 }
             }
         }
     }
     self::setUpAppEnvironment2();
     parent::setUpBeforeClass();
 }