Path: blob/master/src/applications/maniphest/constants/__tests__/ManiphestTaskStatusTestCase.php
12262 views
<?php12final class ManiphestTaskStatusTestCase extends PhabricatorTestCase {34public function testManiphestStatusConstants() {5$map = array(6'y' => true,7'closed' => true,8'longlonglong' => true,9'duplicate2' => true,1011'' => false,12'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' =>13false,14'.' => false,15' ' => false,16'ABCD' => true,17'a b c ' => false,18'1' => false,19'111' => false,20'11a' => true,21);2223foreach ($map as $input => $expect) {24$this->assertEqual(25$expect,26ManiphestTaskStatus::isValidStatusConstant($input),27pht('Validate "%s"', $input));28}29}3031public function testManiphestStatusConfigValidation() {32$this->assertConfigValid(33false,34pht('Empty'),35array());3637// This is a minimal, valid configuration.3839$valid = array(40'open' => array(41'name' => pht('Open'),42'special' => 'default',43),44'closed' => array(45'name' => pht('Closed'),46'special' => 'closed',47'closed' => true,48),49'duplicate' => array(50'name' => pht('Duplicate'),51'special' => 'duplicate',52'closed' => true,53),54);55$this->assertConfigValid(true, pht('Minimal Valid Config'), $valid);5657// We should raise on a bad key.58$bad_key = $valid;59$bad_key['!'] = array('name' => pht('Exclaim'));60$this->assertConfigValid(false, pht('Bad Key'), $bad_key);6162// We should raise on a value type.63$bad_type = $valid;64$bad_type['other'] = 'other';65$this->assertConfigValid(false, pht('Bad Value Type'), $bad_type);6667// We should raise on an unknown configuration key.68$invalid_key = $valid;69$invalid_key['open']['imaginary'] = 'unicorn';70$this->assertConfigValid(false, pht('Invalid Key'), $invalid_key);7172// We should raise on two statuses with the same special.73$double_close = $valid;74$double_close['finished'] = array(75'name' => pht('Finished'),76'special' => 'closed',77'closed' => true,78);79$this->assertConfigValid(false, pht('Duplicate Special'), $double_close);8081// We should raise if any of the special statuses are missing.82foreach ($valid as $key => $config) {83$missing = $valid;84unset($missing[$key]);85$this->assertConfigValid(false, pht('Missing Special'), $missing);86}8788// The "default" special should be an open status.89$closed_default = $valid;90$closed_default['open']['closed'] = true;91$this->assertConfigValid(false, pht('Closed Default'), $closed_default);9293// The "closed" special should be a closed status.94$open_closed = $valid;95$open_closed['closed']['closed'] = false;96$this->assertConfigValid(false, pht('Open Closed'), $open_closed);9798// The "duplicate" special should be a closed status.99$open_duplicate = $valid;100$open_duplicate['duplicate']['closed'] = false;101$this->assertConfigValid(false, pht('Open Duplicate'), $open_duplicate);102}103104private function assertConfigValid($expect, $name, array $config) {105$caught = null;106try {107ManiphestTaskStatus::validateConfiguration($config);108} catch (Exception $ex) {109$caught = $ex;110}111112$this->assertEqual(113$expect,114!($caught instanceof Exception),115pht('Validation of "%s"', $name));116}117118}119120121