Differential D14910 Diff 36035 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 705 Lines • ▼ Show 20 Lines | public function testJoinLeaveProject() { | ||||
| $proj = $this->refreshProject($proj, $user, true); | $proj = $this->refreshProject($proj, $user, true); | ||||
| $this->leaveProject($proj, $user); | $this->leaveProject($proj, $user); | ||||
| $proj = $this->refreshProject($proj, $user, true); | $proj = $this->refreshProject($proj, $user, true); | ||||
| $this->assertFalse( | $this->assertFalse( | ||||
| $proj->isUserMember($user->getPHID()), | $proj->isUserMember($user->getPHID()), | ||||
| pht('Leave allowed without any permission.')); | pht('Leave allowed without any permission.')); | ||||
| } | } | ||||
| public function testComplexConstraints() { | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $engineering = $this->createProject($user); | |||||
| $engineering_scan = $this->createProject($user, $engineering); | |||||
| $engineering_warp = $this->createProject($user, $engineering); | |||||
| $exploration = $this->createProject($user); | |||||
| $exploration_diplomacy = $this->createProject($user, $exploration); | |||||
| $task_engineering = $this->newTask( | |||||
| $user, | |||||
| array($engineering), | |||||
| pht('Engineering Only')); | |||||
| $task_exploration = $this->newTask( | |||||
| $user, | |||||
| array($exploration), | |||||
| pht('Exploration Only')); | |||||
| $task_warp_explore = $this->newTask( | |||||
| $user, | |||||
| array($engineering_warp, $exploration), | |||||
| pht('Warp to New Planet')); | |||||
| $task_diplomacy_scan = $this->newTask( | |||||
| $user, | |||||
| array($engineering_scan, $exploration_diplomacy), | |||||
| pht('Scan Diplomat')); | |||||
| $task_diplomacy = $this->newTask( | |||||
| $user, | |||||
| array($exploration_diplomacy), | |||||
| pht('Diplomatic Meeting')); | |||||
| $task_warp_scan = $this->newTask( | |||||
| $user, | |||||
| array($engineering_scan, $engineering_warp), | |||||
| pht('Scan Warp Drives')); | |||||
| $this->assertQueryByProjects( | |||||
| $user, | |||||
| array( | |||||
| $task_engineering, | |||||
| $task_warp_explore, | |||||
| $task_diplomacy_scan, | |||||
| $task_warp_scan, | |||||
| ), | |||||
| array($engineering), | |||||
| pht('All Engineering')); | |||||
| $this->assertQueryByProjects( | |||||
| $user, | |||||
| array( | |||||
| $task_diplomacy_scan, | |||||
| $task_warp_scan, | |||||
| ), | |||||
| array($engineering_scan), | |||||
| pht('All Scan')); | |||||
| $this->assertQueryByProjects( | |||||
| $user, | |||||
| array( | |||||
| $task_warp_explore, | |||||
| $task_diplomacy_scan, | |||||
| ), | |||||
| array($engineering, $exploration), | |||||
| pht('Engineering + Exploration')); | |||||
| // This is testing that a query for "Parent" and "Parent > Child" works | |||||
| // properly. | |||||
| $this->assertQueryByProjects( | |||||
| $user, | |||||
| array( | |||||
| $task_diplomacy_scan, | |||||
| $task_warp_scan, | |||||
| ), | |||||
| array($engineering, $engineering_scan), | |||||
| pht('Engineering + Scan')); | |||||
| } | |||||
| private function newTask( | |||||
| PhabricatorUser $viewer, | |||||
| array $projects, | |||||
| $name = null) { | |||||
| $task = ManiphestTask::initializeNewTask($viewer); | |||||
| if (!strlen($name)) { | |||||
| $name = pht('Test Task'); | |||||
| } | |||||
| $xactions = array(); | |||||
| $xactions[] = id(new ManiphestTransaction()) | |||||
| ->setTransactionType(ManiphestTransaction::TYPE_TITLE) | |||||
| ->setNewValue($name); | |||||
| if ($projects) { | |||||
| $xactions[] = id(new ManiphestTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
| ->setMetadataValue( | |||||
| 'edge:type', | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST) | |||||
| ->setNewValue( | |||||
| array( | |||||
| '=' => array_fuse(mpull($projects, 'getPHID')), | |||||
| )); | |||||
| } | |||||
| $editor = id(new ManiphestTransactionEditor()) | |||||
| ->setActor($viewer) | |||||
| ->setContentSource(PhabricatorContentSource::newConsoleSource()) | |||||
| ->setContinueOnNoEffect(true) | |||||
| ->applyTransactions($task, $xactions); | |||||
| return $task; | |||||
| } | |||||
| private function assertQueryByProjects( | |||||
| PhabricatorUser $viewer, | |||||
| array $expect, | |||||
| array $projects, | |||||
| $label = null) { | |||||
| $datasource = id(new PhabricatorProjectLogicalDatasource()) | |||||
| ->setViewer($viewer); | |||||
| $project_phids = mpull($projects, 'getPHID'); | |||||
| $constraints = $datasource->evaluateTokens($project_phids); | |||||
| $query = id(new ManiphestTaskQuery()) | |||||
| ->setViewer($viewer); | |||||
| $query->withEdgeLogicConstraints( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| $constraints); | |||||
| $tasks = $query->execute(); | |||||
| $expect_phids = mpull($expect, 'getTitle', 'getPHID'); | |||||
| ksort($expect_phids); | |||||
| $actual_phids = mpull($tasks, 'getTitle', 'getPHID'); | |||||
| ksort($actual_phids); | |||||
| $this->assertEqual($expect_phids, $actual_phids, $label); | |||||
| } | |||||
| private function refreshProject( | private function refreshProject( | ||||
| PhabricatorProject $project, | PhabricatorProject $project, | ||||
| PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
| $need_members = false, | $need_members = false, | ||||
| $need_watchers = false) { | $need_watchers = false) { | ||||
| $results = id(new PhabricatorProjectQuery()) | $results = id(new PhabricatorProjectQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines | |||||