Merge pull request #5986 from sminnee/simpler-test-run

Simpler test run
This commit is contained in:
Daniel Hensby 2016-09-17 08:10:46 +01:00 committed by GitHub
commit 6f28ac5365
44 changed files with 379 additions and 137 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@ node_modules/
coverage/
/**/*.js.map
/**/*.css.map
vendor/
composer.lock
silverstripe-cache/

View File

@ -10,8 +10,6 @@ addons:
env:
global:
- TRAVIS_NODE_VERSION="4"
- CORE_RELEASE=master
- CORE_RELEASE_VERSION=4.0
- ARTIFACTS_REGION=us-east-1
- ARTIFACTS_BUCKET=silverstripe-travis-artifacts
- secure: "jVR0iLTuvVfA6jKX5+A3AdUEs8Ps+r3SbL0zGR687K8IoSp3a/+JLH12zFCEexOuxwCtOhlMq8zoZsptCEduCDq+0payk5k6GjNVywFaWjJCV573JScdaHAtoumoHMUvua+Pxds0qKAD2XEYAcOR4Qu7S4HLJV6E1QqHg9PRW5s=" # Encrypted ARTIFACTS_KEY
@ -29,13 +27,13 @@ matrix:
env: DB=MYSQL PDO=1 PHPUNIT_TEST=1
- php: 5.6
env: DB=MYSQL BEHAT_TEST=1
- php: 5.6
env: NPM_TEST=1
allow_failures:
- php: 5.6
env: DB=MYSQL CMS_TEST=1 PHPUNIT_TEST=1
- php: 5.6
env: DB=MYSQL CMS_TEST=1 BEHAT_TEST=1
- php: 5.6
env: NPM_TEST=1
allow_failures:
- php: 7.0
env: DB=MYSQL PDO=1 PHPUNIT_TEST=1
@ -44,22 +42,22 @@ before_script:
- composer self-update || true
- phpenv rehash
- phpenv config-rm xdebug.ini
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension; fi"
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/cms:$CORE_RELEASE_VERSION.x-dev; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension,silverstripe/cms:$CORE_RELEASE_VERSION.x-dev; fi"
- "export DISPLAY=\":99\""
- "export XVFBARGS=\":99 -ac -screen 0 1024x768x16\""
- "if [ \"$na\" = \"\" ]; then composer install --prefer-dist; fi"
- "if [ \"$DB\" = \"PGSQL\" ]; then composer require silverstripe/postgresql:2.0.x-dev --prefer-dist; fi"
- "if [ \"$DB\" = \"SQLITE\" ]; then composer require silverstripe/sqlite3:2.0.x-dev --prefer-dist; fi"
- "if [ \"$CMS_TEST\" = \"1\" ]; then COMPOSER_ROOT_VERSION=4.0.x-dev composer require silverstripe/cms:4.0.x-dev silverstripe/siteconfig:4.0.x-dev silverstripe/reports:4.0.x-dev --prefer-dist; fi"
- "if [ \"$NPM_TEST\" = \"1\" ]; then nvm install $TRAVIS_NODE_VERSION && npm install; fi"
- "if [ \"$NPM_TEST\" = \"\" ]; then cd ~/builds/ss; fi"
- "if [ \"$NPM_TEST\" = \"\" ] && [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup_selenium.php; fi"
- "if [ \"$NPM_TEST\" = \"\" ] && [ \"$BEHAT_TEST\" = \"1\" ]; then php ~/travis-support/travis_setup_php54_webserver.php; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then sh -e /etc/init.d/xvfb start; sleep 3; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/selenium-server-standalone > selenium.log 2>&1 &); fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then (vendor/bin/serve --bootstrap-file tests/behat/serve-bootstrap.php &> serve.log &); fi"
script:
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/phpunit framework/tests; fi"
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/phpunit framework/admin/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/behat @framework; fi"
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/phpunit; fi"
- "if [ \"$PHPUNIT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/phpunit cms/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/behat @cms; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then vendor/bin/behat --config tests/behat/config.yml .; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"1\" ]; then vendor/bin/behat @cms --config cms/tests/behat/behat.yml; fi"
- "if [ \"$NPM_TEST\" = \"1\" ]; then npm run test; fi"
after_failure:

