2009-11-05 02:12:44 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Tests for the {@link FilesystemPublisher} class.
|
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class FilesystemPublisherTest extends SapphireTest {
|
2010-08-03 05:11:45 +02:00
|
|
|
|
|
|
|
protected $usesDatabase = true;
|
|
|
|
|
2010-10-13 06:20:27 +02:00
|
|
|
protected $orig = array();
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function setUp() {
|
2010-08-03 05:11:45 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2012-10-09 05:56:57 +02:00
|
|
|
SiteTree::add_extension("FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
2010-10-13 06:20:27 +02:00
|
|
|
|
|
|
|
$this->orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching;
|
|
|
|
FilesystemPublisher::$domain_based_caching = false;
|
2010-06-03 03:29:14 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function tearDown() {
|
2010-10-19 03:04:34 +02:00
|
|
|
parent::tearDown();
|
|
|
|
|
2010-10-19 03:04:29 +02:00
|
|
|
Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
|
2010-10-19 03:04:34 +02:00
|
|
|
|
2010-10-13 06:20:27 +02:00
|
|
|
FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
|
2010-10-19 03:04:34 +02:00
|
|
|
|
|
|
|
if(file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) {
|
|
|
|
Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder');
|
|
|
|
}
|
2010-06-03 03:29:14 +02:00
|
|
|
}
|
2009-11-05 02:12:44 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testUrlsToPathsWithRelativeUrls() {
|
2010-10-13 06:20:27 +02:00
|
|
|
$fsp = new FilesystemPublisher('.', 'html');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array('/')),
|
|
|
|
array('/' => './index.html'),
|
|
|
|
'Root URL path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array('about-us')),
|
|
|
|
array('about-us' => './about-us.html'),
|
|
|
|
'URLsegment path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array('parent/child')),
|
|
|
|
array('parent/child' => 'parent/child.html'),
|
|
|
|
'Nested URLsegment path mapping'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testUrlsToPathsWithAbsoluteUrls() {
|
2010-10-13 06:20:27 +02:00
|
|
|
$fsp = new FilesystemPublisher('.', 'html');
|
|
|
|
|
|
|
|
$url = Director::absoluteBaseUrl();
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => './index.html'),
|
|
|
|
'Root URL path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$url = Director::absoluteBaseUrl() . 'about-us';
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => './about-us.html'),
|
|
|
|
'URLsegment path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$url = Director::absoluteBaseUrl() . 'parent/child';
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => 'parent/child.html'),
|
|
|
|
'Nested URLsegment path mapping'
|
|
|
|
);
|
|
|
|
}
|
2012-02-06 10:12:40 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testUrlsToPathsWithDomainBasedCaching() {
|
2010-10-13 06:20:33 +02:00
|
|
|
$origDomainBasedCaching = FilesystemPublisher::$domain_based_caching;
|
2010-10-13 06:20:27 +02:00
|
|
|
FilesystemPublisher::$domain_based_caching = true;
|
|
|
|
|
|
|
|
$fsp = new FilesystemPublisher('.', 'html');
|
|
|
|
|
|
|
|
$url = 'http://domain1.com/';
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => 'domain1.com/index.html'),
|
|
|
|
'Root URL path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$url = 'http://domain1.com/about-us';
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => 'domain1.com/about-us.html'),
|
|
|
|
'URLsegment path mapping'
|
|
|
|
);
|
|
|
|
|
|
|
|
$url = 'http://domain2.com/parent/child';
|
|
|
|
$this->assertEquals(
|
|
|
|
$fsp->urlsToPaths(array($url)),
|
|
|
|
array($url => 'domain2.com/parent/child.html'),
|
|
|
|
'Nested URLsegment path mapping'
|
|
|
|
);
|
2010-10-13 06:20:33 +02:00
|
|
|
|
|
|
|
FilesystemPublisher::$domain_based_caching = $origDomainBasedCaching;
|
2010-10-13 06:20:27 +02:00
|
|
|
}
|
|
|
|
|
2009-11-05 02:12:44 +01:00
|
|
|
/**
|
|
|
|
* Simple test to ensure that FileSystemPublisher::__construct()
|
|
|
|
* has called parent::__construct() by checking the class property.
|
|
|
|
* The class property is set on {@link Object::__construct()} and
|
|
|
|
* this is therefore a good test to ensure it was called.
|
|
|
|
*
|
|
|
|
* If FilesystemPublisher doesn't call parent::__construct() then
|
|
|
|
* it won't be enabled propery because {@link Object::__construct()}
|
|
|
|
* is where extension instances are set up and subsequently used by
|
|
|
|
* {@link DataObject::defineMethods()}.
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testHasCalledParentConstructor() {
|
2009-11-05 02:12:44 +01:00
|
|
|
$fsp = new FilesystemPublisher('.', '.html');
|
|
|
|
$this->assertEquals($fsp->class, 'FilesystemPublisher');
|
|
|
|
}
|
|
|
|
|
2010-10-04 08:14:49 +02:00
|
|
|
/*
|
|
|
|
* These are a few simple tests to check that we will be retrieving the correct theme when we need it
|
|
|
|
* StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testStaticPublisherTheme(){
|
2010-10-04 08:14:49 +02:00
|
|
|
|
|
|
|
//This will be the name of the default theme of this particular project
|
|
|
|
$default_theme=SSViewer::current_theme();
|
|
|
|
|
|
|
|
$p1 = new Page();
|
|
|
|
$p1->URLSegment = strtolower(__CLASS__).'-page-1';
|
|
|
|
$p1->HomepageForDomain = '';
|
|
|
|
$p1->write();
|
|
|
|
$p1->doPublish();
|
|
|
|
|
|
|
|
$current_theme=SSViewer::current_custom_theme();
|
|
|
|
$this->assertEquals($current_theme, $default_theme, 'After a standard publication, the theme is correct');
|
|
|
|
|
|
|
|
//The CMS sometimes sets the theme to null. Check that the $current_custom_theme is still the default
|
|
|
|
SSViewer::set_theme(null);
|
|
|
|
$current_theme=SSViewer::current_custom_theme();
|
|
|
|
$this->assertEquals($current_theme, $default_theme, 'After a setting the theme to null, the default theme is correct');
|
|
|
|
|
|
|
|
//We can set the static_publishing theme to something completely different:
|
|
|
|
//Static publishing will use this one instead of the current_custom_theme if it is not false
|
|
|
|
StaticPublisher::set_static_publisher_theme('otherTheme');
|
|
|
|
$current_theme=StaticPublisher::static_publisher_theme();
|
|
|
|
$this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom theme');
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|