public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     $name = $suite->getName();
     if (!$this->isValidClass($name)) {
         return;
     }
     $this->class->tearDownOnce();
 }
 public function preRequest(HTTPRequest $request, Session $session, DataModel $model)
 {
     // Bootstrap session so that Session::get() accesses the right instance
     $dummyController = new Controller();
     $dummyController->setSession($session);
     $dummyController->setRequest($request);
     $dummyController->pushCurrent();
     // Block non-authenticated users from setting the stage mode
     if (!Versioned::can_choose_site_stage($request)) {
         $permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Convert::raw2xml(Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live")));
         // Force output since RequestFilter::preRequest doesn't support response overriding
         $response = Security::permissionFailure($dummyController, $permissionMessage);
         $session->inst_save();
         $dummyController->popCurrent();
         // Prevent output in testing
         if (class_exists('SilverStripe\\Dev\\SapphireTest', false) && SapphireTest::is_running_test()) {
             throw new HTTPResponse_Exception($response);
         }
         $response->output();
         die;
     }
     Versioned::choose_site_stage();
     $dummyController->popCurrent();
     return true;
 }
 public function tearDown()
 {
     parent::tearDown();
     i18n::set_locale($this->originalLocale);
     Config::inst()->remove('SilverStripe\\Forms\\TimeField', 'default_config');
     Config::inst()->update('SilverStripe\\Forms\\TimeField', 'default_config', $this->origTimeConfig);
 }
 public function setUp()
 {
     parent::setUp();
     $this->base = dirname(__FILE__) . '/fixtures/classmanifest';
     $this->manifest = new ClassManifest($this->base, false, true, false);
     $this->manifestTests = new ClassManifest($this->base, true, true, false);
 }
 public function setUp()
 {
     parent::setUp();
     $this->list = new DataList('GridFieldExportButtonTest_Team');
     $this->list = $this->list->sort('Name');
     $config = GridFieldConfig::create()->addComponent(new GridFieldExportButton());
     $this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
 }
 public function tearDown()
 {
     while ($this->nestingLevel > 0) {
         $this->nestingLevel--;
         Config::unnest();
     }
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     $this->baseManifest1 = dirname(__FILE__) . '/fixtures/classmanifest';
     $this->baseManifest2 = dirname(__FILE__) . '/fixtures/classmanifest_other';
     $this->testManifest1 = new ClassManifest($this->baseManifest1, false, true, false);
     $this->testManifest2 = new ClassManifest($this->baseManifest2, false, true, false);
 }
 public function setUp()
 {
     parent::setUp();
     $this->list = new DataList('GridFieldAction_Edit_Team');
     $config = GridFieldConfig::create()->addComponent(new GridFieldEditButton());
     $this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
     $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
 }
 public function setUpOnce()
 {
     Config::nest();
     VersionableExtensionsTest_DataObject::add_extension('SilverStripe\\ORM\\Versioning\\Versioned');
     VersionableExtensionsTest_DataObject::add_extension('VersionableExtensionsTest_Extension');
     $cfg = Config::inst();
     $cfg->update('VersionableExtensionsTest_DataObject', 'versionableExtensions', array('VersionableExtensionsTest_Extension' => array('test1', 'test2', 'test3')));
     parent::setUpOnce();
 }
 public function tearDown()
 {
     ThemeResourceLoader::set_instance($this->_oldLoader);
     // Pop if added during testing
     if (ClassLoader::instance()->getManifest() === $this->manifest) {
         ClassLoader::instance()->popManifest();
     }
     parent::tearDown();
 }
 protected function init()
 {
     parent::init();
     $isRunningTests = class_exists('SilverStripe\\Dev\\SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN");
     if (!$canAccess) {
         Security::permissionFailure($this);
     }
 }
 public function tearDown()
 {
     foreach ($_GET as $param => $value) {
         if (stripos($param, 'parameterconfirmationtokentest_') === 0) {
             unset($_GET[$param]);
         }
     }
     $_SERVER['HTTP_HOST'] = $this->oldHost;
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     // 42 items
     for ($i = 1; $i <= 42; $i++) {
         $obj = new GridFieldPrintButtonTest_DO();
         $obj->Name = "Object {$i}";
         $obj->write();
     }
 }
 function setUp()
 {
     // Check we can run PHP at all
     $null = is_writeable('/dev/null') ? '/dev/null' : 'NUL';
     exec("php -v 2> {$null}", $out, $rv);
     if ($rv != 0) {
         $this->markTestSkipped("Can't run PHP from the command line - is it in your path?");
     }
     parent::setUp();
 }
 /**
  * Require basic authentication.  Will request a username and password if none is given.
  *
  * Used by {@link Controller::init()}.
  *
  * @throws HTTPResponse_Exception
  *
  * @param string $realm
  * @param string|array $permissionCode Optional
  * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
  *  session log-in if those credentials are disabled.
  * @return Member|bool $member
  */
 public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true)
 {
     $isRunningTests = class_exists('SilverStripe\\Dev\\SapphireTest', false) && SapphireTest::is_running_test();
     if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) {
         return true;
     }
     /*
      * Enable HTTP Basic authentication workaround for PHP running in CGI mode with Apache
      * Depending on server configuration the auth header may be in HTTP_AUTHORIZATION or
      * REDIRECT_HTTP_AUTHORIZATION
      *
      * The follow rewrite rule must be in the sites .htaccess file to enable this workaround
      * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      */
     $authHeader = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : null);
     $matches = array();
     if ($authHeader && preg_match('/Basic\\s+(.*)$/i', $authHeader, $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     $member = null;
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
     }
     if (!$member && $tryUsingSessionLogin) {
         $member = Member::currentUser();
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!$member) {
         $response = new HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"));
         } else {
             $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
         $response = new HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     return $member;
 }
 public function run($request)
 {
     if (!Permission::check('ADMIN') && !Director::is_cli()) {
         $response = Security::permissionFailure();
         if ($response) {
             $response->output();
         }
         die;
     }
     SapphireTest::delete_all_temp_dbs();
 }
 /**
  * Set up manifest before each test
  */
 public function setUp()
 {
     parent::setUp();
     // Fake project root
     $this->base = dirname(__FILE__) . '/fixtures/templatemanifest';
     // New ThemeManifest for that root
     $this->manifest = new ThemeManifest($this->base, 'myproject', false, true);
     // New Loader for that root
     $this->loader = new ThemeResourceLoader($this->base);
     $this->loader->addSet('$default', $this->manifest);
 }
 public function tearDown()
 {
     if ($this->rootDir) {
         Filesystem::removeFolder($this->rootDir);
         $this->rootDir = null;
     }
     if ($this->originalServer) {
         $_SERVER = $this->originalServer;
         $this->originalServer = null;
     }
     parent::tearDown();
 }
 protected function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // if on CLI or with the database not ready. The latter makes it less errorprone to do an
     // initial schema build without requiring a default-admin login.
     // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
     $isRunningTests = class_exists('SilverStripe\\Dev\\SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || !Security::database_is_ready() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN");
     if (!$canAccess) {
         Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
 }
Ejemplo n.º 20
0
 public function tearDown()
 {
     parent::tearDown();
     $user = getTempFolderUsername();
     $base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' . preg_replace('/[^\\w-\\.+]+/', '-', PHP_VERSION);
     foreach (array('C--inetpub-wwwroot-silverstripe-test-project', '-Users-joebloggs-Sites-silverstripe-test-project', '-cache-var-www-silverstripe-test-project') as $dir) {
         $path = $base . $dir;
         if (file_exists($path)) {
             rmdir($path . DIRECTORY_SEPARATOR . $user);
             rmdir($path);
         }
     }
 }
 public function tearDown()
 {
     // TODO Remove director rule, currently API doesnt allow this
     $_GET = $this->originalGet;
     $_SESSION = $this->originalSession;
     // Reinstate the original REQUEST_URI after it was modified by some tests
     $_SERVER['REQUEST_URI'] = self::$originalRequestURI;
     if ($this->originalProtocolHeaders) {
         foreach ($this->originalProtocolHeaders as $header => $value) {
             $_SERVER[$header] = $value;
         }
     }
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     Versioned::set_stage(Versioned::DRAFT);
     // Automatically publish any object named *_published
     foreach ($this->getFixtureFactory()->getFixtures() as $class => $fixtures) {
         foreach ($fixtures as $name => $id) {
             if (stripos($name, '_published') !== false) {
                 /** @var Versioned|DataObject $object */
                 $object = DataObject::get($class)->byID($id);
                 $object->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
             }
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     HTMLEditorField_Toolbar::config()->update('fileurl_scheme_whitelist', array('http'));
     HTMLEditorField_Toolbar::config()->update('fileurl_domain_whitelist', array('example.com'));
     // Filesystem mock
     AssetStoreTest_SpyStore::activate(__CLASS__);
     // Load up files
     /** @var File $file1 */
     $file1 = $this->objFromFixture('SilverStripe\\Assets\\File', 'example_file');
     $file1->setFromString(str_repeat('x', 1000), $file1->Name);
     $file1->write();
     /** @var Image $image1 */
     $image1 = $this->objFromFixture('SilverStripe\\Assets\\Image', 'example_image');
     $image1->setFromLocalFile(__DIR__ . '/images/HTMLEditorFieldTest-example.jpg', 'folder/subfolder/HTMLEditorFieldTest_example.jpg');
     $image1->write();
 }
 public function tearDown()
 {
     AssetStoreTest_SpyStore::reset();
     parent::tearDown();
 }
Ejemplo n.º 25
0
 public function setUpOnce()
 {
     $this->extraDataObjects = DataObjectTest::$extra_data_objects;
     parent::setUpOnce();
 }
 public function setUp()
 {
     return parent::setUp();
 }
 public function tearDown()
 {
     DataObject::reset();
     parent::tearDown();
 }
 public function tearDown()
 {
     date_default_timezone_set($this->originalTZ);
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     Config::inst()->update('SilverStripe\\Assets\\FileNameFilter', 'default_replacements', array('/\\s/' => '-', '/_/' => '-', '/[^A-Za-z0-9+.\\-]+/' => '', '/[\\-]{2,}/' => '-', '/^[\\.\\-_]+/' => ''));
 }
 public function tearDown()
 {
     Security::setDefaultAdmin($this->defaultUsername, $this->defaultPassword);
     Permission::flush_permission_cache();
     parent::tearDown();
 }