public function setUp()
 {
     parent::setUp();
     Director::config()->update('rules', array('FormTest_Controller' => 'FormTest_Controller'));
     // Suppress themes
     SSViewer::config()->remove('theme');
 }
 public function setUp()
 {
     // Skip calling FunctionalTest directly.
     if (get_class($this) == __CLASS__) {
         $this->markTestSkipped(sprintf('Skipping %s ', get_class($this)));
     }
     parent::setUp();
     $this->mainSession = new TestSession();
     // Disable theme, if necessary
     if (static::get_disable_themes()) {
         SSViewer::config()->update('theme_enabled', false);
     }
     // Switch to draft site, if necessary
     if (static::get_use_draft_site()) {
         $this->useDraftSite();
     }
     // Unprotect the site, tests are running with the assumption it's off. They will enable it on a case-by-case
     // basis.
     BasicAuth::protect_entire_site(false);
     SecurityToken::disable();
 }
 public function parseTemplateContent($content, $template = "")
 {
     return $this->getParser()->compileString($content, $template, Director::isDev() && SSViewer::config()->get('source_file_comments'));
 }
 /**
  * @uses LeftAndMainExtension->init()
  * @uses LeftAndMainExtension->accessedCMS()
  * @uses CMSMenu
  */
 protected function init()
 {
     parent::init();
     SSViewer::config()->update('rewrite_hash_links', false);
     ContentNegotiator::config()->update('enabled', false);
     // set language
     $member = Member::currentUser();
     if (!empty($member->Locale)) {
         i18n::set_locale($member->Locale);
     }
     if (!empty($member->DateFormat)) {
         i18n::config()->date_format = $member->DateFormat;
     }
     if (!empty($member->TimeFormat)) {
         i18n::config()->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'), $this->config()->help_link, -2, array('target' => '_blank'));
     // Allow customisation of the access check by a extension
     // Also all the canView() check to execute Controller::redirect()
     if (!$this->canView() && !$this->getResponse()->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()) {
                 $this->redirect($candidate->Link);
                 return;
             }
         }
         if (Member::currentUser()) {
             Session::set("BackURL", null);
         }
         // if no alternate menu items have matched, return a permission error
         $messageSet = array('default' => _t('LeftAndMain.PERMDEFAULT', "You must be logged in to access the administration area; please enter your credentials below."), '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."));
         Security::permissionFailure($this, $messageSet);
         return;
     }
     // Don't continue if there's already been a redirection request.
     if ($this->redirectedTo()) {
         return;
     }
     // Audit logging hook
     if (empty($_REQUEST['executeForm']) && !$this->getRequest()->isAjax()) {
         $this->extend('accessedCMS');
     }
     // Set the members html editor config
     if (Member::currentUser()) {
         HTMLEditorConfig::set_active_identifier(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());
     Requirements::customScript("\n\t\t\twindow.ss = window.ss || {};\n\t\t\twindow.ss.config = " . $this->getCombinedClientConfig() . ";\n\t\t");
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/vendor.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle.js');
     Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/'));
     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) {
         Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/LeftAndMain.Ping.js');
     }
     if (Director::isDev()) {
         // TODO Confuses jQuery.ondemand through document.write()
         Requirements::javascript(ADMIN_THIRDPARTY_DIR . '/jquery-entwine/src/jquery.entwine.inspector.js');
         Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/leaktools.js');
     }
     // Custom requirements
     $extraJs = $this->stat('extra_requirements_javascript');
     if ($extraJs) {
         foreach ($extraJs as $file => $config) {
             if (is_numeric($file)) {
                 $file = $config;
             }
             Requirements::javascript($file);
         }
     }
     $extraCss = $this->stat('extra_requirements_css');
     if ($extraCss) {
         foreach ($extraCss as $file => $config) {
             if (is_numeric($file)) {
                 $file = $config;
                 $config = array();
             }
             Requirements::css($file, isset($config['media']) ? $config['media'] : null);
         }
     }
     $extraThemedCss = $this->stat('extra_requirements_themedCss');
     if ($extraThemedCss) {
         foreach ($extraThemedCss as $file => $config) {
             if (is_numeric($file)) {
                 $file = $config;
                 $config = array();
             }
             Requirements::themedCSS($file, isset($config['media']) ? $config['media'] : null);
         }
     }
     $dummy = null;
     $this->extend('init', $dummy);
     // Assign default cms theme and replace user-specified themes
     SSViewer::set_themes($this->config()->admin_themes);
     //set the reading mode for the admin to stage
     Versioned::set_stage(Versioned::DRAFT);
 }
 /**
  * Test against a theme.
  *
  * @param string $themeBaseDir themes directory
  * @param string $theme Theme name
  * @param callable $callback
  * @throws Exception
  */
 protected function useTestTheme($themeBaseDir, $theme, $callback)
 {
     Config::nest();
     if (strpos($themeBaseDir, BASE_PATH) === 0) {
         $themeBaseDir = substr($themeBaseDir, strlen(BASE_PATH));
     }
     SSViewer::config()->update('theme_enabled', true);
     SSViewer::set_themes([$themeBaseDir . '/themes/' . $theme, '$default']);
     $e = null;
     try {
         $callback();
     } catch (Exception $e) {
         /* NOP for now, just save $e */
     }
     Config::unnest();
     if ($e) {
         throw $e;
     }
 }
 function CacheBlock_CacheBlockTemplate(&$res, $sub)
 {
     // Get the block counter
     $block = ++$res['subblocks'];
     // Build the key for this block from the global key (evaluated in a closure within the template),
     // the passed cache key, the block index, and the sha hash of the template.
     $res['php'] .= '$keyExpression = function() use ($scope, $cache) {' . PHP_EOL;
     $res['php'] .= '$val = \'\';' . PHP_EOL;
     if ($globalKey = SSViewer::config()->get('global_key')) {
         // Embed the code necessary to evaluate the globalKey directly into the template,
         // so that SSTemplateParser only needs to be called during template regeneration.
         // Warning: If the global key is changed, it's necessary to flush the template cache.
         $parser = Injector::inst()->get(__CLASS__, false);
         $result = $parser->compileString($globalKey, '', false, false);
         if (!$result) {
             throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
         }
         $res['php'] .= $result . PHP_EOL;
     }
     $res['php'] .= 'return $val;' . PHP_EOL;
     $res['php'] .= '};' . PHP_EOL;
     $key = 'sha1($keyExpression())' . '.\'_' . sha1($sub['php']) . (isset($res['key']) && $res['key'] ? "_'.sha1(" . $res['key'] . ")" : "'") . ".'_{$block}'";
     // block index
     // Get any condition
     $condition = isset($res['condition']) ? $res['condition'] : '';
     $res['php'] .= 'if (' . $condition . '($partial = $cache->load(' . $key . '))) $val .= $partial;' . PHP_EOL;
     $res['php'] .= 'else { $oldval = $val; $val = "";' . PHP_EOL;
     $res['php'] .= $sub['php'] . PHP_EOL;
     $res['php'] .= $condition . ' $cache->save($val); $val = $oldval . $val;' . PHP_EOL;
     $res['php'] .= '}';
 }
 /**
  * Returns a json array of a search results that can be used by for example Jquery.ui.autosuggestion
  *
  * @param GridField $gridField
  * @param HTTPRequest $request
  * @return string
  */
 public function doSearch($gridField, $request)
 {
     $dataClass = $gridField->getModelClass();
     $allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
     $searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
     if (!$searchFields) {
         throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
     }
     $params = array();
     foreach ($searchFields as $searchField) {
         $name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:StartsWith";
         $params[$name] = $request->getVar('gridfield_relationsearch');
     }
     $results = $allList->subtract($gridField->getList())->filterAny($params)->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getResultsLimit());
     $json = array();
     Config::nest();
     SSViewer::config()->update('source_file_comments', false);
     $viewer = SSViewer::fromString($this->resultsFormat);
     foreach ($results as $result) {
         $title = html_entity_decode($viewer->process($result));
         $json[] = array('label' => $title, 'value' => $title, 'id' => $result->ID);
     }
     Config::unnest();
     return Convert::array2json($json);
 }
 public function testRenderWithSourceFileComments()
 {
     Director::config()->update('environment_type', 'dev');
     SSViewer::config()->update('source_file_comments', true);
     $i = FRAMEWORK_PATH . '/tests/templates/Includes';
     $f = FRAMEWORK_PATH . '/tests/templates/SSViewerTestComments';
     $templates = array(array('name' => 'SSViewerTestCommentsFullSource', 'expected' => "" . "<!doctype html>" . "<!-- template {$f}/SSViewerTestCommentsFullSource.ss -->" . "<html>" . "\t<head></head>" . "\t<body></body>" . "</html>" . "<!-- end template {$f}/SSViewerTestCommentsFullSource.ss -->"), array('name' => 'SSViewerTestCommentsFullSourceHTML4Doctype', 'expected' => "" . "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML " . "4.01//EN\"\t\t\"http://www.w3.org/TR/html4/strict.dtd\">" . "<!-- template {$f}/SSViewerTestCommentsFullSourceHTML4Doctype.ss -->" . "<html>" . "\t<head></head>" . "\t<body></body>" . "</html>" . "<!-- end template {$f}/SSViewerTestCommentsFullSourceHTML4Doctype.ss -->"), array('name' => 'SSViewerTestCommentsFullSourceNoDoctype', 'expected' => "" . "<html><!-- template {$f}/SSViewerTestCommentsFullSourceNoDoctype.ss -->" . "\t<head></head>" . "\t<body></body>" . "<!-- end template {$f}/SSViewerTestCommentsFullSourceNoDoctype.ss --></html>"), array('name' => 'SSViewerTestCommentsFullSourceIfIE', 'expected' => "" . "<!doctype html>" . "<!-- template {$f}/SSViewerTestCommentsFullSourceIfIE.ss -->" . "<!--[if lte IE 8]> <html class='old-ie'> <![endif]-->" . "<!--[if gt IE 8]> <html class='new-ie'> <![endif]-->" . "<!--[if !IE]><!--> <html class='no-ie'> <!--<![endif]-->" . "\t<head></head>" . "\t<body></body>" . "</html>" . "<!-- end template {$f}/SSViewerTestCommentsFullSourceIfIE.ss -->"), array('name' => 'SSViewerTestCommentsFullSourceIfIENoDoctype', 'expected' => "" . "<!--[if lte IE 8]> <html class='old-ie'> <![endif]-->" . "<!--[if gt IE 8]> <html class='new-ie'> <![endif]-->" . "<!--[if !IE]><!--> <html class='no-ie'>" . "<!-- template {$f}/SSViewerTestCommentsFullSourceIfIENoDoctype.ss -->" . " <!--<![endif]-->" . "\t<head></head>" . "\t<body></body>" . "<!-- end template {$f}/SSViewerTestCommentsFullSourceIfIENoDoctype.ss --></html>"), array('name' => 'SSViewerTestCommentsPartialSource', 'expected' => "<!-- template {$f}/SSViewerTestCommentsPartialSource.ss -->" . "<div class='typography'></div>" . "<!-- end template {$f}/SSViewerTestCommentsPartialSource.ss -->"), array('name' => 'SSViewerTestCommentsWithInclude', 'expected' => "<!-- template {$f}/SSViewerTestCommentsWithInclude.ss -->" . "<div class='typography'>" . "<!-- include 'SSViewerTestCommentsInclude' -->" . "<!-- template {$i}/SSViewerTestCommentsInclude.ss -->" . "Included" . "<!-- end template {$i}/SSViewerTestCommentsInclude.ss -->" . "<!-- end include 'SSViewerTestCommentsInclude' -->" . "</div>" . "<!-- end template {$f}/SSViewerTestCommentsWithInclude.ss -->"));
     foreach ($templates as $template) {
         $this->_renderWithSourceFileComments('SSViewerTestComments/' . $template['name'], $template['expected']);
     }
 }
