Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
PersonalisationAttributeTest.php
1 <?php
2 /**
3  *
4  */
5 class PersonalisationAttributeTest extends CDbTestCase
6 {
7  public $fixtures = array(
8  'personalisationAttributes' => 'PersonalisationAttribute',
9  'userPersonalisationAttributes' => 'UserPersonalisationAttribute',
10  'user' => 'User'
11  );
12 
13  public static function setUpBeforeClass()
14  {
15  Yii::app()->getModule('personalisation');
16  PersonalisationAttribute::model()->deleteAll();
17 
18 
19  }
20 
21  public function testGetChildren()
22  {
23  $parent = PersonalisationAttribute::model()->findByAttributes(array('name' => 'Personal'));
24 
25  $this->assertCount(4, $parent->getChildren());
26  $this->assertCount(4, $parent->getChildrenIds());
27 
28  $parent = PersonalisationAttribute::model()->findByAttributes(array('name' => 'CEO'));
29 
30  $this->assertCount(0, $parent->getChildren());
31  $this->assertCount(0, $parent->getChildrenIds());
32  }
33 
34  public function testUserFlatList()
35  {
36  $this->assertCount(4, PersonalisationAttribute::flatListForUser($this->user['sample1']['id']));
37 
38  $this->assertCount(0, PersonalisationAttribute::flatListForUser($this->user['sample2']['id']));
39  }
40 
41  public function testGetTree()
42  {
44 
45  $this->assertCount(4, $tree['item']);
46  $this->assertNotEmpty(array_filter($tree['item'], function($var){return $var['text'] == 'CEO';}));
47  $this->assertNotEmpty(array_filter($tree['item'], function($var){return $var['text'] == 'development';}));
48 
49  }
50 
51  public function testGetTreeWithUserState()
52  {
53  $tree = PersonalisationAttribute::getTreeWithUserState($this->user['sample1']['id']);
54  $this->assertArrayHasKey('checked',array_pop(array_filter($tree['item'], function($var){return $var['text'] == 'Personal';})));
55  }
56 
57  public function testFlatListForUser()
58  {
59  $flatList = PersonalisationAttribute::flatListForUser($this->user['sample1']['id']);
60 
61  $this->assertCount(4, $flatList);
62  $this->assertTrue(in_array('Personal', $flatList));
63  $this->assertTrue(in_array('Programmer', $flatList));
64  $this->assertTrue(in_array('Manager', $flatList));
65  $this->assertTrue(in_array('Cleaner', $flatList));
66 
67  $flatList = PersonalisationAttribute::flatListForUser($this->user['sample2']['id']);
68  $this->assertCount(0, $flatList);
69  }
70 }