update('alternate_base_url', '/mysite/');
}
public function tearDown() {
TestAssetStore::reset();
parent::tearDown();
}
/**
* Test that images in a DBFile are rendered properly
*/
public function testRender() {
$obj = new DBFileTest\TestObject();
// Test image tag
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'awesome-fish.jpg');
$this->assertEquals(
'',
trim($obj->MyFile->forTemplate())
);
// Test download tag
$obj->MyFile->setFromString('puppies', 'subdir/puppy-document.txt');
$this->assertEquals(
'',
trim($obj->MyFile->forTemplate())
);
}
public function testValidation() {
$obj = new DBFileTest\ImageOnly();
// Test from image
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'awesome-fish.jpg');
// This should fail
$this->setExpectedException('SilverStripe\\ORM\\ValidationException');
$obj->MyFile->setFromString('puppies', 'subdir/puppy-document.txt');
}
public function testPermission() {
$obj = new DBFileTest\TestObject();
// Test from image
$fish = realpath(__DIR__ .'/../ORM/ImageTest/test-image-high-quality.jpg');
$this->assertFileExists($fish);
$obj->MyFile->setFromLocalFile($fish, 'private/awesome-fish.jpg', null, null, array(
'visibility' => AssetStore::VISIBILITY_PROTECTED
));
// Test various file permissions work on DBFile
$this->assertFalse($obj->MyFile->canViewFile());
$obj->MyFile->getURL();
$this->assertTrue($obj->MyFile->canViewFile());
$obj->MyFile->revokeFile();
$this->assertFalse($obj->MyFile->canViewFile());
$obj->MyFile->getURL(false);
$this->assertFalse($obj->MyFile->canViewFile());
$obj->MyFile->grantFile();
$this->assertTrue($obj->MyFile->canViewFile());
}
}