FIX: Fix tests when running directly from framework.

This commit is contained in:
Sam Minnee 2016-09-12 18:16:39 +12:00
parent 9dd5ebee8c
commit 61d7c3af28
22 changed files with 66 additions and 48 deletions

View File

@ -9,8 +9,8 @@
* Contributing: http://tinymce.moxiecode.com/contributing
*/
$frameworkPath = rtrim(dirname(dirname(dirname(dirname(__FILE__)))), DIRECTORY_SEPARATOR);
$basePath = rtrim(dirname($frameworkPath), DIRECTORY_SEPARATOR);
$frameworkPath = defined('FRAMEWORK_PATH') ? FRAMEWORK_PATH : rtrim(dirname(dirname(dirname(dirname(__FILE__)))), DIRECTORY_SEPARATOR);
$basePath = defined('BASE_PATH') ? BASE_PATH : rtrim(dirname($frameworkPath), DIRECTORY_SEPARATOR);
// require composers autoloader
if(file_exists($basePath . '/vendor/autoload.php')) {

View File

@ -6,7 +6,7 @@
$MetaTags
<% require css('framework/client/dist/styles/debug.css') %>
<% require themedCSS('client/dist/styles/debug') %>
</head>
<body>
<div class="info">

View File

@ -29,6 +29,7 @@ class ControllerTest extends FunctionalTest {
public function setUp() {
parent::setUp();
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/');
$this->depSettings = Deprecation::dump_settings();
}

View File

@ -63,6 +63,8 @@ class DirectorTest extends SapphireTest {
$this->originalProtocolHeaders[$header] = $_SERVER[$header];
}
}
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/');
}
public function tearDown() {
@ -197,16 +199,6 @@ class DirectorTest extends SapphireTest {
'http://www.example.org/subfolder/test',
Director::absoluteURL('subfolder/test', Director::BASE)
);
// Setting it to false restores functionality
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', false);
$_SERVER['REQUEST_URI'] = $rootURL;
$this->assertEquals(BASE_URL.'/', Director::baseURL());
$this->assertEquals($rootURL.BASE_URL.'/', Director::absoluteBaseURL(BASE_URL));
$this->assertEquals(
$rootURL.BASE_URL . '/subfolder/test',
Director::absoluteURL('subfolder/test')
);
}
/**
@ -393,7 +385,7 @@ class DirectorTest extends SapphireTest {
}
public function testForceSSLProtectsEntireSite() {
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
$_SERVER['REQUEST_URI'] = '/admin';
$output = Director::forceSSL();
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

View File

@ -0,0 +1 @@
.a {color: #f00;}

View File

@ -0,0 +1 @@
.b {color: #0ff;}

View File

@ -0,0 +1 @@
.c {color: #0ff;}

View File

@ -105,7 +105,7 @@ class DeprecationTest extends SapphireTest {
}
protected function callThatOriginatesFromFramework() {
$this->assertEquals(DeprecationTest_Deprecation::get_module(), FRAMEWORK_DIR);
$this->assertEquals(DeprecationTest_Deprecation::get_module(), basename(FRAMEWORK_PATH));
$this->assertNull(Deprecation::notice('2.0', 'Deprecation test passed'));
}

View File

@ -5,6 +5,7 @@ use SilverStripe\Assets\Flysystem\PublicAssetAdapter;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Core\Config\Config;
class AssetAdapterTest extends SapphireTest {
@ -18,6 +19,7 @@ class AssetAdapterTest extends SapphireTest {
$this->rootDir = ASSETS_PATH . '/AssetAdapterTest';
Filesystem::makeFolder($this->rootDir);
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/');
$this->originalServer = $_SERVER;
}

View File

@ -86,14 +86,14 @@ class HTMLEditorConfigTest extends SapphireTest {
// Test plugins included via gzip compresser
HTMLEditorField::config()->update('use_gzip', true);
$this->assertEquals(
'framework/admin/thirdparty/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true',
ADMIN_THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true',
$c->getScriptURL()
);
// If gzip is disabled only the core plugin is loaded
HTMLEditorField::config()->remove('use_gzip');
$this->assertEquals(
'framework/admin/thirdparty/tinymce/tinymce.min.js',
ADMIN_THIRDPARTY_DIR . '/tinymce/tinymce.min.js',
$c->getScriptURL()
);
}

View File

@ -53,7 +53,7 @@ class HTMLEditorFieldTest extends FunctionalTest {
// Create a test files for each of the fixture references
$files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
foreach($files as $file) {
$fromPath = BASE_PATH . '/framework/tests/forms/images/' . $file->Name;
$fromPath = FRAMEWORK_PATH . '/tests/forms/images/' . $file->Name;
$destPath = AssetStoreTest_SpyStore::getLocalPath($file); // Only correct for test asset store
Filesystem::makeFolder(dirname($destPath));
copy($fromPath, $destPath);

View File

@ -162,12 +162,12 @@ class RequirementsTest extends SapphireTest {
]);
$backend->javascript($basePath . '/RequirementsTest_b.js');
$result = $backend->includeInHTML(self::$html_template);
$this->assertContains(
'<script type="application/json" src="/framework/tests/forms/RequirementsTest_a.js',
$this->assertRegexp(
'#<script type="application/json" src=".*/tests/forms/RequirementsTest_a.js#',
$result
);
$this->assertContains(
'<script type="application/javascript" src="/framework/tests/forms/RequirementsTest_b.js',
$this->assertRegexp(
'#<script type="application/javascript" src=".*/tests/forms/RequirementsTest_b.js#',
$result
);
}
@ -582,10 +582,7 @@ class RequirementsTest extends SapphireTest {
}
public function testConditionalTemplateRequire() {
$basePath = $this->getCurrentRelativePath();
// we're asserting "framework", so set the relative path accordingly in case FRAMEWORK_DIR was changed
// to something else
$basePath = 'framework' . substr($basePath, strlen(FRAMEWORK_DIR));
$testPath = ltrim(preg_replace('#^' . BASE_PATH . '#', '', dirname(__DIR__)), '/');
/** @var Requirements_Backend $backend */
$backend = Injector::inst()->create('SilverStripe\\View\\Requirements_Backend');
@ -596,23 +593,39 @@ class RequirementsTest extends SapphireTest {
'FailTest' => true,
));
$data->renderWith('RequirementsTest_Conditionals');
$this->assertFileIncluded($backend, 'css', $basePath .'/RequirementsTest_a.css');
$this->assertFileIncluded($backend, 'css', $testPath .'/css/forms/RequirementsTest_a.css');
$this->assertFileIncluded($backend, 'js',
array($basePath .'/RequirementsTest_b.js', $basePath .'/RequirementsTest_c.js'));
$this->assertFileNotIncluded($backend, 'js', $basePath .'/RequirementsTest_a.js');
array(
$testPath .'/javascript/forms/RequirementsTest_b.js',
$testPath .'/javascript/forms/RequirementsTest_c.js'
)
);
$this->assertFileNotIncluded($backend, 'js', $testPath .'/javascript/forms/RequirementsTest_a.js');
$this->assertFileNotIncluded($backend, 'css',
array($basePath .'/RequirementsTest_b.css', $basePath .'/RequirementsTest_c.css'));
array(
$testPath .'/css/forms/RequirementsTest_b.css',
$testPath .'/css/forms/RequirementsTest_c.css'
)
);
$backend->clear();
$data = new ArrayData(array(
'FailTest' => false,
));
$data->renderWith('RequirementsTest_Conditionals');
$this->assertFileNotIncluded($backend, 'css', $basePath .'/RequirementsTest_a.css');
$this->assertFileNotIncluded($backend, 'css', $testPath .'/css/forms/RequirementsTest_a.css');
$this->assertFileNotIncluded($backend, 'js',
array($basePath .'/RequirementsTest_b.js', $basePath .'/RequirementsTest_c.js'));
$this->assertFileIncluded($backend, 'js', $basePath .'/RequirementsTest_a.js');
array(
$testPath .'/javascript/forms/RequirementsTest_b.js',
$testPath .'/javascript/forms/RequirementsTest_c.js'
)
);
$this->assertFileIncluded($backend, 'js', $testPath .'/javascript/forms/RequirementsTest_a.js');
$this->assertFileIncluded($backend, 'css',
array($basePath .'/RequirementsTest_b.css', $basePath .'/RequirementsTest_c.css'));
array(
$testPath .'/css/forms/RequirementsTest_b.css',
$testPath .'/css/forms/RequirementsTest_c.css'
)
);
Requirements::set_backend($holder);
}

