예제 #1
0
파일: AdminTest.php 프로젝트: dsyman2/X2CRM
 public function testDisableAutomaticRecordTagging()
 {
     Yii::app()->db->createCommand("delete from x2_tags where 1");
     $admin = Yii::app()->settings;
     $admin->disableAutomaticRecordTagging = true;
     $this->assertUpdates($admin, array('disableAutomaticRecordTagging'));
     $contact = new Contacts();
     $contact->setAttributes(array('firstName' => 'test', 'lastName' => 'test', 'visibility' => 1, 'backgroundInfo' => '#tag0 #tag1 #tag2'));
     $this->assertSaves($contact);
     $this->assertEquals(0, (int) Yii::app()->db->createCommand("\n            select count(*) from x2_tags\n        ")->queryScalar());
     $admin->disableAutomaticRecordTagging = false;
     $this->assertUpdates($admin, array('disableAutomaticRecordTagging'));
     $this->assertSaves($contact);
     $this->assertEquals(array('#tag0', '#tag1', '#tag2'), Yii::app()->db->createCommand()->select('tag')->from('x2_tags')->order('tag asc')->queryColumn());
 }
예제 #2
0
 public function testModifyColumn()
 {
     $schema = Yii::app()->db->schema;
     $field = new Fields('test');
     $field->modelName = $this->getTestModelName();
     $field->fieldName = $this->getTestColumnName();
     $field->type = 'varchar';
     $field->custom = 0;
     $tableName = X2Model::model($field->modelName)->tableName();
     try {
         $field->createColumn();
     } catch (Exception $e) {
         $this->tearDownTestColumn();
         throw $e;
     }
     Yii::app()->db->schema->refresh();
     $columnsAfterAdd = Yii::app()->db->schema->tables[$tableName]->columnNames;
     $column = Yii::app()->db->schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('varchar(255)', $column->dbType);
     $this->assertTrue(in_array($field->fieldName, $columnsAfterAdd), "Column {$field->fieldName} was not created.");
     // test column modification
     $field->type = 'float';
     $this->assertTrue($field->modifyColumn());
     Yii::app()->db->schema->refresh();
     $column = Yii::app()->db->schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('float', $column->dbType);
     // test strict mode. Try to truncate column and ensure that modifyColumn returns false in
     // indicating CDbException
     $contact = Contacts::model()->findByPk(12345);
     if (!$contact) {
         // temporary fix to get test to work in opensource. For some reason the contact
         // fixture isn't being loaded.
         $contact = new Contacts();
         $contact->setAttributes(array('id' => 12345, 'name' => 'Testfirstname Testlastname', 'nameId' => 'Testfirstname Testlastname_12345', 'company' => 'Black Mesa_1', 'firstName' => 'Testfirstname', 'lastName' => 'Testlastname', 'email' => '*****@*****.**', 'assignedTo' => 'Anyone', 'visibility' => 1, 'phone' => '(234) 918-2348', 'phone2' => '398-103-6291', 'trackingKey' => '12345678901234567890'), false);
         $contact->save();
     }
     $fieldName = $field->fieldName;
     $field->type = 'text';
     $this->assertTrue($field->modifyColumn());
     Yii::app()->db->schema->refresh();
     $column = $schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('text', $column->dbType);
     $contact->refreshMetaData();
     // set field value to a string with length > 255
     $contact->{$fieldName} = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111';
     $this->assertSaves($contact);
     $field->type = 'varchar';
     Yii::app()->db->createCommand('set sql_mode=STRICT_ALL_TABLES;')->execute();
     $this->assertFalse($field->modifyColumn());
     $column = $schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('text', $column->dbType);
     Yii::app()->db->createCommand('set sql_mode="";')->execute();
     $this->tearDownTestColumn();
 }