Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
ContentTest.php
1 <?php
2 /**
3  *
4  */
5 class ContentTest extends CTestCase
6 {
7  protected $dynamicContent = '/Content.Node/index.html';
8 
9  protected $dynamicSource;
10 
11  protected $fsSource;
12  /**
13  * @var PHPUnit_Framework_MockObject_MockObject
14  */
15  protected $mockRepositoryApi;
16 
17  protected $oldRepositoryApi;
18 
19  public function setUp()
20  {
21  parent::setUp();
22 
23  Yii::app()->cache->flush();
24 
25  $this->dynamicSource = new DynamicContentSource();
26  $this->dynamicSource->cacheFolder = Yii::app()->getModule('contentSource')->sourceSettings['DynamicContentSource']['cacheFolder'];
27  $this->dynamicSource->usePersonalisation = true;
28  $this->dynamicSource->personalisationFields = Yii::app()->getModule('contentSource')->sourceSettings['DynamicContentSource']['personalisationFields'];
29  $this->dynamicSource->init();
30  @unlink($this->dynamicSource->contentFile($this->dynamicContent));
31 
32  $this->fsSource = new FileSystemContentSource();
33  $this->fsSource->contentFolder = Yii::app()->getModule('contentSource')->sourceSettings['FileSystemContentSource']['contentFolder'];
34  $this->fsSource->usePersonalisation = true;
35  $this->fsSource->personalisationFields = Yii::app()->getModule('contentSource')->sourceSettings['FileSystemContentSource']['personalisationFields'];
36  $this->fsSource->init();
37 
38  $this->oldRepositoryApi = Yii::app()->repositoryApi;
39  $this->mockRepositoryApi = $this->getMock('RepositoryApi', array('getContentAttributes'));
40  $this->mockRepositoryApi->expects($this->any())
41  ->method('getContentAttributes')
42  ->will($this->returnValue(require (Yii::getPathOfAlias('site.tests.runtime.contentSource') . '/testAttributes_getContentAttributes.php')));
43  Yii::app()->setComponent('repositoryApi', $this->mockRepositoryApi);
44  }
45 
46  public function tearDown()
47  {
48  Yii::app()->setComponent('repositoryApi', $this->oldRepositoryApi);
49  @unlink($this->dynamicSource->contentFile($this->dynamicContent));
50  }
51 
52  public function testDynamicSourceAttributes()
53  {
54  $this->mockRepositoryApi->expects($this->any())
55  ->method('getCmsObject')
56  ->will($this->returnValue(require (Yii::getPathOfAlias('site.tests.runtime.contentSource') . '/testGetDynamicContent_getCmsObject.php'))
57  );
58 
59  $content = new Content($this->dynamicSource, $this->dynamicContent);
60  $this->assertTrue(is_array($content->getAttributes()));
61  $this->assertTrue(in_array('marketing',$content->getPersonalisationAttributes()));
62  }
63 
64  public function testFileSystemSourceAttributes()
65  {
66  $content = new Content($this->fsSource, $this->dynamicContent);
67  $this->assertTrue(is_array($content->getAttributes()));
68  $this->assertTrue(in_array('marketing',$content->getPersonalisationAttributes()));
69  }
70 }