public function setUp() { parent::setUp(); $this->logInWithPermission('ADMIN'); // Save versioned state $this->oldReadingMode = Versioned::get_reading_mode(); Versioned::set_stage(Versioned::DRAFT); // Set backend root to /UploadFieldTest AssetStoreTest_SpyStore::activate('UploadFieldTest'); // Set the File Name Filter replacements so files have the expected names Config::inst()->update('SilverStripe\\Assets\\FileNameFilter', 'default_replacements', array('/\\s/' => '-', '/_/' => '-', '/[^A-Za-z0-9+.\\-]+/' => '', '/[\\-]{2,}/' => '-', '/^[\\.\\-_]+/' => '')); // Create a test folders for each of the fixture references foreach (Folder::get() as $folder) { $path = AssetStoreTest_SpyStore::getLocalPath($folder); Filesystem::makeFolder($path); } // Create a test files for each of the fixture references $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $file) { $path = AssetStoreTest_SpyStore::getLocalPath($file); Filesystem::makeFolder(dirname($path)); $fh = fopen($path, "w+"); fwrite($fh, str_repeat('x', 1000000)); fclose($fh); } }
public function setUp() { parent::setUp(); $this->logInWithPermission('ADMIN'); Versioned::set_stage(Versioned::DRAFT); // Set backend root to /AssetFieldTest AssetStoreTest_SpyStore::activate('AssetFieldTest'); $create = function ($path) { Filesystem::makeFolder(dirname($path)); $fh = fopen($path, "w+"); fwrite($fh, str_repeat('x', 1000000)); fclose($fh); }; // Write all DBFile references foreach (AssetFieldTest_Object::get() as $object) { $path = AssetStoreTest_SpyStore::getLocalPath($object->File); $create($path); } // Create a test files for each of the fixture references $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $file) { $path = AssetStoreTest_SpyStore::getLocalPath($file); $create($path); } }
public function writeTo($path) { Filesystem::makeFolder(dirname($path)); if (is_dir(dirname($path))) { $this->writeImage($path); } }
public function setUp() { parent::setUp(); $this->rootDir = ASSETS_PATH . '/AssetAdapterTest'; Filesystem::makeFolder($this->rootDir); Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/'); $this->originalServer = $_SERVER; }
public function setUp() { parent::setUp(); $this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot"; Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_folder', $this->alternateBasePath); $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot'; Filesystem::makeFolder($this->alternateBaseSavePath); // Push a class and template loader running from the fake webroot onto // the stack. $this->manifest = new ClassManifest($this->alternateBasePath, false, true, false); // Replace old template loader with new one with alternate base path $this->_oldLoader = ThemeResourceLoader::instance(); ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath)); }
public function setUp() { parent::setUp(); Versioned::set_stage(Versioned::DRAFT); // Set backend root to /DataDifferencerTest AssetStoreTest_SpyStore::activate('DataDifferencerTest'); // Create a test files for each of the fixture references $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $file) { $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); } }
public function setUp() { parent::setUp(); // Set backend root to /HTMLEditorFieldTest AssetStoreTest_SpyStore::activate('HTMLEditorFieldTest'); // Set the File Name Filter replacements so files have the expected names Config::inst()->update('SilverStripe\\Assets\\FileNameFilter', 'default_replacements', array('/\\s/' => '-', '/_/' => '-', '/[^A-Za-z0-9+.\\-]+/' => '', '/[\\-]{2,}/' => '-', '/^[\\.\\-_]+/' => '')); // Create a test files for each of the fixture references $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $file) { $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); } }
public function write($entities, $locale, $path) { // Create folder for lang files $langFolder = $path . '/lang'; if (!file_exists($langFolder)) { Filesystem::makeFolder($langFolder); touch($langFolder . '/_manifest_exclude'); } // Open the English file and write the Master String Table $langFile = $langFolder . '/' . $locale . '.yml'; if ($fh = fopen($langFile, "w")) { fwrite($fh, $this->getYaml($entities, $locale)); fclose($fh); } else { throw new LogicException("Cannot write language file! Please check permissions of {$langFile}"); } return true; }
public function setUp() { parent::setUp(); // Set backend root to /ImageTest AssetStoreTest_SpyStore::activate('ProtectedFileControllerTest'); // Create a test folders for each of the fixture references foreach (Folder::get() as $folder) { /** @var Folder $folder */ $filePath = AssetStoreTest_SpyStore::getLocalPath($folder); Filesystem::makeFolder($filePath); } // Create a test files for each of the fixture references foreach (File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder') as $file) { /** @var File $file */ $path = AssetStoreTest_SpyStore::getLocalPath($file); Filesystem::makeFolder(dirname($path)); $fh = fopen($path, "w+"); fwrite($fh, str_repeat('x', 1000000)); fclose($fh); // Create variant for each file $this->getAssetStore()->setFromString(str_repeat('y', 100), $file->Filename, $file->Hash, 'variant'); } }
public function setUp() { parent::setUp(); // Execute specific subclass if (get_class($this) == "ImageTest") { $this->markTestSkipped(sprintf('Skipping %s ', get_class($this))); return; } // Set backend root to /ImageTest AssetStoreTest_SpyStore::activate('ImageTest'); // Copy test images for each of the fixture references $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $image) { $filePath = AssetStoreTest_SpyStore::getLocalPath($image); // Only correct for test asset store $sourcePath = FRAMEWORK_PATH . '/tests/model/testimages/' . $image->Name; if (!file_exists($filePath)) { SSFilesystem::makeFolder(dirname($filePath)); if (!copy($sourcePath, $filePath)) { user_error('Failed to copy test images', E_USER_ERROR); } } } }
public function setUp() { parent::setUp(); $this->logInWithPermission('ADMIN'); Versioned::set_stage(Versioned::DRAFT); // Set backend root to /ImageTest AssetStoreTest_SpyStore::activate('FileTest'); // Create a test folders for each of the fixture references $folderIDs = $this->allFixtureIDs('SilverStripe\\Assets\\Folder'); foreach ($folderIDs as $folderID) { $folder = DataObject::get_by_id('SilverStripe\\Assets\\Folder', $folderID); $filePath = ASSETS_PATH . '/FileTest/' . $folder->getFilename(); Filesystem::makeFolder($filePath); } // Create a test files for each of the fixture references $fileIDs = $this->allFixtureIDs('SilverStripe\\Assets\\File'); foreach ($fileIDs as $fileID) { /** @var File $file */ $file = DataObject::get_by_id('SilverStripe\\Assets\\File', $fileID); $root = ASSETS_PATH . '/FileTest/'; if ($folder = $file->Parent()) { $root .= $folder->getFilename(); } $path = $root . substr($file->getHash(), 0, 10) . '/' . basename($file->getFilename()); Filesystem::makeFolder(dirname($path)); $fh = fopen($path, "w+"); fwrite($fh, str_repeat('x', 1000000)); fclose($fh); } // Conditional fixture creation in case the 'cms' module is installed if (class_exists('SilverStripe\\CMS\\Model\\ErrorPage')) { $page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404)); $page->write(); $page->copyVersionToStage('Stage', 'Live'); } }
/** * Set this store as the new asset backend * * @param string $basedir Basedir to store assets, which will be placed beneath 'assets' folder */ public static function activate($basedir) { // Assign this as the new store $publicAdapter = new PublicAssetAdapter(ASSETS_PATH . '/' . $basedir); $publicFilesystem = new Filesystem($publicAdapter, ['visibility' => AdapterInterface::VISIBILITY_PUBLIC]); $protectedAdapter = new ProtectedAssetAdapter(ASSETS_PATH . '/' . $basedir . '/.protected'); $protectedFilesystem = new Filesystem($protectedAdapter, ['visibility' => AdapterInterface::VISIBILITY_PRIVATE]); $backend = new AssetStoreTest_SpyStore(); $backend->setPublicFilesystem($publicFilesystem); $backend->setProtectedFilesystem($protectedFilesystem); Injector::inst()->registerService($backend, 'AssetStore'); // Assign flysystem backend to generated asset handler at the same time $generated = new GeneratedAssetHandler(); $generated->setFilesystem($publicFilesystem); Injector::inst()->registerService($generated, 'GeneratedAssetHandler'); Requirements::backend()->setAssetHandler($generated); // Disable legacy and set defaults Config::inst()->remove(get_class(new FlysystemAssetStore()), 'legacy_filenames'); Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', '/'); DBFile::config()->force_resample = false; File::config()->force_resample = false; self::reset(); self::$basedir = $basedir; // Ensure basedir exists SSFilesystem::makeFolder(self::base_path()); }
public function writeTo($filename) { if (!$filename) { return; } // Get current image data if (file_exists($filename)) { list($width, $height, $type, $attr) = getimagesize($filename); unlink($filename); } else { Filesystem::makeFolder(dirname($filename)); } // If image type isn't known, guess from extension $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if (empty($type)) { switch ($ext) { case "gif": $type = IMAGETYPE_GIF; break; case "jpeg": case "jpg": case "jpe": $type = IMAGETYPE_JPEG; break; default: $type = IMAGETYPE_PNG; break; } } // if $this->interlace != 0, the output image will be interlaced imageinterlace($this->gd, $this->interlace); // if the extension does not exist, the file will not be created! switch ($type) { case IMAGETYPE_GIF: imagegif($this->gd, $filename); break; case IMAGETYPE_JPEG: imagejpeg($this->gd, $filename, $this->quality); break; // case 3, and everything else // case 3, and everything else default: // Save them as 8-bit images // imagetruecolortopalette($this->gd, false, 256); imagepng($this->gd, $filename); break; } if (file_exists($filename)) { @chmod($filename, 0664); } }