View File

@ -0,0 +1 @@
alert('a');

View File

@ -0,0 +1 @@
alert('b');

View File

@ -0,0 +1 @@
alert('c');

View File

@ -37,7 +37,7 @@ class DataDifferencerTest extends SapphireTest {
// Create a test files for each of the fixture references
$files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
foreach($files as $file) {
$fromPath = BASE_PATH . '/framework/tests/model/testimages/' . $file->Name;
$fromPath = FRAMEWORK_PATH . '/tests/model/testimages/' . $file->Name;
$destPath = AssetStoreTest_SpyStore::getLocalPath($file); // Only correct for test asset store
Filesystem::makeFolder(dirname($destPath));
copy($fromPath, $destPath);

View File

@ -1,5 +1,7 @@
<?php
require_once(__DIR__ . "/ImageTest.php");
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Cache;

View File

@ -40,7 +40,7 @@ class ImageTest extends SapphireTest {
$files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
foreach($files as $image) {
$filePath = AssetStoreTest_SpyStore::getLocalPath($image); // Only correct for test asset store
$sourcePath = BASE_PATH . '/framework/tests/model/testimages/' . $image->Name;
$sourcePath = FRAMEWORK_PATH . '/tests/model/testimages/' . $image->Name;
if(!file_exists($filePath)) {
SSFilesystem::makeFolder(dirname($filePath));
if (!copy($sourcePath, $filePath)) {

View File

@ -63,6 +63,8 @@ class SecurityTest extends FunctionalTest {
Member::config()->unique_identifier_field = 'Email';
parent::setUp();
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/');
}
public function tearDown() {
@ -347,7 +349,7 @@ class SecurityTest extends FunctionalTest {
$expiredResponse = $this->doTestLoginForm('expired@silverstripe.com' , '1nitialPassword');
$this->assertEquals(302, $expiredResponse->getStatusCode());
$this->assertEquals(
Controller::join_links(Director::baseURL(), 'Security/changepassword'),
'/Security/changepassword',
$expiredResponse->getHeader('Location')
);
$this->assertEquals($this->idFromFixture('SilverStripe\\Security\\Member', 'expiredpassword'),

View File

@ -1,3 +1,3 @@
<head>
<% require javascript(framework/tests/forms/RequirementsTest_a.js) %>
<% require themedJavascript(forms/RequirementsTest_a) %>
</head>

View File

@ -1,9 +1,9 @@
<% if $FailTest %>
<% require css(framework/tests/forms/RequirementsTest_a.css) %>
<% require javascript(framework/tests/forms/RequirementsTest_b.js) %>
<% require javascript(framework/tests/forms/RequirementsTest_c.js) %>
<% require themedCss(forms/RequirementsTest_a) %>
<% require themedJavascript(forms/RequirementsTest_b) %>
<% require themedJavascript(forms/RequirementsTest_c) %>
<% else %>
<% require javascript(framework/tests/forms/RequirementsTest_a.js) %>
<% require css(framework/tests/forms/RequirementsTest_b.css) %>
<% require css(framework/tests/forms/RequirementsTest_c.css) %>
<% require themedJavascript(forms/RequirementsTest_a) %>
<% require themedCss(forms/RequirementsTest_b) %>
<% require themedCss(forms/RequirementsTest_c) %>
<% end_if %>

View File

@ -25,7 +25,7 @@ class YamlFixtureTest extends SapphireTest {
}
public function testRelativeFixturePath() {
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
$relPath = ltrim(FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml', '/');
$obj = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $relPath);
$this->assertEquals(Director::baseFolder() . '/' . $relPath, $obj->getFixtureFile());
$this->assertNull($obj->getFixtureString());
@ -43,13 +43,13 @@ class YamlFixtureTest extends SapphireTest {
* @expectedException InvalidArgumentException
*/
public function testFailsWithInvalidFixturePath() {
$invalidPath = FRAMEWORK_DIR . '/tests/testing/invalid.yml';
$invalidPath = ltrim(FRAMEWORK_DIR . '/tests/testing/invalid.yml', '/');
$obj = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $invalidPath);
}
public function testSQLInsert() {
$factory = new FixtureFactory();
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
$relPath = ltrim(FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml', '/');
$fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $relPath);
$fixture->writeInto($factory);
@ -76,7 +76,7 @@ class YamlFixtureTest extends SapphireTest {
public function testWriteInto() {
$factory = Injector::inst()->create('SilverStripe\\Dev\\FixtureFactory');
$relPath = FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml';
$relPath = ltrim(FRAMEWORK_DIR . '/tests/testing/YamlFixtureTest.yml', '/');
$fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $relPath);
$fixture->writeInto($factory);