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 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 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); } } } }
/** * Retrieves details for files that this field wishes to attache to the * client-side form * * @param HTTPRequest $request * @return HTTPResponse */ public function attach(HTTPRequest $request) { if (!$request->isPOST()) { return $this->httpError(403); } if (!$this->canAttachExisting()) { return $this->httpError(403); } // Retrieve file attributes required by front end $return = array(); $files = File::get()->byIDs($request->postVar('ids')); foreach ($files as $file) { $return[] = $this->encodeFileAttributes($file); } $response = new HTTPResponse(Convert::raw2json($return)); $response->addHeader('Content-Type', 'application/json'); return $response; }
/** * Gets files filtered by a given parent with the allowed extensions * * @param int $parentID * @return DataList */ protected function getFiles($parentID = null) { $exts = $this->getAllowedExtensions(); $dotExts = array_map(function ($ext) { return ".{$ext}"; }, $exts); $files = File::get()->filter('Name:EndsWith', $dotExts); // Limit by folder (if required) if ($parentID) { $files = $files->filter('ParentID', $parentID); } return $files; }
/** * Redirects 3.x style detail links to new 4.x style routing. * * @param HTTPRequest $request */ public function legacyRedirectForEditView($request) { $fileID = $request->param('FileID'); /** @var File $file */ $file = File::get()->byID($fileID); $link = $this->getFileEditLink($file) ?: $this->Link(); $this->redirect($link); }