function testDateFormatCustom() { i18n::set_locale('en_US'); $this->assertEquals('MMM d, yyyy', i18n::get_date_format()); i18n::set_date_format('d/MM/yyyy'); $this->assertEquals('d/MM/yyyy', i18n::get_date_format()); }
public function init() { parent::init(); i18n::set_locale('de_DE'); setlocale(LC_ALL, 'de_DE@euro', 'de_DE.UTF-8', 'de_DE', 'de', 'ge'); i18n::set_date_format('dd.MM.YYYY'); i18n::set_time_format('HH:mm'); Requirements::set_write_js_to_body(false); Requirements::javascript("framework/thirdparty/jquery/jquery.js"); Requirements::javascript("calendar/3rdparty/jquery-ui-1.9.2.custom.js"); Requirements::javascript("calendar/3rdparty/fullcalendar/fullcalendar.js"); Requirements::javascript("calendar/3rdparty/jQuery-Loading/toggleLoading.jquery.js"); Requirements::javascript("calendar/javascript/widget.js"); Requirements::css("framework/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css"); Requirements::css("calendar/3rdparty/fullcalendar/fullcalendar.css"); Requirements::css("calendar/css/calendar.css"); }
/** * @uses LeftAndMainExtension->init() * @uses LeftAndMainExtension->accessedCMS() * @uses CMSMenu */ function init() { parent::init(); SSViewer::setOption('rewriteHashlinks', false); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } if (!empty($member->DateFormat)) { i18n::set_date_format($member->DateFormat); } if (!empty($member->TimeFormat)) { i18n::set_time_format($member->TimeFormat); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', 'Menu title'), self::$help_link); // Allow customisation of the access check by a extension // Also all the canView() check to execute Controller::redirect() if (!$this->canView() && !$this->response->isFinished()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach ($menu as $candidate) { if ($candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView()) { return $this->redirect($candidate->Link); } } if (Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if ($this->redirectedTo()) { return; } // Audit logging hook if (empty($_REQUEST['executeForm']) && !$this->request->isAjax()) { $this->extend('accessedCMS'); } // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); // Set default values in the config if missing. These things can't be defined in the config // file because insufficient information exists when that is being processed $htmlEditorConfig = HtmlEditorConfig::get_active(); $htmlEditorConfig->setOption('language', i18n::get_tinymce_lang()); if (!$htmlEditorConfig->getOption('content_css')) { $cssFiles = array(); $cssFiles[] = FRAMEWORK_ADMIN_DIR . '/css/editor.css'; // Use theme from the site config if (class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { $cssFiles[] = THEMES_DIR . "/{$theme}/css/editor.css"; } else { if (project()) { $cssFiles[] = project() . '/css/editor.css'; } } // Remove files that don't exist foreach ($cssFiles as $k => $cssFile) { if (!file_exists(BASE_PATH . '/' . $cssFile)) { unset($cssFiles[$k]); } } $htmlEditorConfig->setOption('content_css', implode(',', $cssFiles)); } // Using uncompressed files as they'll be processed by JSMin in the Requirements class. // Not as effective as other compressors or pre-compressed+finetuned files, // but overall the unified minification into a single file brings more performance benefits // than a couple of saved bytes (after gzip) in individual files. // We also re-compress already compressed files through JSMin as this causes weird runtime bugs. Requirements::combine_files('lib.js', array(THIRDPARTY_DIR . '/jquery/jquery.js', FRAMEWORK_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js', FRAMEWORK_ADMIN_DIR . '/javascript/lib.js', THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js', THIRDPARTY_DIR . '/json-js/json2.js', THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js', THIRDPARTY_DIR . '/jquery-cookie/jquery.cookie.js', THIRDPARTY_DIR . '/jquery-query/jquery.query.js', THIRDPARTY_DIR . '/jquery-form/jquery.form.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/jsizes/lib/jquery.sizes.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/jlayout/lib/jlayout.border.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js', THIRDPARTY_DIR . '/jstree/jquery.jstree.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js', FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js', FRAMEWORK_ADMIN_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js', FRAMEWORK_DIR . '/javascript/TreeDropdownField.js', FRAMEWORK_DIR . '/javascript/DateField.js', FRAMEWORK_DIR . '/javascript/HtmlEditorField.js', FRAMEWORK_DIR . '/javascript/TabSet.js', FRAMEWORK_DIR . '/javascript/i18n.js', FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js', FRAMEWORK_DIR . '/javascript/GridField.js')); if (Director::isDev()) { Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/leaktools.js'); } HTMLEditorField::include_js(); Requirements::combine_files('leftandmain.js', array_unique(array_merge(array(FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Content.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.AddForm.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.Preview.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.BatchActions.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.FieldHelp.js', FRAMEWORK_ADMIN_DIR . '/javascript/LeftAndMain.TreeDropdownField.js'), Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang', true, true), Requirements::add_i18n_javascript(FRAMEWORK_ADMIN_DIR . '/javascript/lang', true, true)))); // TODO Confuses jQuery.ondemand through document.write() if (Director::isDev()) { Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/src/jquery.entwine.inspector.js'); } Requirements::css(FRAMEWORK_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.css'); Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.css'); Requirements::css(THIRDPARTY_DIR . '/jstree/themes/apple/style.css'); Requirements::css(FRAMEWORK_DIR . '/css/TreeDropdownField.css'); Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/screen.css'); Requirements::css(FRAMEWORK_DIR . '/css/GridField.css'); // Browser-specific requirements $ie = isset($_SERVER['HTTP_USER_AGENT']) ? strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') : false; if ($ie) { $version = substr($_SERVER['HTTP_USER_AGENT'], $ie + 5, 3); if ($version == 7) { Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/ie7.css'); } else { if ($version == 8) { Requirements::css(FRAMEWORK_ADMIN_DIR . '/css/ie8.css'); } } } // Custom requirements foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::themedCSS($file[0], $file[1]); } $dummy = null; $this->extend('init', $dummy); // The user's theme shouldn't affect the CMS, if, for example, they have replaced // TableListField.ss or Form.ss. SSViewer::set_theme(null); }
function setUp() { // Mark test as being run $this->originalIsRunningTest = self::$is_running_test; self::$is_running_test = true; // i18n needs to be set to the defaults or tests fail i18n::set_locale(i18n::default_locale()); i18n::set_date_format(null); i18n::set_time_format(null); // Remove password validation $this->originalMemberPasswordValidator = Member::password_validator(); $this->originalRequirements = Requirements::backend(); Member::set_password_validator(null); Cookie::set_report_errors(false); RootURLController::reset(); Translatable::reset(); Versioned::reset(); DataObject::reset(); SiteTree::reset(); Hierarchy::reset(); if (Controller::has_curr()) { Controller::curr()->setSession(new Session(array())); } $this->originalTheme = SSViewer::current_theme(); // Save nested_urls state, so we can restore it later $this->originalNestedURLsState = SiteTree::nested_urls(); $className = get_class($this); $fixtureFile = eval("return {$className}::\$fixture_file;"); $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_'; // Set up fixture if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) { if (substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) { //echo "Re-creating temp database... "; self::create_temp_db(); //echo "done.\n"; } singleton('DataObject')->flushCache(); self::empty_temp_db(); foreach ($this->requireDefaultRecordsFrom as $className) { $instance = singleton($className); if (method_exists($instance, 'requireDefaultRecords')) { $instance->requireDefaultRecords(); } if (method_exists($instance, 'augmentDefaultRecords')) { $instance->augmentDefaultRecords(); } } if ($fixtureFile) { $fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile); $i = 0; foreach ($fixtureFiles as $fixtureFilePath) { $fixture = new YamlFixture($fixtureFilePath); $fixture->saveIntoDatabase(); $this->fixtures[] = $fixture; // backwards compatibility: Load first fixture into $this->fixture if ($i == 0) { $this->fixture = $fixture; } $i++; } } $this->logInWithPermission("ADMIN"); } // Set up email $this->originalMailer = Email::mailer(); $this->mailer = new TestMailer(); Email::set_mailer($this->mailer); Email::send_all_emails_to(null); // Preserve memory settings $this->originalMemoryLimit = ini_get('memory_limit'); }
/** * @uses LeftAndMainDecorator->init() * @uses LeftAndMainDecorator->accessedCMS() * @uses CMSMenu */ function init() { parent::init(); SSViewer::setOption('rewriteHashlinks', false); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } if (!empty($member->DateFormat)) { i18n::set_date_format($member->DateFormat); } if (!empty($member->TimeFormat)) { i18n::set_time_format($member->TimeFormat); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', PR_HIGH, 'Menu title'), self::$help_link); // set reading lang if (Object::has_extension('SiteTree', 'Translatable') && !$this->isAjax()) { Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } // Allow customisation of the access check by a decorator // Also all the canView() check to execute Director::redirect() if (!$this->canView() && !$this->response->isFinished()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach ($menu as $candidate) { if ($candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView()) { return Director::redirect($candidate->Link); } } if (Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if (Director::redirected_to()) { return; } // Audit logging hook if (empty($_REQUEST['executeForm']) && !$this->isAjax()) { $this->extend('accessedCMS'); } // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); // Set default values in the config if missing. These things can't be defined in the config // file because insufficient information exists when that is being processed $htmlEditorConfig = HtmlEditorConfig::get_active(); $htmlEditorConfig->setOption('language', i18n::get_tinymce_lang()); if (!$htmlEditorConfig->getOption('content_css')) { $cssFiles = 'cms/css/editor.css'; // Use theme from the site config if (($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { $cssFiles .= ',' . THEMES_DIR . "/{$theme}/css/editor.css"; } else { if (project()) { $cssFiles .= ',' . project() . '/css/editor.css'; } } $htmlEditorConfig->setOption('content_css', $cssFiles); } Requirements::css(CMS_DIR . '/css/typography.css'); Requirements::css(CMS_DIR . '/css/layout.css'); Requirements::css(CMS_DIR . '/css/cms_left.css'); Requirements::css(CMS_DIR . '/css/cms_right.css'); Requirements::css(SAPPHIRE_DIR . '/css/Form.css'); if (isset($_REQUEST['debug_firebug'])) { // Firebug is a useful console for debugging javascript // Its available as a Firefox extension or a javascript library // for easy inclusion in other browsers (just append ?debug_firebug=1 to the URL) Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebug.js'); } else { // By default, we include fake-objects for all firebug calls // to avoid javascript errors when referencing console.log() etc in javascript code Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/firebug-lite/firebugx.js'); } Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototypefix/intro.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototypefix/outro.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery_improvements.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); //import all of jquery ui Requirements::javascript(CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.js'); Requirements::javascript(CMS_DIR . '/thirdparty/jquery-layout/jquery.layout.state.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/json-js/json2.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-metadata/jquery.metadata.js'); Requirements::javascript(CMS_DIR . '/javascript/jquery-fitheighttoparent/jquery.fitheighttoparent.js'); Requirements::javascript(CMS_DIR . '/javascript/ssui.core.js'); // @todo Load separately so the CSS files can be inlined Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery.ui.all.css'); // entwine Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); // Required for TreeTools panel above tree Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js'); Requirements::javascript(CMS_DIR . '/thirdparty/jquery-notice/jquery.notice.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js'); Requirements::javascript(CMS_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js'); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/dragdrop.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/controls.js'); Requirements::javascript(THIRDPARTY_DIR . '/tree/tree.js'); Requirements::css(THIRDPARTY_DIR . '/tree/tree.css'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.Tree.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.AddForm.js'); Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.BatchActions.js'); // navigator Requirements::css(SAPPHIRE_DIR . '/css/SilverStripeNavigator.css'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/SilverStripeNavigator.js'); Requirements::themedCSS('typography'); foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::themedCSS($file[0], $file[1]); } Requirements::css(CMS_DIR . '/css/unjquery.css'); // Javascript combined files Requirements::combine_files('base.js', array('sapphire/thirdparty/prototype/prototype.js', 'sapphire/thirdparty/behaviour/behaviour.js', 'sapphire/thirdparty/jquery/jquery.js', 'sapphire/thirdparty/jquery-livequery/jquery.livequery.js', 'sapphire/javascript/jquery-ondemand/jquery.ondemand.js', 'sapphire/thirdparty/jquery-ui/jquery-ui.js', 'sapphire/thirdparty/firebug-lite/firebug.js', 'sapphire/thirdparty/firebug-lite/firebugx.js', 'sapphire/javascript/i18n.js')); Requirements::combine_files('leftandmain.js', array('sapphire/thirdparty/scriptaculous/effects.js', 'sapphire/thirdparty/scriptaculous/dragdrop.js', 'sapphire/thirdparty/scriptaculous/controls.js', 'cms/javascript/LeftAndMain.js', 'sapphire/javascript/tree/tree.js', 'sapphire/javascript/TreeSelectorField.js', 'cms/javascript/ThumbnailStripField.js')); $dummy = null; $this->extend('init', $dummy); // The user's theme shouldn't affect the CMS, if, for example, they have replaced // TableListField.ss or Form.ss. SSViewer::set_theme(null); }
public function setUp() { // We cannot run the tests on this abstract class. if (get_class($this) == "SapphireTest") { $this->skipTest = true; } if ($this->skipTest) { $this->markTestSkipped(sprintf('Skipping %s ', get_class($this))); return; } // Mark test as being run $this->originalIsRunningTest = self::$is_running_test; self::$is_running_test = true; // i18n needs to be set to the defaults or tests fail i18n::set_locale(i18n::default_locale()); i18n::set_date_format(null); i18n::set_time_format(null); // Set default timezone consistently to avoid NZ-specific dependencies date_default_timezone_set('UTC'); // Remove password validation $this->originalMemberPasswordValidator = Member::password_validator(); $this->originalRequirements = Requirements::backend(); Member::set_password_validator(null); Cookie::set_report_errors(false); if (class_exists('RootURLController')) { RootURLController::reset(); } if (class_exists('Translatable')) { Translatable::reset(); } Versioned::reset(); DataObject::reset(); if (class_exists('SiteTree')) { SiteTree::reset(); } Hierarchy::reset(); if (Controller::has_curr()) { Controller::curr()->setSession(new Session(array())); } Security::$database_is_ready = null; $this->originalTheme = SSViewer::current_theme(); if (class_exists('SiteTree')) { // Save nested_urls state, so we can restore it later $this->originalNestedURLsState = SiteTree::nested_urls(); } $className = get_class($this); $fixtureFile = eval("return {$className}::\$fixture_file;"); $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_'; // Todo: this could be a special test model $this->model = DataModel::inst(); // Set up fixture if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) { if (substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) { //echo "Re-creating temp database... "; self::create_temp_db(); //echo "done.\n"; } singleton('DataObject')->flushCache(); self::empty_temp_db(); foreach ($this->requireDefaultRecordsFrom as $className) { $instance = singleton($className); if (method_exists($instance, 'requireDefaultRecords')) { $instance->requireDefaultRecords(); } if (method_exists($instance, 'augmentDefaultRecords')) { $instance->augmentDefaultRecords(); } } if ($fixtureFile) { $pathForClass = $this->getCurrentAbsolutePath(); $fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile); $i = 0; foreach ($fixtureFiles as $fixtureFilePath) { // Support fixture paths relative to the test class, rather than relative to webroot // String checking is faster than file_exists() calls. $isRelativeToFile = strpos('/', $fixtureFilePath) === false || preg_match('/^\\.\\./', $fixtureFilePath); if ($isRelativeToFile) { $resolvedPath = realpath($pathForClass . '/' . $fixtureFilePath); if ($resolvedPath) { $fixtureFilePath = $resolvedPath; } } $fixture = new YamlFixture($fixtureFilePath); $fixture->saveIntoDatabase($this->model); $this->fixtures[] = $fixture; // backwards compatibility: Load first fixture into $this->fixture if ($i == 0) { $this->fixture = $fixture; } $i++; } } $this->logInWithPermission("ADMIN"); } // Set up email $this->originalMailer = Email::mailer(); $this->mailer = new TestMailer(); Email::set_mailer($this->mailer); Email::send_all_emails_to(null); // Preserve memory settings $this->originalMemoryLimit = ini_get('memory_limit'); // turn off template debugging SSViewer::set_source_file_comments(false); // Clear requirements Requirements::clear(); }
/** * @uses LeftAndMainExtension->init() * @uses LeftAndMainExtension->accessedCMS() * @uses CMSMenu */ function init() { parent::init(); SSViewer::setOption('rewriteHashlinks', false); // set language $member = Member::currentUser(); if (!empty($member->Locale)) { i18n::set_locale($member->Locale); } if (!empty($member->DateFormat)) { i18n::set_date_format($member->DateFormat); } if (!empty($member->TimeFormat)) { i18n::set_time_format($member->TimeFormat); } // can't be done in cms/_config.php as locale is not set yet CMSMenu::add_link('Help', _t('LeftAndMain.HELP', 'Help', PR_HIGH, 'Menu title'), self::$help_link); // Allow customisation of the access check by a extension // Also all the canView() check to execute Director::redirect() if (!$this->canView() && !$this->response->isFinished()) { // When access /admin/, we should try a redirect to another part of the admin rather than be locked out $menu = $this->MainMenu(); foreach ($menu as $candidate) { if ($candidate->Link && $candidate->Link != $this->Link() && $candidate->MenuItem->controller && singleton($candidate->MenuItem->controller)->canView()) { return Director::redirect($candidate->Link); } } if (Member::currentUser()) { Session::set("BackURL", null); } // if no alternate menu items have matched, return a permission error $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "Please choose an authentication method and enter your credentials to access the CMS."), 'alreadyLoggedIn' => _t('LeftAndMain.PERMALREADY', "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"), 'logInAgain' => _t('LeftAndMain.PERMAGAIN', "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.")); return Security::permissionFailure($this, $messageSet); } // Don't continue if there's already been a redirection request. if (Director::redirected_to()) { return; } // Audit logging hook if (empty($_REQUEST['executeForm']) && !$this->isAjax()) { $this->extend('accessedCMS'); } // Requirements Requirements::combine_files('lib.js', array(THIRDPARTY_DIR . '/prototype/prototype.js', THIRDPARTY_DIR . '/behaviour/behaviour.js', THIRDPARTY_DIR . '/jquery/jquery.js', SAPPHIRE_DIR . '/javascript/jquery_improvements.js', THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js', SAPPHIRE_DIR . '/javascript/jquery-ondemand/jquery.ondemand.js', THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js', THIRDPARTY_DIR . '/json-js/json2.js', THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js', THIRDPARTY_DIR . '/jquery-cookie/jquery.cookie.js', THIRDPARTY_DIR . '/jquery-query/jquery.query.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-notice/jquery.notice.js', THIRDPARTY_DIR . '/jquery-metadata/jquery.metadata.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jsizes/lib/jquery.sizes.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jlayout.border.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js', THIRDPARTY_DIR . '/jstree/jquery.jstree.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js', SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js', SAPPHIRE_ADMIN_DIR . '/javascript/jquery-changetracker/lib/jquery.changetracker.js', SAPPHIRE_DIR . '/javascript/TreeDropdownField.js', SAPPHIRE_DIR . "/thirdparty/jquery-form/jquery.form.js", SAPPHIRE_DIR . '/javascript/DateField.js', SAPPHIRE_DIR . '/javascript/HtmlEditorField.js', SAPPHIRE_DIR . '/javascript/TabSet.js', SAPPHIRE_DIR . '/javascript/Validator.js', SAPPHIRE_DIR . '/javascript/i18n.js', SAPPHIRE_ADMIN_DIR . '/javascript/ssui.core.js')); Requirements::combine_files('leftandmain.js', array(SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Panel.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Tree.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Ping.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Content.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.EditForm.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Menu.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.AddForm.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.Preview.js', SAPPHIRE_ADMIN_DIR . '/javascript/LeftAndMain.BatchActions.js')); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(SAPPHIRE_ADMIN_DIR . '/javascript/lang'); Requirements::combine_files('lib.css', array(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css', SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.css', THIRDPARTY_DIR . '/jstree/themes/apple/style.css', SAPPHIRE_DIR . '/javascript/TreeDropdownField.css', SAPPHIRE_ADMIN_DIR . '/css/unjquery.css')); Requirements::css(SAPPHIRE_ADMIN_DIR . '/css/screen.css'); // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); // Set default values in the config if missing. These things can't be defined in the config // file because insufficient information exists when that is being processed $htmlEditorConfig = HtmlEditorConfig::get_active(); $htmlEditorConfig->setOption('language', i18n::get_tinymce_lang()); if (!$htmlEditorConfig->getOption('content_css')) { $cssFiles = array(); $cssFiles[] = 'sapphire/admin/css/editor.css'; // Use theme from the site config if (class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { $cssFiles[] = THEMES_DIR . "/{$theme}/css/editor.css"; } else { if (project()) { $cssFiles[] = project() . '/css/editor.css'; } } // Remove files that don't exist foreach ($cssFiles as $k => $cssFile) { if (!file_exists(BASE_PATH . '/' . $cssFile)) { unset($cssFiles[$k]); } } $htmlEditorConfig->setOption('content_css', implode(',', $cssFiles)); } foreach (self::$extra_requirements['javascript'] as $file) { Requirements::javascript($file[0]); } foreach (self::$extra_requirements['css'] as $file) { Requirements::css($file[0], $file[1]); } foreach (self::$extra_requirements['themedcss'] as $file) { Requirements::themedCSS($file[0], $file[1]); } $dummy = null; $this->extend('init', $dummy); // The user's theme shouldn't affect the CMS, if, for example, they have replaced // TableListField.ss or Form.ss. SSViewer::set_theme(null); }