Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
historyTest.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: Andrey
5  * Date: 5/17/13
6  * Time: 2:51 PM
7  * To change this template use File | Settings | File Templates.
8  */
9 
10 class historyTest extends CDbTestCase{
11 
12  public $fixtures = array(
13 
14  );
15 
16  public $collection_id;
17 
18  public $data;
19 
20  public static function setUpBeforeClass(){
21 
22  Yii::app()->getModule('history');
23  Yii::app()->cache->delete(VisitedHistory::getCacheKey('getCacheKey'));
24  }
25 
26  public function setUp(){
27 
28  $this->collection_id = 'history';
29 
30  $this->data = array(
31  'home' => array(
32  'url' => 'http://gportal-dev-dev.gentics.com/Content.Node/index.html',
33  'title' => 'home',
34  'page_id' => 1,
35  ),
36  'news' => array(
37  'url' => 'http://gportal-dev-dev.gentics.com/Content.Node/news/News-Overview.en.html',
38  'title' => 'news',
39  'page_id' => 2,
40  ),
41  'products' => array(
42  'url' => 'http://gportal-dev-dev.gentics.com/Content.Node/products/Products.en.html',
43  'title' => 'products',
44  'page_id' => 3,
45  ),
46  'blog' => array(
47  'url' => 'http://gportal-dev-dev.gentics.com/Content.Node/blog/Corporate-Blog.en.html',
48  'title' => 'blog',
49  'page_id' => 4,
50  ),
51  'service' => array(
52  'url' => 'http://gportal-dev-dev.gentics.com/Content.Node/service/Overview_Service.en.html',
53  'title' => 'service',
54  'page_id' => 5,
55  ),
56  );
57 
58  parent::setUp();
59  }
60 
61  public function testSaveHistory(){
62 
63  foreach($this->data as $i => $page){
64 
65  VisitedHistory::addItem($page['url'], $page['title'], $page['page_id'], $this->collection_id);
66 
67  $this->assertNotEquals(Yii::app()->cache->get(VisitedHistory::getCacheKey($this->collection_id)), null, "History has not been written");
68  }
69  }
70 
71  public function testReadHistory(){
72 
73  $history = VisitedHistory::getItems($this->collection_id);
74 
75  $this->assertNotEmpty($history, "History has not been read");
76 
77  foreach($history as $valuesFromCache){
78  $title = $valuesFromCache['title'];
79  $this->assertEquals($this->getHash($this->data[$title]), $this->getHash($valuesFromCache), "Information which was read doesn't math the pattern");
80  }
81  }
82 
83  public function getHash($data){
84  $hash = '';
85  $comparedFields = array('url', 'title', 'page_id');
86 
87  foreach($data as $fieldName => $value){
88 
89  if(in_array($fieldName, $comparedFields)){
90  $hash .= $value;
91  }
92 
93  }
94  return md5($hash);
95  }
96 }