Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
MainNavigationTreeTest.php
1 <?php
2 /**
3  *
4  */
5 class MainNavigationTreeTest extends CDbTestCase
6 {
7  protected $fixtures = array(
8  'user' => 'User',
9  'personalisationAttributes' => 'PersonalisationAttribute',
10  'userPersonalisationAttributes' => 'UserPersonalisationAttribute',
11  );
12 
13  protected $startFolderId = '10002.580';
14  protected $activeElement = '10002.4';
15 
16  public static function setUpBeforeClass()
17  {
18  Yii::app()->getModule('navigation');
19  Yii::app()->getModule('personalisation');
20  }
21 
22 
23  private $_oldRepositoryApi;
24 
25  public function setUp()
26  {
27  parent::setUp();
28 
29  Yii::app()->cache->flush();
30 
31  $this->_oldRepositoryApi = Yii::app()->repositoryApi;
32  $mock = $this->getMock('RepositoryApi', array('requestNavigation', 'requestActivePath', 'request'));
33 
34  $mock->expects($this->any())
35  ->method('requestNavigation')
36  ->will($this->returnValue(file_get_contents(Yii::getPathOfAlias('site.tests.runtime.navigation') . '/requestNavigation.api')));
37 
38  $mock->expects($this->any())
39  ->method('request')
40 // ->with($this->identicalTo(array('filter' => 'object.contentid==10002.580', 'type' => 'php')), $this->identicalTo(array('updatetimestamp')))
41  ->will($this->returnValue('a:2:{s:6:"status";s:2:"ok";s:9:"10002.580";a:6:{s:9:"contentid";s:9:"10002.580";s:6:"obj_id";s:3:"580";s:8:"obj_type";s:5:"10002";s:9:"mother_id";s:1:"0";s:11:"mother_type";s:5:"10002";s:10:"attributes";a:1:{s:15:"updatetimestamp";s:10:"1338894653";}}}'));
42 
43  Yii::app()->setComponent('repositoryApi', $mock);
44 
45  }
46 
47  public function tearDown()
48  {
49  Yii::app()->setComponent('repositoryApi', $this->_oldRepositoryApi);
50  }
51 
52  public function testConstructorNoActiveElement()
53  {
54  Yii::app()->repositoryApi
55  ->expects($this->any())
56  ->method('requestActivePath')
57  ->will($this->returnValue('a:2:{s:6:"status";s:5:"error";s:5:"Error";a:2:{s:4:"type";s:11:"NoDataFound";s:7:"message";s:24:"Data could not be found.";}}'));
58  $navigationTree = new NavigationTree($this->startFolderId, 0);
59  $this->assertTrue(is_array($navigationTree->data));
60  $this->assertTrue(is_array($navigationTree->activePath));
61 
62  return $navigationTree;
63  }
64 
65  /**
66  * @depends testConstructorNoActiveElement
67  */
68  public function testExtractBranch(NavigationTree $navigationTree)
69  {
70  $contentId = '10002.3216';
71  $branch = NavigationTree::extractBranch($navigationTree->data, $contentId);
72  $this->assertEquals($branch['contentid'], $contentId);
73  $this->assertCount(7, $branch['children']);
74  }
75 
76  public function testConstructorIsActiveElement()
77  {
78  Yii::app()->repositoryApi
79  ->expects($this->any())
80  ->method('requestActivePath')
81  ->will($this->returnValue('a:3:{s:6:"status";s:2:"ok";s:9:"10002.580";a:5:{s:9:"contentid";s:9:"10002.580";s:6:"obj_id";s:3:"580";s:8:"obj_type";s:5:"10002";s:9:"mother_id";s:1:"0";s:11:"mother_type";s:5:"10002";}s:7:"10002.4";a:5:{s:9:"contentid";s:7:"10002.4";s:6:"obj_id";s:1:"4";s:8:"obj_type";s:5:"10002";s:9:"mother_id";s:3:"580";s:11:"mother_type";s:5:"10002";}}'));
82  $navigationTree = new NavigationTree($this->startFolderId, $this->activeElement);
83  $this->assertTrue(is_array($navigationTree->data));
84  $this->assertTrue(is_array($navigationTree->activePath));
85  }
86 
87  public function testPersonalize()
88  {
89  Yii::app()->repositoryApi
90  ->expects($this->any())
91  ->method('requestActivePath')
92  ->with($this->identicalTo(array('root' => '10002.580', 'contentid' => 0, 'type' => 'php')))
93  ->will($this->returnValue('a:2:{s:6:"status";s:5:"error";s:5:"Error";a:2:{s:4:"type";s:11:"NoDataFound";s:7:"message";s:24:"Data could not be found.";}}'));
94  $navigationTree = new NavigationTree($this->startFolderId, 0);
95 
96  $filteredTree = $navigationTree->cleanUp($this->user['sample2']['id']);
97  AppHelper::findItemsWithKey($filteredTree, 'permissions', $permissions);
98  $this->assertCount(0, array_filter($permissions));
99 
100  $filteredTree = $navigationTree->cleanUp($this->user['sample3']['id']);
101  AppHelper::findItemsWithKey($filteredTree, 'permissions', $permissions);
102  $this->assertCount(24, array_filter($permissions));
103  }
104 
105 
106 
107 }
108