Differential D14888 Diff 35996 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 487 Lines • ▼ Show 20 Lines | public function testParentProject() { | ||||
| // First user (who can see the parent because they are a member of | // First user (who can see the parent because they are a member of | ||||
| // the child) can see the project. | // the child) can see the project. | ||||
| $this->assertTrue((bool)$this->refreshProject($child, $user)); | $this->assertTrue((bool)$this->refreshProject($child, $user)); | ||||
| // Second user can not, because they can't see the parent. | // Second user can not, because they can't see the parent. | ||||
| $this->assertFalse((bool)$this->refreshProject($child, $user2)); | $this->assertFalse((bool)$this->refreshProject($child, $user2)); | ||||
| } | } | ||||
| public function testSlugMaps() { | |||||
| // When querying by slugs, slugs should be normalized and the mapping | |||||
| // should be reported correctly. | |||||
| $user = $this->createUser(); | |||||
| $user->save(); | |||||
| $name = 'queryslugproject'; | |||||
| $name2 = 'QUERYslugPROJECT'; | |||||
| $slug = 'queryslugextra'; | |||||
| $slug2 = 'QuErYSlUgExTrA'; | |||||
| $project = PhabricatorProject::initializeNewProject($user); | |||||
| $xactions = array(); | |||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | |||||
| ->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME) | |||||
| ->setNewValue($name); | |||||
| $xactions[] = id(new PhabricatorProjectTransaction()) | |||||
| ->setTransactionType(PhabricatorProjectTransaction::TYPE_SLUGS) | |||||
| ->setNewValue(array($slug)); | |||||
| $this->applyTransactions($project, $user, $xactions); | |||||
| $project_query = id(new PhabricatorProjectQuery()) | |||||
| ->setViewer($user) | |||||
| ->withSlugs(array($name)); | |||||
| $project_query->execute(); | |||||
| $map = $project_query->getSlugMap(); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $name => $project->getPHID(), | |||||
| ), | |||||
| ipull($map, 'projectPHID')); | |||||
| $project_query = id(new PhabricatorProjectQuery()) | |||||
| ->setViewer($user) | |||||
| ->withSlugs(array($slug)); | |||||
| $project_query->execute(); | |||||
| $map = $project_query->getSlugMap(); | |||||
| $this->assertEqual( | |||||
| array( | |||||
| $slug => $project->getPHID(), | |||||
| ), | |||||
| ipull($map, 'projectPHID')); | |||||
| $project_query = id(new PhabricatorProjectQuery()) | |||||
| ->setViewer($user) | |||||
| ->withSlugs(array($name, $slug, $name2, $slug2)); | |||||
| $project_query->execute(); | |||||
| $map = $project_query->getSlugMap(); | |||||
| $expect = array( | |||||
| $name => $project->getPHID(), | |||||
| $slug => $project->getPHID(), | |||||
| $name2 => $project->getPHID(), | |||||
| $slug2 => $project->getPHID(), | |||||
| ); | |||||
| $actual = ipull($map, 'projectPHID'); | |||||
| ksort($expect); | |||||
| ksort($actual); | |||||
| $this->assertEqual($expect, $actual); | |||||
| $expect = array( | |||||
| $name => $name, | |||||
| $slug => $slug, | |||||
| $name2 => $name, | |||||
| $slug2 => $slug, | |||||
| ); | |||||
| $actual = ipull($map, 'slug'); | |||||
| ksort($expect); | |||||
| ksort($actual); | |||||
| $this->assertEqual($expect, $actual); | |||||
| } | |||||
| 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(); | ||||
| ▲ Show 20 Lines • Show All 295 Lines • Show Last 20 Lines | |||||