Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
DynamicContentSourceTest.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  */
11 class DynamicContentSourceTest extends CTestCase
12 {
13 
14  protected $dynamicContent = '/Content.Node/index.html';
15  protected $staticContent = '/Content.Node/files/css/audioplayerv1.min.css';
16 
17  /**
18  * @var DynamicContentSource
19  */
20  protected $source;
21  protected $oldRepositoryApi;
22  /**
23  * @var PHPUnit_Framework_MockObject_MockObject
24  */
25  protected $mockRepositoryApi;
26 
27  public function setUp()
28  {
29  parent::setUp();
30 
31  Yii::app()->cache->flush();
32 
33  $this->source = new DynamicContentSource();
34  $this->source->cacheFolder = Yii::app()->getModule('contentSource')->sourceSettings['DynamicContentSource']['cacheFolder'];
35  $this->source->init();
36 
37  $this->oldRepositoryApi = Yii::app()->repositoryApi;
38  $this->mockRepositoryApi = $this->getMock('RepositoryApi', array('getCmsObject', 'getLastModificationTime'));
39  $this->mockRepositoryApi->contentExternalHost = 'test.com';
40  Yii::app()->setComponent('repositoryApi', $this->mockRepositoryApi);
41  }
42 
43  public function tearDown()
44  {
45  Yii::app()->setComponent('repositoryApi', $this->oldRepositoryApi);
46 
47  @unlink($this->source->contentFile($this->dynamicContent));
48  @unlink($this->source->contentFile($this->staticContent));
49  }
50 
51  public function testGetDynamicContent()
52  {
53  $this->mockRepositoryApi->expects($this->any())
54  ->method('getCmsObject')
55  ->will($this->returnValue(require (Yii::getPathOfAlias('site.tests.runtime.contentSource') . '/testGetDynamicContent_getCmsObject.php'))
56  );
57 
58  $content = $this->source->getContent($this->dynamicContent);
59  $this->assertFileExists($content->getFile());
60  }
61 
62  public function testGetStaticContent()
63  {
64  $this->mockRepositoryApi->expects($this->any())
65  ->method('getCmsObject')
66  ->will($this->returnValue(require (Yii::getPathOfAlias('site.tests.runtime.contentSource') . '/testGetStaticContent_getCmsObject.php'))
67  );
68  $content = $this->source->getContent($this->staticContent);
69  $this->assertFileExists($content->getFile());
70  }
71 
72  public function testGetSavedContent()
73  {
74  $this->mockRepositoryApi->expects($this->once())
75  ->method('getCmsObject')
76  ->will($this->returnValue(require (Yii::getPathOfAlias('site.tests.runtime.contentSource') . '/testGetDynamicContent_getCmsObject.php'))
77  );
78  $this->mockRepositoryApi->expects($this->once())
79  ->method('getLastModificationTime')
80  ->will($this->returnValue('1339749121'));
81 
82  $content = $this->source->getContent($this->dynamicContent);
83  $this->assertFileExists($content->getFile());
84 
85  $content = $this->source->getContent($this->dynamicContent);
86  $this->assertFileExists($content->getFile());
87  }
88 
89  public function testGetFailedContent()
90  {
91  $this->mockRepositoryApi->expects($this->exactly(1))
92  ->method('getCmsObject')
93  ->will($this->returnValue(false));
94 
95  $content = $this->source->getContent($this->dynamicContent);
96  $this->assertFalse($content);
97  }
98 
99 }