Esempio n. 1
0
 public static function clearCounters()
 {
     self::$_counters = array();
 }
 /**
  * CActiveRecord::getRelated doesn't call afterFind() with `through` relation
  * https://github.com/yiisoft/yii/issues/591
  */
 public function testIssue591()
 {
     UserWithWrappers::model()->with('comments')->findByPk(1);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 0);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 3);
     $user = UserWithWrappers::model()->findByPk(1);
     $user->comments;
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 0);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 3);
 }
 public function testAfterFindRelational()
 {
     UserWithWrappers::model()->with('posts.comments')->find();
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
     UserWithWrappers::model()->with('posts.comments')->findByAttributes(array('username' => 'user2'));
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findByPk(2);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findBySql('SELECT * FROM users WHERE id=2');
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAll();
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
     UserWithWrappers::model()->with('posts.comments')->findAllByAttributes(array('username' => 'user2'));
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAllByPk(2);
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 1);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 3);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 6);
     UserWithWrappers::model()->with('posts.comments')->findAllBySql('SELECT * FROM users');
     $this->assertEquals(UserWithWrappers::getCounter('afterFind'), 4);
     $this->assertEquals(PostWithWrappers::getCounter('afterFind'), 5);
     $this->assertEquals(CommentWithWrappers::getCounter('afterFind'), 10);
 }