7 protected $fixtures = array(
9 'personalisationAttributes' =>
'PersonalisationAttribute',
10 'userPersonalisationAttributes' =>
'UserPersonalisationAttribute',
13 protected $startFolderId =
'10002.580';
14 protected $activeElement =
'10002.4';
16 public static function setUpBeforeClass()
18 Yii::app()->getModule(
'navigation');
19 Yii::app()->getModule(
'personalisation');
23 private $_oldRepositoryApi;
29 Yii::app()->cache->flush();
31 $this->_oldRepositoryApi = Yii::app()->repositoryApi;
32 $mock = $this->getMock(
'RepositoryApi', array(
'requestNavigation',
'requestActivePath',
'request'));
34 $mock->expects($this->any())
35 ->method(
'requestNavigation')
36 ->will($this->returnValue(file_get_contents(Yii::getPathOfAlias(
'site.tests.runtime.navigation') .
'/requestNavigation.api')));
38 $mock->expects($this->any())
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";}}}'));
43 Yii::app()->setComponent(
'repositoryApi', $mock);
47 public function tearDown()
49 Yii::app()->setComponent(
'repositoryApi', $this->_oldRepositoryApi);
52 public function testConstructorNoActiveElement()
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.";}}'));
59 $this->assertTrue(is_array($navigationTree->data));
60 $this->assertTrue(is_array($navigationTree->activePath));
62 return $navigationTree;
70 $contentId =
'10002.3216';
72 $this->assertEquals($branch[
'contentid'], $contentId);
73 $this->assertCount(7, $branch[
'children']);
76 public function testConstructorIsActiveElement()
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));
87 public function testPersonalize()
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.";}}'));
96 $filteredTree = $navigationTree->cleanUp($this->user[
'sample2'][
'id']);
98 $this->assertCount(0, array_filter($permissions));
100 $filteredTree = $navigationTree->cleanUp($this->user[
'sample3'][
'id']);
102 $this->assertCount(24, array_filter($permissions));