本文整理汇总了PHP中Contacts::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Contacts::setAttributes方法的具体用法?PHP Contacts::setAttributes怎么用?PHP Contacts::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contacts
的用法示例。
在下文中一共展示了Contacts::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDisableAutomaticRecordTagging
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: testModifyColumn
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' => 'contact@test.com', '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();
}