View File

@ -175,8 +175,19 @@ if (defined('SS_ALLOWED_HOSTS') && php_sapi_name() !== "cli") {
/**
* Define system paths
*/
// Determine BASE_PATH based on the composer autoloader
if(!defined('BASE_PATH')) {
// Assuming that this file is framework/core/Core.php we can then determine the base path
foreach(debug_backtrace() as $backtraceItem) {
if(preg_match('#^(.*)\/vendor/composer/autoload_real.php#', $backtraceItem['file'], $matches)) {
define('BASE_PATH', $matches[1]);
break;
}
}
}
// Determine BASE_PATH by assuming that this file is framework/core/Core.php
if(!defined('BASE_PATH')) {
// we can then determine the base path
$candidateBasePath = rtrim(dirname(dirname(dirname(__FILE__))), DIRECTORY_SEPARATOR);
// We can't have an empty BASE_PATH. Making it / means that double-slashes occur in places but that's benign.
// This likely only happens on chrooted environemnts
@ -209,21 +220,20 @@ define('THEMES_DIR', 'themes');
define('THEMES_PATH', BASE_PATH . '/' . THEMES_DIR);
// Relies on this being in a subdir of the framework.
// If it isn't, or is symlinked to a folder with a different name, you must define FRAMEWORK_DIR
if(!defined('FRAMEWORK_DIR')) {
define('FRAMEWORK_DIR', basename(dirname(dirname(__FILE__))));
define('FRAMEWORK_PATH', realpath(__DIR__ . '/../'));
if(strpos(FRAMEWORK_PATH, BASE_PATH) === 0) {
define('FRAMEWORK_DIR', trim(substr(FRAMEWORK_PATH, strlen(BASE_PATH)), '/'));
$frameworkDirSlashSuffix = FRAMEWORK_DIR ? FRAMEWORK_DIR . '/' : '';
} else {
throw new Exception("Path error: FRAMEWORK_PATH " . FRAMEWORK_PATH . " not within BASE_PATH " . BASE_PATH);
}
define('FRAMEWORK_PATH', BASE_PATH . '/' . FRAMEWORK_DIR);
define('FRAMEWORK_ADMIN_DIR', FRAMEWORK_DIR . '/admin');
define('FRAMEWORK_ADMIN_PATH', BASE_PATH . '/' . FRAMEWORK_ADMIN_DIR);
// These are all deprecated. Use the FRAMEWORK_ versions instead.
define('SAPPHIRE_DIR', FRAMEWORK_DIR);
define('SAPPHIRE_PATH', FRAMEWORK_PATH);
define('SAPPHIRE_ADMIN_DIR', FRAMEWORK_ADMIN_DIR);
define('SAPPHIRE_ADMIN_PATH', FRAMEWORK_ADMIN_PATH);
define('FRAMEWORK_ADMIN_DIR', $frameworkDirSlashSuffix . 'admin');
define('FRAMEWORK_ADMIN_PATH', FRAMEWORK_PATH . '/admin');
define('THIRDPARTY_DIR', FRAMEWORK_DIR . '/thirdparty');
define('THIRDPARTY_PATH', BASE_PATH . '/' . THIRDPARTY_DIR);
define('THIRDPARTY_DIR', $frameworkDirSlashSuffix . 'thirdparty');
define('THIRDPARTY_PATH', FRAMEWORK_PATH . '/thirdparty');
define('ADMIN_THIRDPARTY_DIR', FRAMEWORK_ADMIN_DIR . '/thirdparty');
define('ADMIN_THIRDPARTY_PATH', BASE_PATH . '/' . ADMIN_THIRDPARTY_DIR);

View File

@ -226,6 +226,7 @@ class ConfigManifest {
$finder = new ManifestFileFinder();
$finder->setOptions(array(
'min_depth' => 0,
'name_regex' => '/(^|[\/\\\\])_config.php$/',
'ignore_tests' => !$includeTests,
'file_callback' => array($this, 'addSourceConfigFile')

View File

@ -39,6 +39,11 @@ class ManifestFileFinder extends FileFinder {
return false;
}
// Skip over the vendor directories
if (($depth == 1 || $depth == 2) && $basename == 'vendor') {
return false;
}
// If we're not in testing mode, then skip over any tests directories.
if ($this->getOption('ignore_tests') && $basename == self::TESTS_DIR) {
return false;
@ -57,6 +62,8 @@ class ManifestFileFinder extends FileFinder {
&& !($this->getOption('include_themes') && $basename == THEMES_DIR)
&& !file_exists($pathname . '/' . self::CONFIG_FILE)
&& !file_exists($pathname . '/' . self::CONFIG_DIR)
&& $basename !== self::CONFIG_DIR // include a root config dir
&& !file_exists("$pathname/../" . self::CONFIG_DIR) // include all paths if a root config dir exists
);
if ($lackingConfig) {

View File

@ -119,7 +119,7 @@ class GridFieldPrintButton implements GridField_HTMLProvider, GridField_ActionPr
public function handlePrint($gridField, $request = null) {
set_time_limit(60);
Requirements::clear();
Requirements::css(FRAMEWORK_DIR . '/client/dist/styles/GridField_print.css');
Requirements::css(ltrim(FRAMEWORK_DIR . '/client/dist/styles/GridField_print.css', '/'));
if($data = $this->generatePrintData($gridField)){
return $data->renderWith(get_class($gridField)."_print");

View File

@ -250,7 +250,7 @@ class HTMLEditorField_Toolbar extends RequestHandler
$remoteURL->addExtraClass('remoteurl');
$fromWeb->addExtraClass('content ss-uploadfield htmleditorfield-from-web');
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/AssetUploadField.css');
Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/AssetUploadField.css', '/'));
$computerUploadField = UploadField::create('AssetUploadField', '');
$computerUploadField->setConfig('previewMaxWidth', 40);
$computerUploadField->setConfig('previewMaxHeight', 30);

View File

@ -147,7 +147,7 @@ class UploadField_ItemHandler extends RequestHandler
return $this->httpError(403);
}
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/UploadField.css');
Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/UploadField.css', '/'));
return $this->customise(array(
'Form' => $this->EditForm()

View File

@ -60,7 +60,7 @@ class UploadField_SelectHandler extends RequestHandler
public function index()
{
// Requires a separate JS file, because we can't reach into the iframe with entwine.
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/UploadField_select.js');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/UploadField_select.js', '/'));
return $this->renderWith('SilverStripe\\Admin\\CMSDialog');
}

View File

@ -154,7 +154,7 @@ class ThemeManifest implements ThemeList {
$path = '/'.implode('/', $themeParts);
// If this is in the project, add to beginning of list. Else add to end.
if ($themeParts[0] == $this->project) {
if ($themeParts && $themeParts[0] == $this->project) {
array_unshift($this->themes, $path);
}
else {

View File

@ -95,19 +95,42 @@ class ThemeResourceLoader {
// <module> is always the name of the install directory, not necessarily the composer name.
$parts = explode(':', $identifier, 2);
list($vendor, $module) = explode('/', $parts[0], 2);
$theme = count($parts) > 1 ? $parts[1] : '';
if(count($parts) > 1) {
$theme = $parts[1];
// "module/vendor:/sub/path"
if($theme[0] === '/') {
$subpath = $theme;
$path = $module . ($theme ? '/themes/'.$theme : '');
// "module/vendor:subtheme"
} else {
$subpath = '/themes/' . $theme;
}
// Right now we require $module to be a silverstripe module (in root) or theme (in themes dir)
// If both exist, we prefer theme
if (is_dir(THEMES_PATH . '/' .$path)) {
return THEMES_DIR . '/' . $path;
// "module/vendor"
} else {
$subpath = '';
}
else {
return $path;
// To do: implement more flexible module path lookup
$package = $parts[0];
switch($package) {
case 'silverstripe/framework':
$modulePath = FRAMEWORK_DIR;
break;
case 'silverstripe/cms':
$modulePath = CMS_DIR;
break;
default:
list($vendor, $modulePath) = explode('/', $parts[0], 2);
// If the module is in the themes/<module>/ prefer that
if (is_dir(THEMES_PATH . '/' .$modulePath)) {
$modulePath = THEMES_DIR . '/' . $$modulePath;
}
}
return ltrim($modulePath . $subpath, '/');
}
// Otherwise it's a (deprecated) old-style "theme" identifier
else {
@ -196,24 +219,19 @@ class ThemeResourceLoader {
* @param array $themes List of themes
* @return string Path to resolved CSS file (relative to base dir)
*/
public function findThemedCSS($name, $themes)
{
$css = "/css/$name.css";
$paths = $this->getThemePaths($themes);
foreach ($paths as $themePath) {
$abspath = $this->base . '/' . $themePath;
public function findThemedCSS($name, $themes) {
if(substr($name, -4) !== '.css') $name .= '.css';
if (file_exists($abspath . $css)) {
return $themePath . $css;
}
$filename = $this->findThemedResource("css/$name", $themes);
if($filename === null) {
$filename = $this->findThemedResource($name, $themes);
}
// CSS exists in no context
return null;
return $filename;
}
/**
* Registers the given themeable javascript as required.
* Resolve themed javascript path
*
* A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for,
* and it that doesn't exist and the module parameter is set then a javascript file with that name in
@ -224,17 +242,40 @@ class ThemeResourceLoader {
* @return string Path to resolved javascript file (relative to base dir)
*/
public function findThemedJavascript($name, $themes) {
$js = "/javascript/$name.js";
if(substr($name, -3) !== '.js') $name .= '.js';
$filename = $this->findThemedResource("javascript/$name", $themes);
if($filename === null) {
$filename = $this->findThemedResource($name, $themes);
}
return $filename;
}
/**
* Resolve a themed resource
*
* A themed resource and be any file that resides in a theme folder.
*
* @param string $resource A file path relative to the root folder of a theme
* @param array $themes An order listed of themes to search
*/
public function findThemedResource($resource, $themes)
{
if($resource[0] !== '/') {
$resource = '/' . $resource;
}
$paths = $this->getThemePaths($themes);
foreach ($paths as $themePath) {
$abspath = $this->base . '/' . $themePath;
if (file_exists($abspath . $js)) {
return $themePath . $js;
if (file_exists($abspath . $resource)) {
return $themePath . $resource;
}
}
// js exists in no context
// Resource exists in no context
return null;
}

View File

@ -165,7 +165,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
* @var array
*/
private static $admin_themes = [
'/framework/admin/themes/cms-forms',
'silverstripe/framework:/admin/themes/cms-forms',
SSViewer::DEFAULT_THEME,
];
@ -536,12 +536,12 @@ class LeftAndMain extends Controller implements PermissionProvider {
window.ss.config = " . $this->getCombinedClientConfig() . ";
");
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js');
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/'));
Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/'));
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-legacy.js');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-legacy.js', '/'));
Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/client/lang', false, true);
Requirements::add_i18n_javascript(ltrim(FRAMEWORK_DIR . '/client/lang', '/'), false, true);
Requirements::add_i18n_javascript(FRAMEWORK_ADMIN_DIR . '/client/lang', false, true);
if ($this->config()->session_keepalive_ping) {

View File

@ -71,7 +71,7 @@ class MemberImportForm extends Form {
parent::__construct($controller, $name, $fields, $actions, $validator);
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/'));
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js');
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css');

View File

@ -233,9 +233,9 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
public function memberimport() {
Requirements::clear();
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js');
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js');
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/'));
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js', '/'));
Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/'));
return $this->renderWith('BlankPage', array(
'Form' => $this->MemberImportForm()->forTemplate(),
@ -267,9 +267,9 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
public function groupimport() {
Requirements::clear();
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js');
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js');
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css');
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/'));
Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js', '/'));
Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/'));
return $this->renderWith('BlankPage', array(
'Content' => ' ',

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

@ -24,7 +24,11 @@
"embed/embed": "^2.6"
},
"require-dev": {
"phpunit/PHPUnit": "~4.8"
"phpunit/PHPUnit": "~4.8",
"silverstripe/behat-extension": "^2.1.0",
"silverstripe/serve": "dev-master",
"silverstripe/testsession": "^2.0.0-alpha3",
"se/selenium-server-standalone": "2.41.0"
},
"extra": {
"branch-alias": {
@ -54,5 +58,7 @@
"include-path": [
"thirdparty/",
"thirdparty/HTML_BBCodeParser2/"
]
],
"min-stability": "dev",
"prefer-stable": true
}

View File

@ -57,17 +57,19 @@ if (version_compare(phpversion(), '5.5.0', '<')) {
* @see Director::direct()
*/
// require composers autoloader
if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) {
require_once $autoloadPath;
}
else {
if (!headers_sent()) {
header($_SERVER['SERVER_PROTOCOL'] . " 500 Server Error");
header('Content-Type: text/plain');
// require composers autoloader, unless it is already installed
if(!class_exists('Composer\\Autoload\\ClassLoader', false)) {
if (file_exists($autoloadPath = dirname(__DIR__) . '/vendor/autoload.php')) {
require_once $autoloadPath;
}
else {
if (!headers_sent()) {
header($_SERVER['SERVER_PROTOCOL'] . " 500 Server Error");
header('Content-Type: text/plain');
}
echo "Failed to include composer's autoloader, unable to continue\n";
exit(1);
}
echo "Failed to include composer's autoloader, unable to continue\n";
exit(1);
}
// IIS will sometimes generate this.

35
phpunit.xml.dist Normal file
View File

@ -0,0 +1,35 @@
<!--
PHPUnit configuration for SilverStripe
Requires PHPUnit 3.5+
Usage:
- "phpunit": Runs all tests in all folders
- "phpunit framework/tests/": Run all tests of the framework module
- "phpunit framework/tests/filesystem": Run all filesystem tests within the framework module
- "phpunit framework/tests/filesystem/FolderTest.php": Run a single test
- "phpunit <dash><dash>coverage-html assets/": Generate coverage report (replace <dash> with "-", requires xdebug)
More information:
- http://www.phpunit.de/manual/current/en/textui.html
- http://doc.silverstripe.org/framework/en/topics/testing/#configuration
It is safe to remove this file for normal website operation.
-->
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests</directory>
<directory>admin/tests</directory>
</testsuite>
<listeners>
<listener class="SilverStripe\Dev\TestListener" />
</listeners>
<groups>
<exclude>
<group>sanitychecks</group>
</exclude>
</groups>
</phpunit>

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">

23
tests/behat/config.yml Normal file
View File

@ -0,0 +1,23 @@
default:
context:
class: SilverStripe\Framework\Test\Behaviour\FeatureContext
filters:
tags: "~@todo"
formatter:
name: pretty
parameters:
snippets: false
extensions:
SilverStripe\BehatExtension\MinkExtension:
base_url: http://localhost:8080/
files_path: %behat.paths.base%/tests/behat/features/files/
default_session: selenium2
javascript_session: selenium2
selenium2:
browser: firefox
SilverStripe\BehatExtension\Extension:
screenshot_path: %behat.paths.base%/artifacts/screenshots
framework_path: "../.."
bootstrap_file: "tests/behat/serve-bootstrap.php"

View File

@ -0,0 +1,47 @@
<?php
// Asset folder
if(!file_exists(BASE_PATH . '/assets')) {
mkdir(BASE_PATH . '/assets', 02775);
}
// DATABASE BOOTSTRAP
if (!defined('SS_ENVIRONMENT_TYPE')) {
define('SS_ENVIRONMENT_TYPE', 'dev');
}
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
// The default settings let us define the database config via environment vars
// Database connection, including PDO and legacy ORM support
switch(getenv('DB')) {
case "PGSQL";
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
define('SS_DATABASE_USERNAME', 'postgres');
define('SS_DATABASE_PASSWORD', '');
break;
case "SQLITE":
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
define('SS_SQLITE_DATABASE_PATH', ':memory:');
break;
default:
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
}
define('SS_DATABASE_SERVER', '127.0.0.1');
define('SS_DATABASE_CHOOSE_NAME', true);
}
// Default database settings
global $database;
$database = '';
require_once(__DIR__ . '/../../conf/ConfigureFromEnv.php');
class Page extends SilverStripe\View\ViewableData {}
class Page_Controller extends SilverStripe\Control\Controller {}

View File

@ -21,8 +21,6 @@ $frameworkDir = basename($frameworkPath);
$_SERVER['SCRIPT_FILENAME'] = $frameworkPath . DIRECTORY_SEPARATOR . 'cli-script.php';
$_SERVER['SCRIPT_NAME'] = '.' . DIRECTORY_SEPARATOR . $frameworkDir . DIRECTORY_SEPARATOR . 'cli-script.php';
if(!defined('BASE_PATH')) define('BASE_PATH', dirname($frameworkPath));
// Copied from cli-script.php, to enable same behaviour through phpunit runner.
if(isset($_SERVER['argv'][2])) {
$args = array_slice($_SERVER['argv'],2);
@ -40,6 +38,58 @@ if(isset($_SERVER['argv'][2])) {
$_REQUEST = array_merge($_REQUEST, $_GET);
}
// DATABASE BOOTSTRAP
if (!defined('SS_ENVIRONMENT_TYPE')) {
define('SS_ENVIRONMENT_TYPE', 'dev');
}
if (!defined('SS_DATABASE_CLASS') && !defined('SS_DATABASE_USERNAME')) {
// The default settings let us define the database config via environment vars
// Database connection, including PDO and legacy ORM support
switch(getenv('DB')) {
case "PGSQL";
define('SS_DATABASE_CLASS', getenv('PDO') ? 'PostgrePDODatabase' : 'PostgreSQLDatabase');
define('SS_DATABASE_USERNAME', 'postgres');
define('SS_DATABASE_PASSWORD', '');
break;
case "SQLITE":
define('SS_DATABASE_CLASS', getenv('PDO') ? 'SQLite3PDODatabase' : 'SQLite3Database');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
define('SS_SQLITE_DATABASE_PATH', ':memory:');
break;
default:
define('SS_DATABASE_CLASS', getenv('PDO') ? 'MySQLPDODatabase' : 'MySQLDatabase');
define('SS_DATABASE_USERNAME', 'root');
define('SS_DATABASE_PASSWORD', '');
}
define('SS_DATABASE_SERVER', '127.0.0.1');
define('SS_DATABASE_CHOOSE_NAME', true);
}
// Ensure Director::protocolAndHost() works
if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = 'localhost';
}
// Asset folder
if(!file_exists(BASE_PATH . '/assets')) {
mkdir(BASE_PATH . '/assets', 02775);
}
// Default database settings
global $project;
$project = 'mysite';
global $database;
$database = '';
require_once(__DIR__ . '/../conf/ConfigureFromEnv.php');
// Connect to database
require_once $frameworkPath . '/Core/Core.php';
require_once $frameworkPath . '/tests/FakeController.php';

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

@ -327,8 +327,9 @@ class HTTPTest extends FunctionalTest {
public function testFilename2url() {
$this->withBaseURL('http://www.silverstripe.org/', function($test) {
$frameworkTests = ltrim(FRAMEWORK_DIR . '/tests', '/');
$test->assertEquals(
'http://www.silverstripe.org/framework/tests/control/HTTPTest.php',
"http://www.silverstripe.org/$frameworkTests/control/HTTPTest.php",
HTTP::filename2url(__FILE__)
);
});

View File

@ -78,7 +78,7 @@ class ClassInfoTest extends SapphireTest {
//$baseFolder = Director::baseFolder() . '/' . FRAMEWORK_DIR . '/tests/_ClassInfoTest';
//$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
$classes = ClassInfo::classes_for_folder(FRAMEWORK_DIR . '/tests');
$classes = ClassInfo::classes_for_folder(ltrim(FRAMEWORK_DIR . '/tests', '/'));
$this->assertContains(
'classinfotest',
$classes,

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);