Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
CommentRelationsAndScopesTest.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: andrew
5  * Date: 7/12/12
6  * Time: 5:59 PM
7  * To change this template use File | Settings | File Templates.
8  */
9 class CommentRelationsAndScopesTest extends CDbTestCase
10 {
11  public $fixtures = array(
12  'comments' => 'Comment'
13  );
14 
15  public function testParentRelation()
16  {
17  $comment = Comment::model()->findByPk($this->comments['child1']['id']);
18  $this->assertNotNull($comment->parent);
19  }
20 
21  public function testChildRelation()
22  {
23  $comment = Comment::model()->findByPk($this->comments['parent']['id']);
24  $this->assertCount(2, $comment->childs);
25  }
26 
27  public function testIsParentScope()
28  {
29  $this->assertEquals(3, Comment::model()->resetScope()->isParent()->countByAttributes(array('content_id' => 'fixture1')));
30  }
31 
32  public function testIsChildScope()
33  {
34  $this->assertEquals(2, Comment::model()->resetScope()->isChild()->countByAttributes(array('content_id' => 'fixture1')));
35  }
36 
37  public function testDefaultScope()
38  {
39  $this->assertEquals(4, Comment::model()->countByAttributes(array('content_id' => 'fixture1')));
40  $this->assertEquals(5, Comment::model()->resetScope()->countByAttributes(array('content_id' => 'fixture1')));
41  }
42 
43  public function testApprovedScope()
44  {
45  $this->assertEquals(1, Comment::model()->approved()->countByAttributes(array('content_id' => 'fixture1')));
46  }
47 
48  public function testGetStatusText()
49  {
50  $this->assertEquals('Approved', $this->comments('approved')->getStatusText());
51  $this->assertEquals('Not approved', $this->comments('child2')->getStatusText());
52 
53  $deleted = Comment::model()->resetScope()->findByAttributes(array('status' => Comment::DELETED));
54  $this->assertEquals('Deleted', $deleted->getStatusText());
55  }
56 
57  public function testDelete()
58  {
59  $this->comments('approved')->delete();
60  $this->assertNull(Comment::model()->findByPk($this->comments('approved')->id));
61  $this->assertNotNull(Comment::model()->resetScope()->findByPk($this->comments('approved')->id));
62 
63  $this->comments('approved')->delete(true);
64  $this->assertNull(Comment::model()->resetScope()->findByPk($this->comments('approved')->id));
65  }
66 }