Ejemplo n.º 9
0
 /**
  * Output the feed to the browser.
  *
  * TODO: Pass $response object to ->outputToBrowser() to loosen dependence on global state for easier testing/prototyping so dev can inject custom HTTPResponse instance.
  *
  * @return DBHTMLText
  */
 public function outputToBrowser()
 {
     $prevState = SSViewer::config()->get('source_file_comments');
     SSViewer::config()->update('source_file_comments', false);
     $response = Controller::curr()->getResponse();
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         $response->addHeader("Last-Modified", gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         $response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");
     }
     SSViewer::config()->update('source_file_comments', $prevState);
     return $this->renderWith($this->getTemplates());
 }
Ejemplo n.º 10
0
 /**
  * Load all the template variables into the internal variables, including
  * the template into body.	Called before send() or debugSend()
  * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used
  * and it won't be plain email :)
  *
  * @param bool $isPlain
  * @return $this
  */
 protected function parseVariables($isPlain = false)
 {
     $origState = SSViewer::config()->get('source_file_comments');
     SSViewer::config()->update('source_file_comments', false);
     if (!$this->parseVariables_done) {
         $this->parseVariables_done = true;
         // Parse $ variables in the base parameters
         $this->templateData();
         // Process a .SS template file
         $fullBody = $this->body;
         if ($this->ss_template && !$isPlain) {
             // Requery data so that updated versions of To, From, Subject, etc are included
             $data = $this->templateData();
             $candidateTemplates = [$this->ss_template, ['type' => 'email', $this->ss_template]];
             $template = new SSViewer($candidateTemplates);
             if ($template->exists()) {
                 $fullBody = $template->process($data);
             }
         }
         // Rewrite relative URLs
         $this->body = HTTP::absoluteURLs($fullBody);
     }
     SSViewer::config()->update('source_file_comments', $origState);
     return $this;
 }