Differential D14863 Diff 35930 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 181 Lines • ▼ Show 20 Lines | $projects = id(new PhabricatorProjectQuery()) | ||||
array( | array( | ||||
$child->getPHID(), | $child->getPHID(), | ||||
$grandchild2->getPHID(), | $grandchild2->getPHID(), | ||||
)) | )) | ||||
->execute(); | ->execute(); | ||||
$this->assertEqual(2, count($projects)); | $this->assertEqual(2, count($projects)); | ||||
} | } | ||||
public function testMemberMaterialization() { | |||||
$material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST; | |||||
$user = $this->createUser(); | |||||
$user->save(); | |||||
$parent = $this->createProject($user); | |||||
$child = $this->createProject($user, $parent); | |||||
$this->joinProject($child, $user); | |||||
$parent_material = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$parent->getPHID(), | |||||
$material_type); | |||||
$this->assertEqual( | |||||
array($user->getPHID()), | |||||
$parent_material); | |||||
} | |||||
public function testMilestones() { | |||||
$user = $this->createUser(); | |||||
$user->save(); | |||||
$parent = $this->createProject($user); | |||||
$m1 = $this->createProject($user, $parent, true); | |||||
$m2 = $this->createProject($user, $parent, true); | |||||
$m3 = $this->createProject($user, $parent, true); | |||||
$this->assertEqual(1, $m1->getMilestoneNumber()); | |||||
$this->assertEqual(2, $m2->getMilestoneNumber()); | |||||
$this->assertEqual(3, $m3->getMilestoneNumber()); | |||||
} | |||||
public function testMilestoneMembership() { | |||||
$user = $this->createUser(); | |||||
$user->save(); | |||||
$parent = $this->createProject($user); | |||||
$milestone = $this->createProject($user, $parent, true); | |||||
$this->joinProject($parent, $user); | |||||
$milestone = id(new PhabricatorProjectQuery()) | |||||
->setViewer($user) | |||||
->withPHIDs(array($milestone->getPHID())) | |||||
->executeOne(); | |||||
$this->assertTrue($milestone->isUserMember($user->getPHID())); | |||||
$milestone = id(new PhabricatorProjectQuery()) | |||||
->setViewer($user) | |||||
->withPHIDs(array($milestone->getPHID())) | |||||
->needMembers(true) | |||||
->executeOne(); | |||||
$this->assertEqual( | |||||
array($user->getPHID()), | |||||
$milestone->getMemberPHIDs()); | |||||
} | |||||
public function testParentProject() { | public function testParentProject() { | ||||
$user = $this->createUser(); | $user = $this->createUser(); | ||||
$user->save(); | $user->save(); | ||||
$parent = $this->createProject($user); | $parent = $this->createProject($user); | ||||
$child = $this->createProject($user, $parent); | $child = $this->createProject($user, $parent); | ||||
$this->assertTrue(true); | $this->assertTrue(true); | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | if ($results) { | ||||
return head($results); | return head($results); | ||||
} else { | } else { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
private function createProject( | private function createProject( | ||||
PhabricatorUser $user, | PhabricatorUser $user, | ||||
PhabricatorProject $parent = null) { | PhabricatorProject $parent = null, | ||||
$is_milestone = false) { | |||||
$project = PhabricatorProject::initializeNewProject($user); | $project = PhabricatorProject::initializeNewProject($user); | ||||
$name = pht('Test Project %d', mt_rand()); | $name = pht('Test Project %d', mt_rand()); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(new PhabricatorProjectTransaction()) | $xactions[] = id(new PhabricatorProjectTransaction()) | ||||
->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME) | ->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME) | ||||
->setNewValue($name); | ->setNewValue($name); | ||||
if ($parent) { | if ($parent) { | ||||
$xactions[] = id(new PhabricatorProjectTransaction()) | $xactions[] = id(new PhabricatorProjectTransaction()) | ||||
->setTransactionType(PhabricatorProjectTransaction::TYPE_PARENT) | ->setTransactionType(PhabricatorProjectTransaction::TYPE_PARENT) | ||||
->setNewValue($parent->getPHID()); | ->setNewValue($parent->getPHID()); | ||||
} | } | ||||
if ($is_milestone) { | |||||
$xactions[] = id(new PhabricatorProjectTransaction()) | |||||
->setTransactionType(PhabricatorProjectTransaction::TYPE_MILESTONE) | |||||
->setNewValue(true); | |||||
} | |||||
$this->applyTransactions($project, $user, $xactions); | $this->applyTransactions($project, $user, $xactions); | ||||
return $project; | return $project; | ||||
} | } | ||||
private function setViewPolicy( | private function setViewPolicy( | ||||
PhabricatorProject $project, | PhabricatorProject $project, | ||||
PhabricatorUser $user, | PhabricatorUser $user, | ||||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |