public function setUp()
 {
     if (get_class($this) == "ImageTest") {
         $this->skipTest = true;
     }
     parent::setUp();
     if ($this->skipTest) {
         return;
     }
     // Set backend root to /ImageTest
     AssetStoreTest_SpyStore::activate('ImageTest');
     // Copy test images for each of the fixture references
     $files = File::get()->exclude('ClassName', 'Folder');
     foreach ($files as $image) {
         $filePath = AssetStoreTest_SpyStore::getLocalPath($image);
         // Only correct for test asset store
         $sourcePath = BASE_PATH . '/framework/tests/model/testimages/' . $image->Name;
         if (!file_exists($filePath)) {
             SS_Filesystem::makeFolder(dirname($filePath));
             if (!copy($sourcePath, $filePath)) {
                 user_error('Failed to copy test images', E_USER_ERROR);
             }
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     AssetStoreTest_SpyStore::activate('SiteTreeHtmlEditorFieldTest');
     $this->logInWithPermission('ADMIN');
     // Write file contents
     $files = File::get()->exclude('ClassName', 'Folder');
     foreach ($files as $file) {
         $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
         Filesystem::makeFolder(dirname($destPath));
         file_put_contents($destPath, str_repeat('x', 1000000));
     }
 }
 public function setUp()
 {
     parent::setUp();
     // Set backend root to /HtmlEditorFieldTest
     AssetStoreTest_SpyStore::activate('HtmlEditorFieldTest');
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'Folder');
     foreach ($files as $file) {
         $fromPath = BASE_PATH . '/framework/tests/forms/images/' . $file->Name;
         $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
         // Only correct for test asset store
         SS_Filesystem::makeFolder(dirname($destPath));
         copy($fromPath, $destPath);
     }
 }
 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();
     AssetStoreTest_SpyStore::activate('FileLinkTrackingTest');
     $this->logInWithPermission('ADMIN');
     // Write file contents
     $files = File::get()->exclude('ClassName', 'Folder');
     foreach ($files as $file) {
         $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
         Filesystem::makeFolder(dirname($destPath));
         file_put_contents($destPath, str_repeat('x', 1000000));
     }
     // Since we can't hard-code IDs, manually inject image tracking shortcode
     $imageID = $this->idFromFixture('Image', 'file1');
     $page = $this->objFromFixture('Page', 'page1');
     $page->Content = sprintf('<p><img src="/assets/FileLinkTrackingTest/55b443b601/testscript-test-file.jpg" data-fileid="%d" /></p>', $imageID);
     $page->write();
 }
 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', '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);
             }
         }
     }
 }
 /**
  * Test that files can be removed from an existing field
  */
 public function testRemoveFromHasOne()
 {
     $record = $this->objFromFixture('AssetFieldTest_Object', 'object1');
     // Check record exists
     $this->assertTrue($record->File->exists());
     $filePath = AssetStoreTest_SpyStore::getLocalPath($record->File);
     $this->assertFileExists($filePath);
     // Remove from record
     $response = $this->mockUploadFileSave('File', null, null, null);
     $this->assertEmpty($response['errors']);
     // Check file is removed
     $record = AssetFieldTest_Object::get()->byID($record->ID);
     $this->assertFalse($record->File->exists());
     // Check file object itself exists
     $this->assertFileNotExists($filePath, 'File is deleted once detached');
 }
 /**
  * Test that UploadField:overwriteWarning cannot overwrite Upload:replaceFile
  */
 public function testConfigOverwriteWarningCannotRelaceFiles()
 {
     Upload::config()->replaceFile = false;
     UploadField::config()->defaultConfig = array_merge(UploadField::config()->defaultConfig, array('overwriteWarning' => true));
     $tmpFileName = 'testUploadBasic.txt';
     $response = $this->mockFileUpload('NoRelationField', $tmpFileName);
     $this->assertFalse($response->isError());
     $responseData = Convert::json2array($response->getBody());
     $uploadedFile = DataObject::get_by_id('SilverStripe\\Assets\\File', (int) $responseData[0]['id']);
     $this->assertTrue(is_object($uploadedFile), 'The file object is created');
     $this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile));
     $tmpFileName = 'testUploadBasic.txt';
     $response = $this->mockFileUpload('NoRelationField', $tmpFileName);
     $this->assertFalse($response->isError());
     $responseData = Convert::json2array($response->getBody());
     $uploadedFile2 = DataObject::get_by_id('SilverStripe\\Assets\\File', (int) $responseData[0]['id']);
     $this->assertTrue(is_object($uploadedFile2), 'The file object is created');
     $this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile2));
     $this->assertTrue($uploadedFile->Filename !== $uploadedFile2->Filename, 'Filename is not the same');
     $this->assertTrue($uploadedFile->ID !== $uploadedFile2->ID, 'File database record is not the same');
 }
 public function testDeleteResampledImagesOnUpload()
 {
     $tmpFileName = 'UploadTest-testUpload.jpg';
     $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
     $uploadImage = function () use($tmpFileName, $tmpFilePath) {
         copy(__DIR__ . '/gdtest/test_jpg.jpg', $tmpFilePath);
         // emulates the $_FILES array
         $tmpFile = array('name' => $tmpFileName, 'type' => 'text/plaintext', 'size' => filesize($tmpFilePath), 'tmp_name' => $tmpFilePath, 'extension' => 'jpg', 'error' => UPLOAD_ERR_OK);
         $v = new UploadTest_Validator();
         // test upload into default folder
         $u = new Upload();
         $u->setReplaceFile(true);
         $u->setValidator($v);
         $u->loadIntoFile($tmpFile);
         return $u->getFile();
     };
     // Image upload and generate a resampled image
     $image = $uploadImage();
     $resampled = $image->ResizedImage(123, 456);
     $resampledPath = AssetStoreTest_SpyStore::getLocalPath($resampled);
     $this->assertFileExists($resampledPath);
     // Re-upload the image, overwriting the original
     // Resampled images should removed when their parent file is overwritten
     $image = $uploadImage();
     $this->assertFileExists($resampledPath);
 }
 /**
  * Test that files can be removed from an existing field
  */
 public function testRemoveFromHasOne()
 {
     $record = $this->objFromFixture('AssetFieldTest_Object', 'object1');
     // Check record exists
     $this->assertTrue($record->File->exists());
     $filePath = AssetStoreTest_SpyStore::getLocalPath($record->File);
     $this->assertFileExists($filePath);
     // Remove from record
     $response = $this->mockUploadFileSave('File', null, null, null);
     $this->assertEmpty($response['errors']);
     // Check file is removed
     $record = AssetFieldTest_Object::get()->byID($record->ID);
     $this->assertFalse($record->File->exists());
     // Check file object itself exists
     // @todo - When assets are removed from a DBFile reference, these files should be archived
     $this->assertFileExists($filePath, 'File is only detached, not deleted from filesystem');
 }
示例#13
0
 /**
  * Tests for the bug #5994 - if you don't execute get_by_id prior to the rename or move, it will fail.
  */
 public function testRenameFolderAndCheckTheFile()
 {
     // ID is prefixed in case Folder is subclassed by project/other module.
     $folder1 = DataObject::get_one('Folder', array('"File"."ID"' => $this->idFromFixture('Folder', 'folder1')));
     $folder1->Name = 'FileTest-folder1-changed';
     $folder1->write();
     // Check if the file in the folder moved along
     $file1 = DataObject::get_by_id('File', $this->idFromFixture('File', 'file1-folder1'), false);
     $this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($file1));
     $this->assertEquals($file1->Filename, 'FileTest-folder1-changed/File1.txt', 'The file DataObject path uses renamed folder');
     // File should be located in new folder
     $this->assertEquals(ASSETS_PATH . '/FolderTest/FileTest-folder1-changed/55b443b601/File1.txt', AssetStoreTest_SpyStore::getLocalPath($file1));
 }
 public function testDeleteFile()
 {
     $file = $this->objFromFixture('File', 'asdf');
     $fileID = $file->ID;
     $filePath = AssetStoreTest_SpyStore::getLocalPath($file);
     $file->delete();
     // File is deleted
     $this->assertFileNotExists($filePath);
     $this->assertEmpty(DataObject::get_by_id('File', $fileID));
 }
示例#15
0
 public function testDeleteDatabaseOnly()
 {
     $file = $this->objFromFixture('File', 'asdf');
     $fileID = $file->ID;
     $filePath = AssetStoreTest_SpyStore::getLocalPath($file);
     $file->delete();
     $this->assertFileExists($filePath);
     $this->assertFalse(DataObject::get_by_id('File', $fileID));
 }