Differential D15167 Diff 36619 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 802 Lines • ▼ Show 20 Lines | $this->assertQueryByProjects( | ||||
| array( | array( | ||||
| $task_diplomacy_scan, | $task_diplomacy_scan, | ||||
| $task_warp_scan, | $task_warp_scan, | ||||
| ), | ), | ||||
| array($engineering, $engineering_scan), | array($engineering, $engineering_scan), | ||||
| pht('Engineering + Scan')); | pht('Engineering + Scan')); | ||||
| } | } | ||||
| public function testTagAncestryConflicts() { | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $stonework = $this->createProject($user); | |||||
| $stonework_masonry = $this->createProject($user, $stonework); | |||||
| $stonework_sculpting = $this->createProject($user, $stonework); | |||||
| $task = $this->newTask($user, array()); | |||||
| $this->assertEqual(array(), $this->getTaskProjects($task)); | |||||
| $this->addProjectTags($user, $task, array($stonework->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // Adding a descendant should remove the parent. | |||||
| $this->addProjectTags($user, $task, array($stonework_masonry->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework_masonry->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // Adding an ancestor should remove the descendant. | |||||
| $this->addProjectTags($user, $task, array($stonework->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // Adding two tags in the same hierarchy which are not mutual ancestors | |||||
| // should remove the ancestor but otherwise work fine. | |||||
| $this->addProjectTags( | |||||
| $user, | |||||
| $task, | |||||
| array( | |||||
| $stonework_masonry->getPHID(), | |||||
| $stonework_sculpting->getPHID(), | |||||
| )); | |||||
| $expect = array( | |||||
| $stonework_masonry->getPHID(), | |||||
| $stonework_sculpting->getPHID(), | |||||
| ); | |||||
| sort($expect); | |||||
| $this->assertEqual($expect, $this->getTaskProjects($task)); | |||||
| } | |||||
| public function testTagMilestoneConflicts() { | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $stonework = $this->createProject($user); | |||||
| $stonework_1 = $this->createProject($user, $stonework, true); | |||||
| $stonework_2 = $this->createProject($user, $stonework, true); | |||||
| $task = $this->newTask($user, array()); | |||||
| $this->assertEqual(array(), $this->getTaskProjects($task)); | |||||
| $this->addProjectTags($user, $task, array($stonework->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // Adding a milesone should remove the parent. | |||||
| $this->addProjectTags($user, $task, array($stonework_1->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework_1->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // Adding the parent should remove the milestone. | |||||
| $this->addProjectTags($user, $task, array($stonework->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| // First, add one milestone. | |||||
| $this->addProjectTags($user, $task, array($stonework_1->getPHID())); | |||||
| // Now, adding a second milestone should remove the first milestone. | |||||
| $this->addProjectTags($user, $task, array($stonework_2->getPHID())); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $stonework_2->getPHID(), | |||||
| ), | |||||
| $this->getTaskProjects($task)); | |||||
| } | |||||
| private function getTaskProjects(ManiphestTask $task) { | |||||
| $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
| $task->getPHID(), | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | |||||
| sort($project_phids); | |||||
| return $project_phids; | |||||
| } | |||||
| 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); | ||||
| $this->applyTransactions($proj, $user, array($xaction)); | $this->applyTransactions($proj, $user, array($xaction)); | ||||
| return true; | return true; | ||||
| } | } | ||||
| private function addProjectTags( | |||||
| PhabricatorUser $viewer, | |||||
| ManiphestTask $task, | |||||
| array $phids) { | |||||
| $xactions = array(); | |||||
| $xactions[] = id(new ManiphestTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
| ->setMetadataValue( | |||||
| 'edge:type', | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST) | |||||
| ->setNewValue( | |||||
| array( | |||||
| '+' => array_fuse($phids), | |||||
| )); | |||||
| $editor = id(new ManiphestTransactionEditor()) | |||||
| ->setActor($viewer) | |||||
| ->setContentSource(PhabricatorContentSource::newConsoleSource()) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->applyTransactions($task, $xactions); | |||||
| } | |||||
| private function newTask( | private function newTask( | ||||
| PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
| array $projects, | array $projects, | ||||
| $name = null) { | $name = null) { | ||||
| $task = ManiphestTask::initializeNewTask($viewer); | $task = ManiphestTask::initializeNewTask($viewer); | ||||
| if (!strlen($name)) { | if (!strlen($name)) { | ||||
| ▲ Show 20 Lines • Show All 229 Lines • Show Last 20 Lines | |||||