Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
CommentsModuleAccessMethodsTest.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: andrew
5  * Date: 7/13/12
6  * Time: 3:37 PM
7  * To change this template use File | Settings | File Templates.
8  */
10 {
11 
12  public $fixtures = array(
13  'comments' => 'Comment',
14  'users' => 'User',
15  'AuthItem' => ':AuthItem',
16  'AuthItemChild' => ':AuthItemChild',
17  'AuthAssignment' => ':AuthAssignment'
18  );
19 
20  protected $oldUser;
21 
22  public function setUp()
23  {
24  parent::setUp();
25  $this->oldUser = Yii::app()->user;
26  }
27 
28  public function tearDown()
29  {
30  Yii::app()->setComponent('user', $this->oldUser);
31  }
32 
33  protected function getUserMock($methods)
34  {
35  $webUser = $this->getMock('CWebUser', $methods);
36  Yii::app()->setComponent('user', $webUser);
37  return $webUser;
38  }
39 
40  public function testCantDeleteNotLoggedIn()
41  {
42  $this->assertFalse(CommentsModule::canDelete($this->comments('loggedIn')));
43  }
44 
45  public function testCanDeleteOwner()
46  {
47  $webUser = $this->getUserMock(array('getId', 'getIsInitialized'));
48  $webUser->expects($this->any())->method('getId')->will($this->returnValue($this->users['commenterWithoutRights']['id']));
49  $webUser->expects($this->any())->method('getIsInitialized')->will($this->returnValue(true));
50 
51  $this->assertTrue(CommentsModule::canDelete($this->comments('loggedIn')));
52  }
53 
54  public function testCanDeleteModerator()
55  {
56  $webUser = $this->getUserMock(array('getId', '__get'));
57  //override whole __get, getId() also returns email
58  $webUser->expects($this->any())->method('__get')
59  ->will($this->returnValue($this->users['commentsModerator']['email']));
60  $webUser->expects($this->any())->method('getIsInitialized')->will($this->returnValue(true));
61  $this->assertTrue(CommentsModule::canDelete($this->comments('loggedIn')));
62  }
63 
64  public function testCanDeleteManageCommentsPermission()
65  {
66  $webUser = $this->getUserMock(array('getId', 'getIsInitialized', '__get'));
67  $webUser->expects($this->any())->method('getId')->will($this->returnValue($this->users['manageComments']['id']));
68  $webUser->expects($this->any())->method('getIsInitialized')->will($this->returnValue(true));
69  $this->assertTrue(CommentsModule::canDelete($this->comments('loggedIn')));
70  }
71 
72  public function testCanApproveNotLoggedIn()
73  {
74  $this->assertFalse(CommentsModule::canApprove($this->comments('loggedIn')));
75  }
76 
77  public function testCantApproveOwner()
78  {
79  $webUser = $this->getUserMock(array('__get', 'getId', 'getIsInitialized'));
80  $webUser->expects($this->any())->method('getIsInitialized')->will($this->returnValue(true));
81  $webUser->expects($this->any())->method('__get')
82  ->will($this->returnValue($this->users['commenterWithoutRights']['email']));
83  $webUser->expects($this->any())->method('getId')
84  ->will($this->returnValue($this->users['commenterWithoutRights']['id']));
85 
86  $this->assertFalse(CommentsModule::canApprove($this->comments('loggedIn')));
87  }
88 
89  public function testCanApproveManageCommentsPermission()
90  {
91  $webUser = $this->getUserMock(array('getId', 'getIsInitialized', '__get'));
92  $webUser->expects($this->any())->method('getId')->will($this->returnValue($this->users['manageComments']['id']));
93  $webUser->expects($this->any())->method('getIsInitialized')->will($this->returnValue(true));
94  $this->assertTrue(CommentsModule::canApprove($this->comments('loggedIn')));
95  }
96 
97  public function testIsEmailModerator()
98  {
99  $this->assertTrue(CommentsModule::isEmailModerator($this->users['commentsModerator']['email']));
100  $this->assertFalse(CommentsModule::isEmailModerator($this->users['commenterWithoutRights']['email']));
101  }
102 
103 }