silverstripe-cms/tests/model/ErrorPageFileExtensionTest.php
Damian Mooyman 1c907dd227 API Support versioned File management
API Decouple File and ErrorPage
API Link tracking is now only performed on stage (in lieu of versioned relationships)
API Refactor versioned API methods out of SiteTree and into Versioned
2016-02-22 12:25:25 +13:00

59 lines
2.4 KiB
PHP

<?php
class ErrorPageFileExtensionTest extends SapphireTest {
protected static $fixture_file = 'ErrorPageTest.yml';
protected $versionedMode = null;
public function setUp() {
parent::setUp();
$this->versionedMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
AssetStoreTest_SpyStore::activate('ErrorPageFileExtensionTest');
$file = new File();
$file->setFromString('dummy', 'dummy.txt');
$file->write();
}
public function tearDown() {
Versioned::set_reading_mode($this->versionedMode);
AssetStoreTest_SpyStore::reset();
parent::tearDown(); // TODO: Change the autogenerated stub
}
public function testErrorPage() {
// Get and publish records
$notFoundPage = $this->objFromFixture('ErrorPage', '404');
$notFoundPage->publish('Stage', 'Live');
$notFoundLink = $notFoundPage->Link();
$disallowedPage = $this->objFromFixture('ErrorPage', '403');
$disallowedPage->publish('Stage', 'Live');
$disallowedLink = $disallowedPage->Link();
// Get stage version of file
$file = File::get()->first();
$fileLink = $file->Link();
Session::clear("loggedInAs");
// Generate shortcode for a file which doesn't exist
$shortcode = File::handle_shortcode(array('id' => 9999), null, new ShortcodeParser(), 'file_link');
$this->assertEquals($notFoundLink, $shortcode);
$shortcode = File::handle_shortcode(array('id' => 9999), 'click here', new ShortcodeParser(), 'file_link');
$this->assertEquals(sprintf('<a href="%s">%s</a>', $notFoundLink, 'click here'), $shortcode);
// Test that user cannot view draft file
$shortcode = File::handle_shortcode(array('id' => $file->ID), null, new ShortcodeParser(), 'file_link');
$this->assertEquals($disallowedLink, $shortcode);
$shortcode = File::handle_shortcode(array('id' => $file->ID), 'click here', new ShortcodeParser(), 'file_link');
$this->assertEquals(sprintf('<a href="%s">%s</a>', $disallowedLink, 'click here'), $shortcode);
// Authenticated users don't get the same error
$this->logInWithPermission('ADMIN');
$shortcode = File::handle_shortcode(array('id' => $file->ID), null, new ShortcodeParser(), 'file_link');
$this->assertEquals($fileLink, $shortcode);
}
}