Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
Show All 19 Lines | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'viewPolicy' => PhabricatorPolicies::POLICY_USER, | 'viewPolicy' => PhabricatorPolicies::POLICY_USER, | ||||
'authorPHID' => $author->getPHID(), | 'authorPHID' => $author->getPHID(), | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params, $author); | ||||
$secret1 = $file->getSecretKey(); | $secret1 = $file->getSecretKey(); | ||||
// First, change the name: this should not scramble the secret. | // First, change the name: this should not scramble the secret. | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorFileTransaction()) | $xactions[] = id(new PhabricatorFileTransaction()) | ||||
->setTransactionType(PhabricatorFileNameTransaction::TRANSACTIONTYPE) | ->setTransactionType(PhabricatorFileNameTransaction::TRANSACTIONTYPE) | ||||
->setNewValue('test.dat2'); | ->setNewValue('test.dat2'); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'viewPolicy' => $author->getPHID(), | 'viewPolicy' => $author->getPHID(), | ||||
'authorPHID' => $author->getPHID(), | 'authorPHID' => $author->getPHID(), | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params, $author); | ||||
$secret1 = $file->getSecretKey(); | $secret1 = $file->getSecretKey(); | ||||
$task = ManiphestTask::initializeNewTask($author); | $task = ManiphestTask::initializeNewTask($author); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new ManiphestTransaction()) | $xactions[] = id(new ManiphestTransaction()) | ||||
->setTransactionType(ManiphestTaskTitleTransaction::TRANSACTIONTYPE) | ->setTransactionType(ManiphestTaskTitleTransaction::TRANSACTIONTYPE) | ||||
->setNewValue(pht('File Scramble Test Task')); | ->setNewValue(pht('File Scramble Test Task')); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | ||||
'authorPHID' => $author->getPHID(), | 'authorPHID' => $author->getPHID(), | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params, $author); | ||||
$filter = new PhabricatorPolicyFilter(); | $filter = new PhabricatorPolicyFilter(); | ||||
// Test bare file policies. | // Test bare file policies. | ||||
$this->assertEqual( | $this->assertEqual( | ||||
array( | array( | ||||
true, | true, | ||||
false, | false, | ||||
), | ), | ||||
Show All 38 Lines | public function testFileVisibility() { | ||||
$params = array( | $params = array( | ||||
'name' => 'test.thumb.dat', | 'name' => 'test.thumb.dat', | ||||
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
$xform = PhabricatorFile::newFromFileData($data, $params); | $xform = PhabricatorFile::newFromFileData($data, $params, $author); | ||||
id(new PhabricatorTransformedFile()) | id(new PhabricatorTransformedFile()) | ||||
->setOriginalPHID($file->getPHID()) | ->setOriginalPHID($file->getPHID()) | ||||
->setTransform('test-thumb') | ->setTransform('test-thumb') | ||||
->setTransformedPHID($xform->getPHID()) | ->setTransformedPHID($xform->getPHID()) | ||||
->save(); | ->save(); | ||||
// Test the thumbnail's visibility. | // Test the thumbnail's visibility. | ||||
Show All 36 Lines | public function testFileStorageReadWrite() { | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment: This comment has a TODO. | |||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params); | ||||
// Test that the storage engine worked, and was the target of the write. We | // Test that the storage engine worked, and was the target of the write. We | ||||
// don't actually care what the data is (future changes may compress or | // don't actually care what the data is (future changes may compress or | ||||
// encrypt it), just that it exists in the test storage engine. | // encrypt it), just that it exists in the test storage engine. | ||||
$engine->readFile($file->getStorageHandle()); | $engine->readFile($file->getStorageHandle()); | ||||
// Now test that we get the same data back out. | // Now test that we get the same data back out. | ||||
$this->assertEqual($data, $file->loadFileData()); | $this->assertEqual($data, $file->loadFileData()); | ||||
} | } | ||||
public function testFileStorageUploadDifferentFiles() { | public function testFileStorageUploadDifferentFiles() { | ||||
$engine = new PhabricatorTestStorageEngine(); | $engine = new PhabricatorTestStorageEngine(); | ||||
$data = Filesystem::readRandomCharacters(64); | $data = Filesystem::readRandomCharacters(64); | ||||
$other_data = Filesystem::readRandomCharacters(64); | $other_data = Filesystem::readRandomCharacters(64); | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$first_file = PhabricatorFile::newFromFileData($data, $params); | $first_file = PhabricatorFile::newFromFileData($data, $params); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$second_file = PhabricatorFile::newFromFileData($other_data, $params); | $second_file = PhabricatorFile::newFromFileData($other_data, $params); | ||||
// Test that the second file uses different storage handle from | // Test that the second file uses different storage handle from | ||||
// the first file. | // the first file. | ||||
$first_handle = $first_file->getStorageHandle(); | $first_handle = $first_file->getStorageHandle(); | ||||
$second_handle = $second_file->getStorageHandle(); | $second_handle = $second_file->getStorageHandle(); | ||||
$this->assertTrue($first_handle != $second_handle); | $this->assertTrue($first_handle != $second_handle); | ||||
Show All 11 Lines | public function testFileStorageUploadSameFile() { | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$first_file = PhabricatorFile::newFromFileData($data, $params); | $first_file = PhabricatorFile::newFromFileData($data, $params); | ||||
$second_file = PhabricatorFile::newFromFileData($data, $params); | $second_file = PhabricatorFile::newFromFileData($data, $params); | ||||
// Test that the second file uses the same storage handle as | // Test that the second file uses the same storage handle as | ||||
// the first file. | // the first file. | ||||
$handle = $first_file->getStorageHandle(); | $handle = $first_file->getStorageHandle(); | ||||
$second_handle = $second_file->getStorageHandle(); | $second_handle = $second_file->getStorageHandle(); | ||||
$this->assertEqual($handle, $second_handle); | $this->assertEqual($handle, $second_handle); | ||||
} | } | ||||
public function testFileStorageDelete() { | public function testFileStorageDelete() { | ||||
$engine = new PhabricatorTestStorageEngine(); | $engine = new PhabricatorTestStorageEngine(); | ||||
$data = Filesystem::readRandomCharacters(64); | $data = Filesystem::readRandomCharacters(64); | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params); | ||||
$handle = $file->getStorageHandle(); | $handle = $file->getStorageHandle(); | ||||
$file->delete(); | $file->delete(); | ||||
$caught = null; | $caught = null; | ||||
try { | try { | ||||
$engine->readFile($handle); | $engine->readFile($handle); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
Show All 10 Lines | public function testFileStorageDeleteSharedHandle() { | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$first_file = PhabricatorFile::newFromFileData($data, $params); | $first_file = PhabricatorFile::newFromFileData($data, $params); | ||||
$second_file = PhabricatorFile::newFromFileData($data, $params); | $second_file = PhabricatorFile::newFromFileData($data, $params); | ||||
$first_file->delete(); | $first_file->delete(); | ||||
$this->assertEqual($data, $second_file->loadFileData()); | $this->assertEqual($data, $second_file->loadFileData()); | ||||
} | } | ||||
public function testReadWriteTtlFiles() { | public function testReadWriteTtlFiles() { | ||||
$engine = new PhabricatorTestStorageEngine(); | $engine = new PhabricatorTestStorageEngine(); | ||||
$data = Filesystem::readRandomCharacters(64); | $data = Filesystem::readRandomCharacters(64); | ||||
$ttl = (PhabricatorTime::getNow() + phutil_units('24 hours in seconds')); | $ttl = (PhabricatorTime::getNow() + phutil_units('24 hours in seconds')); | ||||
$params = array( | $params = array( | ||||
'name' => 'test.dat', | 'name' => 'test.dat', | ||||
'ttl.absolute' => $ttl, | 'ttl.absolute' => $ttl, | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$file = PhabricatorFile::newFromFileData($data, $params); | $file = PhabricatorFile::newFromFileData($data, $params); | ||||
$this->assertEqual($ttl, $file->getTTL()); | $this->assertEqual($ttl, $file->getTTL()); | ||||
} | } | ||||
public function testFileTransformDelete() { | public function testFileTransformDelete() { | ||||
// We want to test that a file deletes all its inbound transformation | // We want to test that a file deletes all its inbound transformation | ||||
// records and outbound transformed derivatives when it is deleted. | // records and outbound transformed derivatives when it is deleted. | ||||
// First, we create a chain of transforms, A -> B -> C. | // First, we create a chain of transforms, A -> B -> C. | ||||
$engine = new PhabricatorTestStorageEngine(); | $engine = new PhabricatorTestStorageEngine(); | ||||
$params = array( | $params = array( | ||||
'name' => 'test.txt', | 'name' => 'test.txt', | ||||
'storageEngines' => array( | 'storageEngines' => array( | ||||
$engine, | $engine, | ||||
), | ), | ||||
); | ); | ||||
// TODO | |||||
Lint: TODO Comment This comment has a TODO. Lint: TODO Comment: This comment has a TODO. | |||||
$a = PhabricatorFile::newFromFileData('a', $params); | $a = PhabricatorFile::newFromFileData('a', $params); | ||||
$b = PhabricatorFile::newFromFileData('b', $params); | $b = PhabricatorFile::newFromFileData('b', $params); | ||||
$c = PhabricatorFile::newFromFileData('c', $params); | $c = PhabricatorFile::newFromFileData('c', $params); | ||||
id(new PhabricatorTransformedFile()) | id(new PhabricatorTransformedFile()) | ||||
->setOriginalPHID($a->getPHID()) | ->setOriginalPHID($a->getPHID()) | ||||
->setTransform('test:a->b') | ->setTransform('test:a->b') | ||||
->setTransformedPHID($b->getPHID()) | ->setTransformedPHID($b->getPHID()) | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |
This comment has a TODO.