コード例 #1
0
ファイル: Entity.php プロジェクト: nofutrue/MyProject
 public function testEntitySetDataConstruct()
 {
     $mapper = test_spot_mapper();
     $post = new Entity_Post(array('title' => 'My Awesome Post', 'body' => '<p>Body</p>'));
     $data = $post->data();
     ksort($data);
     $testData = array('id' => null, 'title' => 'My Awesome Post', 'body' => '<p>Body</p>', 'status' => 0, 'date_created' => null);
     ksort($testData);
     $this->assertEquals($testData, $data);
 }
コード例 #2
0
ファイル: Entity.php プロジェクト: acidline/rocket
 public function testEntityErrors()
 {
     $post = new Entity_Post(array('title' => 'My Awesome Post', 'body' => '<p>Body</p>'));
     $postErrors = array('title' => array('Title cannot contain the word awesome'));
     // Has NO errors
     $this->assertTrue(!$post->hasErrors());
     // Set errors
     $post->errors($postErrors);
     // Has errors
     $this->assertTrue($post->hasErrors());
     // Full error array
     $this->assertEquals($postErrors, $post->errors());
     // Errors for one key only
     $this->assertEquals($postErrors['title'], $post->errors('title'));
 }
コード例 #3
0
ファイル: Entity.php プロジェクト: vlucas/spot
 public function testDataNulls()
 {
     $data = array('title' => 'A Post', 'body' => 'A Body', 'status' => 0, 'author_id' => 1);
     $post = new Entity_Post($data);
     $post->status = null;
     $this->assertTrue($post->isModified('status'));
     $post->status = 1;
     $this->assertTrue($post->isModified('status'));
     $post->data(array('status' => null));
     $this->assertTrue($post->isModified('status'));
     $post->title = '';
     $this->assertTrue($post->isModified('title'));
     $this->title = null;
     $this->assertTrue($post->isModified('title'));
     $this->title = 'A Post';
     $post->data(array('title' => null));
     $this->assertTrue($post->isModified('title'));
 }
コード例 #4
0
ファイル: Hooks.php プロジェクト: vlucas/spot
 public function testAfterSaveEntityHook()
 {
     $mapper = test_spot_mapper();
     $post = new Entity_Post(array('title' => 'A title', 'body' => '<p>body</p>', 'status' => 1, 'author_id' => 1, 'date_created' => new \DateTime()));
     $i = $post->status;
     Entity_Post::$hooks = array('afterSave' => array('mock_save_hook'));
     $mapper->save($post);
     $this->assertEquals($i + 1, $post->status);
 }