Ejemplo n.º 1
0
 public function setUp()
 {
     DatabaseService::configProfile(array('user' => 'root', 'pass' => 'root'));
     $DBName = 'solve_test_database';
     DBOperator::getInstance()->createDB($DBName)->useDB($DBName);
     QC::executeSQL('DROP TABLE IF EXISTS users');
     DBOperator::getInstance()->createTable('users', array('table' => 'users', 'columns' => array('id' => array('type' => 'int(11) unsigned', 'auto_increment' => true), 'position' => 'varchar(255)', 'age' => 'tinyint(1) unsigned', 'name' => 'varchar(255)'), 'indexes' => array('id' => array('type' => 'primary', 'columns' => 'id'))));
     QC::executeSQL('TRUNCATE `users`');
 }
Ejemplo n.º 2
0
 public function testBasic()
 {
     $mo = ModelOperator::getInstance(self::$_storagePath);
     $this->assertEmpty($mo->getModelStructure('User'), 'Empty structure returns array()');
     $mo->generateBasicStructure('User');
     $data = $mo->getModelStructure('User');
     $this->assertEquals(array('table' => 'users', 'columns' => array('id' => array('type' => 'int(11) unsigned', 'auto_increment' => true), 'title' => array('type' => 'varchar(255)')), 'indexes' => array('primary' => array('columns' => array('id')))), $data, 'Basic structure generator is ok');
     $mo->saveModelStructure('User');
     $this->assertFileExists(self::$_storagePath . 'structure/User.yml', 'Save model structure is ok');
     $mo->generateModelClass('User');
     require_once __DIR__ . '/storage/bases/BaseUser.php';
     require_once __DIR__ . '/storage/classes/User.php';
     $this->assertFileExists(self::$_storagePath . 'bases/BaseUser.php', 'BaseModel generated');
     $this->assertFileExists(self::$_storagePath . 'classes/User.php', 'Model generated');
     $this->assertTrue(class_exists('\\User'), 'Generated model class is available');
     QC::executeSQL('DROP TABLE IF EXISTS users');
     $mo->updateDBForModel('User');
     $data = DBOperator::getInstance()->getTableStructure('users');
     $this->assertNotEmpty($data, 'Table generation is ok');
 }
Ejemplo n.º 3
0
 public function setup()
 {
     $this->reloadConfig();
     $columnsToTranslate = $this->detectTranslatableColumns();
     if (empty($this->_config['columns'])) {
         $this->_config['columns'] = array_keys($columnsToTranslate);
     }
     if (empty($columnsToTranslate)) {
         throw new \Exception('You have to specify at least 1 column for translate in ' . $this->_modelName->_getName());
     }
     $this->_tableName = $this->_modelStructure->getTableName() . '_translate';
     $tableStructure = array('columns' => array(), 'indexes' => array($this->_tableName . '_translate' => array('columns' => array('id_language', 'id_object'), 'type' => 'unique')));
     $keyType = $this->_modelStructure->getColumnInfo($this->_primaryKey);
     $tableStructure['columns']['id_object'] = array('type' => $keyType['type']);
     $tableStructure['columns']['id_language'] = array('type' => 'char(2)');
     $tableStructure['columns'] = array_merge($tableStructure['columns'], $columnsToTranslate);
     DBOperator::getInstance()->createTable($this->_tableName, $tableStructure);
     $this->_modelStructure->updateAbilityInfo('translate', $this->_config);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Created database for profile default
  */
 public function createDbAction()
 {
     $config = DC::getDatabaseConfig('profiles/default');
     DatabaseService::configProfile(array('user' => $config['user'], 'pass' => $config['pass']));
     DBOperator::getInstance()->createDB($config['name']);
     $this->notify($config['name'], '+Database created:');
 }
Ejemplo n.º 5
0
 public function updateDBForModel($modelName, $safeUpdate = true)
 {
     $modelStructure = $this->getModelStructure($modelName);
     DBOperator::getInstance()->updateDBFromStructure($modelStructure, $safeUpdate);
     DBOperator::getInstance()->updateDBRelations($modelName, $modelStructure);
     return $this;
 }
Ejemplo n.º 6
0
 public function updateDatabaseStructure($safeUpdate = true)
 {
     DBOperator::getInstance()->updateDBFromStructure($this->_data->getArray(), $safeUpdate);
     return $this;
 }
Ejemplo n.º 7
0
 public static function tearDownAfterClass()
 {
     DBOperator::getInstance()->dropDB(self::$_DBName);
     FSService::unlinkRecursive(self::$_storagePath);
 }