Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | public function testFileIndirectScramble() { | ||||
$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')); | ||||
$xactions[] = id(new ManiphestTransaction()) | $xactions[] = id(new ManiphestTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
ManiphestTaskDescriptionTransaction::TRANSACTIONTYPE) | ManiphestTaskDescriptionTransaction::TRANSACTIONTYPE) | ||||
->setNewValue('{'.$file->getMonogram().'}'); | ->setNewValue('{'.$file->getMonogram().'}') | ||||
->setMetadataValue( | |||||
'remarkup.control', | |||||
array( | |||||
'attachedFilePHIDs' => array( | |||||
$file->getPHID(), | |||||
), | |||||
)); | |||||
id(new ManiphestTransactionEditor()) | id(new ManiphestTransactionEditor()) | ||||
->setActor($author) | ->setActor($author) | ||||
->setContentSource($this->newContentSource()) | ->setContentSource($this->newContentSource()) | ||||
->applyTransactions($task, $xactions); | ->applyTransactions($task, $xactions); | ||||
$file = $file->reload(); | $file = $file->reload(); | ||||
$secret2 = $file->getSecretKey(); | $secret2 = $file->getSecretKey(); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | $this->assertEqual( | ||||
true, | true, | ||||
false, | false, | ||||
), | ), | ||||
$this->canViewFile($users, $file), | $this->canViewFile($users, $file), | ||||
pht('File Visibility')); | pht('File Visibility')); | ||||
// Create an object and test object policies. | // Create an object and test object policies. | ||||
$object = ManiphestTask::initializeNewTask($author); | $object = ManiphestTask::initializeNewTask($author) | ||||
$object->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()); | ->setTitle(pht('File Visibility Test Task')) | ||||
$object->save(); | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ||||
->save(); | |||||
$this->assertTrue( | $this->assertTrue( | ||||
$filter->hasCapability( | $filter->hasCapability( | ||||
$author, | $author, | ||||
$object, | $object, | ||||
PhabricatorPolicyCapability::CAN_VIEW), | PhabricatorPolicyCapability::CAN_VIEW), | ||||
pht('Object Visible to Author')); | pht('Object Visible to Author')); | ||||
$this->assertTrue( | $this->assertTrue( | ||||
$filter->hasCapability( | $filter->hasCapability( | ||||
$viewer, | $viewer, | ||||
$object, | $object, | ||||
PhabricatorPolicyCapability::CAN_VIEW), | PhabricatorPolicyCapability::CAN_VIEW), | ||||
pht('Object Visible to Others')); | pht('Object Visible to Others')); | ||||
// Reference the file in a comment. This should not affect the file | |||||
// policy. | |||||
$file_ref = '{F'.$file->getID().'}'; | |||||
$xactions = array(); | |||||
$xactions[] = id(new ManiphestTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | |||||
->attachComment( | |||||
id(new ManiphestTransactionComment()) | |||||
->setContent($file_ref)); | |||||
id(new ManiphestTransactionEditor()) | |||||
->setActor($author) | |||||
->setContentSource($this->newContentSource()) | |||||
->applyTransactions($object, $xactions); | |||||
// Test the referenced file's visibility. | |||||
$this->assertEqual( | |||||
array( | |||||
true, | |||||
false, | |||||
), | |||||
$this->canViewFile($users, $file), | |||||
pht('Referenced File Visibility')); | |||||
// Attach the file to the object and test that the association opens a | // Attach the file to the object and test that the association opens a | ||||
// policy exception for the non-author viewer. | // policy exception for the non-author viewer. | ||||
$file->attachToObject($object->getPHID()); | $xactions = array(); | ||||
$xactions[] = id(new ManiphestTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | |||||
->setMetadataValue( | |||||
'remarkup.control', | |||||
array( | |||||
'attachedFilePHIDs' => array( | |||||
$file->getPHID(), | |||||
), | |||||
)) | |||||
->attachComment( | |||||
id(new ManiphestTransactionComment()) | |||||
->setContent($file_ref)); | |||||
id(new ManiphestTransactionEditor()) | |||||
->setActor($author) | |||||
->setContentSource($this->newContentSource()) | |||||
->applyTransactions($object, $xactions); | |||||
// Test the attached file's visibility. | // Test the attached file's visibility. | ||||
$this->assertEqual( | $this->assertEqual( | ||||
array( | array( | ||||
true, | true, | ||||
true, | true, | ||||
), | ), | ||||
$this->canViewFile($users, $file), | $this->canViewFile($users, $file), | ||||
▲ Show 20 Lines • Show All 285 Lines • Show Last 20 Lines |