Differential D14861 Diff 35938 src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/__tests__/PhabricatorProjectCoreTestCase.php
| Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | public function testEditProject() { | ||||
| try { | try { | ||||
| $this->attemptProjectEdit($proj, $user); | $this->attemptProjectEdit($proj, $user); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $caught = $ex; | $caught = $ex; | ||||
| } | } | ||||
| $this->assertTrue($caught instanceof Exception); | $this->assertTrue($caught instanceof Exception); | ||||
| } | } | ||||
| public function testParentProject() { | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $parent = $this->createProject($user); | |||||
| $child = $this->createProject($user, $parent); | |||||
| $this->assertTrue(true); | |||||
| $child = $this->refreshProject($child, $user); | |||||
| $this->assertEqual( | |||||
| $parent->getPHID(), | |||||
| $child->getParentProject()->getPHID()); | |||||
| $this->assertEqual(1, (int)$child->getProjectDepth()); | |||||
| $this->assertFalse( | |||||
| $child->isUserMember($user->getPHID())); | |||||
| $this->assertFalse( | |||||
| $child->getParentProject()->isUserMember($user->getPHID())); | |||||
| $this->joinProject($child, $user); | |||||
| $child = $this->refreshProject($child, $user); | |||||
| $this->assertTrue( | |||||
| $child->isUserMember($user->getPHID())); | |||||
| $this->assertTrue( | |||||
| $child->getParentProject()->isUserMember($user->getPHID())); | |||||
| // Test that hiding a parent hides the child. | |||||
| $user2 = $this->createUser(); | |||||
| $user2->save(); | |||||
| // Second user can see the project for now. | |||||
| $this->assertTrue((bool)$this->refreshProject($child, $user2)); | |||||
| // Hide the parent. | |||||
| $this->setViewPolicy($parent, $user, $user->getPHID()); | |||||
| // First user (who can see the parent because they are a member of | |||||
| // the child) can see the project. | |||||
| $this->assertTrue((bool)$this->refreshProject($child, $user)); | |||||
| // Second user can not, because they can't see the parent. | |||||
| $this->assertFalse((bool)$this->refreshProject($child, $user2)); | |||||
| } | |||||
| private function attemptProjectEdit( | private function attemptProjectEdit( | ||||
| PhabricatorProject $proj, | PhabricatorProject $proj, | ||||
| PhabricatorUser $user, | PhabricatorUser $user, | ||||
| $skip_refresh = false) { | $skip_refresh = false) { | ||||
| $proj = $this->refreshProject($proj, $user, true); | $proj = $this->refreshProject($proj, $user, true); | ||||
| $new_name = $proj->getName().' '.mt_rand(); | $new_name = $proj->getName().' '.mt_rand(); | ||||
| $xaction = new PhabricatorProjectTransaction(); | $xaction = new PhabricatorProjectTransaction(); | ||||
| $xaction->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME); | $xaction->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME); | ||||
| $xaction->setNewValue($new_name); | $xaction->setNewValue($new_name); | ||||
| $editor = new PhabricatorProjectTransactionEditor(); | $this->applyTransactions($proj, $user, array($xaction)); | ||||
| $editor->setActor($user); | |||||
| $editor->setContentSource(PhabricatorContentSource::newConsoleSource()); | |||||
| $editor->applyTransactions($proj, array($xaction)); | |||||
| return true; | return true; | ||||
| } | } | ||||
| public function testJoinLeaveProject() { | public function testJoinLeaveProject() { | ||||
| $user = $this->createUser(); | $user = $this->createUser(); | ||||
| $user->save(); | $user->save(); | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | private function refreshProject( | ||||
| if ($results) { | if ($results) { | ||||
| return head($results); | return head($results); | ||||
| } else { | } else { | ||||
| return null; | return null; | ||||
| } | } | ||||
| } | } | ||||
| private function createProject(PhabricatorUser $user) { | private function createProject( | ||||
| PhabricatorUser $user, | |||||
| PhabricatorProject $parent = null) { | |||||
| $project = PhabricatorProject::initializeNewProject($user); | $project = PhabricatorProject::initializeNewProject($user); | ||||
| $project->setName(pht('Test Project %d', mt_rand())); | |||||
| $project->save(); | $name = pht('Test Project %d', mt_rand()); | ||||
| $xactions = array(); | |||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | |||||
| ->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME) | |||||
| ->setNewValue($name); | |||||
| if ($parent) { | |||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | |||||
| ->setTransactionType(PhabricatorProjectTransaction::TYPE_PARENT) | |||||
| ->setNewValue($parent->getPHID()); | |||||
| } | |||||
| $this->applyTransactions($project, $user, $xactions); | |||||
| return $project; | |||||
| } | |||||
| private function setViewPolicy( | |||||
| PhabricatorProject $project, | |||||
| PhabricatorUser $user, | |||||
| $policy) { | |||||
| $xactions = array(); | |||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | |||||
| ->setNewValue($policy); | |||||
| $this->applyTransactions($project, $user, $xactions); | |||||
| return $project; | return $project; | ||||
| } | } | ||||
| private function createProjectWithNewAuthor() { | private function createProjectWithNewAuthor() { | ||||
| $author = $this->createUser(); | $author = $this->createUser(); | ||||
| $author->save(); | $author->save(); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | private function applyProjectEdgeTransaction( | ||||
| ); | ); | ||||
| $xactions = array(); | $xactions = array(); | ||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | $xactions[] = id(new PhabricatorProjectTransaction()) | ||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ||||
| ->setMetadataValue('edge:type', $edge_type) | ->setMetadataValue('edge:type', $edge_type) | ||||
| ->setNewValue($spec); | ->setNewValue($spec); | ||||
| $this->applyTransactions($project, $user, $xactions); | |||||
| return $project; | |||||
| } | |||||
| private function applyTransactions( | |||||
| PhabricatorProject $project, | |||||
| PhabricatorUser $user, | |||||
| array $xactions) { | |||||
| $editor = id(new PhabricatorProjectTransactionEditor()) | $editor = id(new PhabricatorProjectTransactionEditor()) | ||||
| ->setActor($user) | ->setActor($user) | ||||
| ->setContentSource(PhabricatorContentSource::newConsoleSource()) | ->setContentSource(PhabricatorContentSource::newConsoleSource()) | ||||
| ->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
| ->applyTransactions($project, $xactions); | ->applyTransactions($project, $xactions); | ||||
| return $project; | |||||
| } | } | ||||
| } | } | ||||