本文整理汇总了PHP中Sample::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Sample::read方法的具体用法?PHP Sample::read怎么用?PHP Sample::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBehaviorSaveCallbacks
/**
* testBehaviorSaveCallbacks method
*
* @return void
*/
public function testBehaviorSaveCallbacks()
{
$Sample = new Sample();
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
$Sample->create();
$this->assertSame(false, $Sample->save($record));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
$Sample->create();
$result = $Sample->save($record);
$expected = $record;
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
$Sample->create();
$result = $Sample->save($record);
$expected = $record;
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
$expected = Hash::insert($record, 'Sample.name', 'sample99 modified before');
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->disable('Test');
$this->assertSame($record, $Sample->save($record));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
$expected = Hash::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertEquals($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Hash::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
$Sample->create();
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
$Sample->create();
$expected = $record;
unset($expected['Sample']['name']);
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
$Sample->create();
$expected = $record;
$result = $Sample->save($record);
$expected['Sample']['id'] = $Sample->id;
$this->assertSame($expected, $result);
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
$Sample->recursive = -1;
$record2 = $Sample->read(null, 1);
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
$expected = Hash::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
$Sample->create();
$this->assertSame($expected, $Sample->save($record2));
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
$expected = Hash::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
$Sample->create();
$this->assertSame($expected, $Sample->save($record2));
}
示例2: testBehaviorSaveCallbacks
/**
* testBehaviorSaveCallbacks method
*
* @access public
* @return void
*/
function testBehaviorSaveCallbacks()
{
$Sample = new Sample();
$record = array('Sample' => array('apple_id' => 6, 'name' => 'sample99'));
$Sample->Behaviors->attach('Test', array('beforeSave' => 'on'));
$Sample->create();
$this->assertIdentical($Sample->save($record), false);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify'));
$expected = Set::insert($record, 'Sample.name', 'sample99 modified before');
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->disable('Test');
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'on'));
$expected = Set::merge($record, array('Sample' => array('aftersave' => 'modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'modify', 'afterSave' => 'modify'));
$expected = Set::merge($record, array('Sample' => array('name' => 'sample99 modified before modified after on create')));
$Sample->create();
$this->assertIdentical($Sample->save($record), $expected);
$Sample->Behaviors->attach('Test', array('beforeSave' => 'off', 'afterSave' => 'test'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('afterSave' => 'test2'));
$Sample->create();
$this->assertIdentical($Sample->save($record), $record);
$Sample->Behaviors->attach('Test', array('beforeFind' => 'off', 'afterFind' => 'off'));
$Sample->recursive = -1;
$record2 = $Sample->read(null, 1);
$Sample->Behaviors->attach('Test', array('afterSave' => 'on'));
$expected = Set::merge($record2, array('Sample' => array('aftersave' => 'modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
$Sample->Behaviors->attach('Test', array('afterSave' => 'modify'));
$expected = Set::merge($record2, array('Sample' => array('name' => 'sample1 modified after')));
$Sample->create();
$this->assertIdentical($Sample->save($record2), $expected);
}