Christopher Johnson (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/181866
Change subject: new unit tests for custom field implementations ...................................................................... new unit tests for custom field implementations adds SprintValidator Change-Id: I02cbf925cb33d0fdd9a46bd09d458fd0f321579d --- M src/__phutil_library_map__.php M src/customfield/SprintProjectCustomField.php M src/tests/SprintApplicationTest.php A src/tests/SprintCustomFieldTest.php M src/tests/SprintQueryTest.php M src/tests/SprintTestCase.php A src/util/SprintValidator.php 7 files changed, 248 insertions(+), 44 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint refs/changes/66/181866/1 diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9ce7c6e..1a07ca8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -39,6 +39,7 @@ 'SprintConstants' => 'constants/SprintConstants.php', 'SprintController' => 'controller/SprintController.php', 'SprintControllerTest' => 'tests/SprintControllerTest.php', + 'SprintCustomDateFieldTest' => 'tests/SprintCustomFieldTest.php', 'SprintDAO' => 'storage/SprintDAO.php', 'SprintDataView' => 'view/SprintDataView.php', 'SprintDataViewController' => 'controller/SprintDataViewController.php', @@ -60,6 +61,7 @@ 'SprintTransaction' => 'storage/SprintTransaction.php', 'SprintUIEventListener' => 'events/SprintUIEventListener.php', 'SprintUIInterface' => 'controller/SprintUIInterface.php', + 'SprintValidator' => 'util/SprintValidator.php', 'SprintView' => 'view/SprintView.php', 'TasksTableView' => 'view/TasksTableView.php', 'UserOpenTasksView' => 'view/UserOpenTasksView.php', @@ -89,6 +91,7 @@ 'SprintBuildStatsTest' => 'SprintTestCase', 'SprintController' => 'PhabricatorController', 'SprintControllerTest' => 'SprintTestCase', + 'SprintCustomDateFieldTest' => 'SprintTestCase', 'SprintDAO' => 'PhabricatorLiskDAO', 'SprintDataView' => 'SprintView', 'SprintDataViewController' => 'SprintController', diff --git a/src/customfield/SprintProjectCustomField.php b/src/customfield/SprintProjectCustomField.php index b7989c8..8654ea7 100644 --- a/src/customfield/SprintProjectCustomField.php +++ b/src/customfield/SprintProjectCustomField.php @@ -7,24 +7,12 @@ abstract class SprintProjectCustomField extends PhabricatorProjectCustomField implements PhabricatorStandardCustomFieldInterface { - /** - * Use this function to determine whether to show sprint fields - * - * public function renderPropertyViewValue(array $handles) { - * if (!$this->shouldShowSprintFields()) { - * return - * } - * // Actually show something - * - * NOTE: You can NOT call this in functions like "shouldAppearInEditView" because - * $this->getObject() is not available yet. - * - */ - protected function shouldShowSprintFields() - { - if ($this->getObject() instanceof PhabricatorProject) { - return (strpos($this->getObject()->getName(), SprintConstants::MAGIC_WORD) !== FALSE); - } + + protected function isSprint() { + $validator = new SprintValidator; + $is_sprint = call_user_func(array($validator, 'checkForSprint'), + array($validator, 'shouldShowSprintFields'), $this->getObject()); + return $is_sprint; } /** @@ -52,25 +40,25 @@ } public function renderDateProxyPropertyViewValue($date_proxy, $handles) { - if (!$this->shouldShowSprintFields()) { - return null; + $is_sprint = $this->isSprint(); + + if ($is_sprint && ($date_proxy->getFieldValue())) { + return $date_proxy->renderPropertyViewValue($handles); + } else { + return null; } - if ($date_proxy->getFieldValue()) - { - return $date_proxy->renderPropertyViewValue($handles); - } - return null; } /** * @param string $time */ public function renderDateProxyEditControl($date_proxy, $time) { - if (!$this->shouldShowSprintFields()) { + $is_sprint = $this->isSprint(); + + if ($is_sprint && $date_proxy) { + return $this->newDateControl($date_proxy, $time); + } else { return null; - } - if ($date_proxy) { - return $this->newDateControl($date_proxy, $time); } } @@ -79,14 +67,10 @@ return $this->getProxy()->renderPropertyViewLabel(); } return $this->getFieldName(); - } public function renderPropertyViewValue(array $handles) { - if ($this->getProxy()) { return $this->getProxy()->renderPropertyViewValue($handles); - } - throw new PhabricatorCustomFieldImplementationIncompleteException($this); } // == Edit View @@ -95,10 +79,7 @@ } public function renderEditControl(array $handles) { - if ($this->getProxy()) { return $this->getProxy()->renderEditControl($handles); - } - throw new PhabricatorCustomFieldImplementationIncompleteException($this); } public function newDateControl($proxy, $time) { diff --git a/src/tests/SprintApplicationTest.php b/src/tests/SprintApplicationTest.php index f64c739..5b809f4 100644 --- a/src/tests/SprintApplicationTest.php +++ b/src/tests/SprintApplicationTest.php @@ -22,23 +22,20 @@ public function testgetShortDescription() { $burndown_application = new SprintApplication; $description = $burndown_application->getShortDescription(); - $this->assertEquals('Build burndowns', $description); + $this->assertEquals('Build Sprints', $description); } public function testgetEventListeners() { $burndown_application = new SprintApplication; $eventlistener = $burndown_application->getEventListeners(); $this->assertInstanceOf('BurndownActionMenuEventListener', $eventlistener[0]); + $this->assertInstanceOf('SprintUIEventListener', $eventlistener[1]); } public function testgetRoutes() { $burndown_application = new SprintApplication; $routes = $burndown_application->getRoutes(); $assertion = array( - '/project/' => array( - 'view/(?P<id>[1-9]\d*)/' - => 'SprintProjectProfileController', - ), '/sprint/' => array( 'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorProjectEditMainController', '' => 'SprintListController', @@ -81,8 +78,7 @@ ), ), '/tag/' => array( - '(?P<slug>[^/]+)/' => 'SprintProjectProfileController', - '(?P<slug>[^/]+)/board/' => 'SprintBoardViewController', + '(?P<slug>[^/]+)/sboard/' => 'SprintBoardViewController', ), ); $this->assertEquals($assertion, $routes); diff --git a/src/tests/SprintCustomFieldTest.php b/src/tests/SprintCustomFieldTest.php new file mode 100644 index 0000000..bd659ed --- /dev/null +++ b/src/tests/SprintCustomFieldTest.php @@ -0,0 +1,204 @@ +<?php +final class SprintCustomFieldTest extends SprintTestCase { + + public function testgetBeginFieldName() { + $subclassname = new SprintBeginDateField(); + $fieldname = $subclassname->getFieldName(); + $this->assertEquals($fieldname, 'Sprint Start Date'); + } + + public function testgetBeginFieldKey() { + $subclassname = new SprintBeginDateField(); + $fieldname = $subclassname->getFieldKey(); + $this->assertEquals($fieldname, 'isdc:sprint:startdate'); + } + + public function testgetBeginFieldDescription() { + $subclassname = new SprintBeginDateField(); + $fieldname = $subclassname->getFieldDescription(); + $this->assertEquals($fieldname, 'When a sprint starts'); + } + + public function testgetStoryPointsFieldName() { + $subclassname = new SprintTaskStoryPointsField(); + $fieldname = $subclassname->getFieldName(); + $this->assertEquals($fieldname, 'Story Points'); + } + + public function testgetStoryPointsFieldKey() { + $subclassname = new SprintTaskStoryPointsField(); + $fieldname = $subclassname->getFieldKey(); + $this->assertEquals($fieldname, 'isdc:sprint:storypoints'); + } + + public function testgetStoryPointsFieldDescription() { + $subclassname = new SprintTaskStoryPointsField(); + $fieldname = $subclassname->getFieldDescription(); + $this->assertEquals($fieldname, 'Estimated story points for this task'); + } + + public function testgetEndFieldName() { + $subclassname = new SprintEndDateField(); + $fieldname = $subclassname->getFieldName(); + $this->assertEquals($fieldname, 'Sprint End Date'); + } + + public function testgetEndFieldKey() { + $subclassname = new SprintEndDateField(); + $fieldname = $subclassname->getFieldKey(); + $this->assertEquals($fieldname, 'isdc:sprint:enddate'); + } + + public function testgetEndFieldDescription() { + $subclassname = new SprintEndDateField(); + $fieldname = $subclassname->getFieldDescription(); + $this->assertEquals($fieldname, 'When a sprint ends'); + } + + public function testgetDateFieldProxy() { + $classname = 'SprintProjectCustomField'; + $datefield = new PhabricatorStandardCustomFieldDate(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('getDateFieldProxy')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('getDateFieldProxy') + ->with($datefield, $this->anything(), $this->anything()) + ->will($this->returnValue($datefield)); + + $proxy = $mock->getDateFieldProxy($datefield, $this->anything(), $this->anything()); + $this->assertEquals('PhabricatorStandardCustomFieldDate', get_class($proxy)); + } + + public function testCustomFieldImplementationIncompleteException() { + $this->setExpectedException('PhabricatorCustomFieldImplementationIncompleteException'); + $classname = 'PhabricatorCustomField'; + $datefield = new SprintBeginDateField(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('getFieldKey')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('getFieldKey') + ->will($this->throwException(new PhabricatorCustomFieldImplementationIncompleteException($datefield))); + + $mock->getFieldKey(); + } + + public function testnewDateControl() + { + $classname = 'SprintProjectCustomField'; + $datecontrol = new AphrontFormDateControl(); + $proxy = new PhabricatorStandardCustomFieldDate(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('newDateControl')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('newDateControl') + ->with($proxy, $this->anything()) + ->will($this->returnValue($datecontrol)); + + $control = $mock->newDateControl($proxy, $this->anything()); + $this->assertEquals('AphrontFormDateControl', get_class($control)); + } + + public function testcheckForSprint() { + $validator = new SprintValidator(); + $mword = SprintConstants::MAGIC_WORD; + $showfields = array($validator, 'shouldShowSprintFields'); + $project = id(new PhabricatorProject())->setName($mword.'Test'); + $is_sprint = $validator->checkForSprint($showfields, $project); + $this->assertTrue($is_sprint); + } + + public function testcheckForNonSprint() { + $validator = new SprintValidator(); + $showfields = array($validator, 'shouldShowSprintFields'); + $project = id(new PhabricatorProject())->setName('Test'); + $is_sprint = $validator->checkForSprint($showfields, $project); + $this->assertFalse($is_sprint); + } + + public function testrenderDateProxyPropertyViewValue() + { + $classname = 'SprintProjectCustomField'; + $datefield = new PhabricatorStandardCustomFieldDate(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('renderDateProxyPropertyViewValue')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('renderDateProxyPropertyViewValue') + ->with($datefield, $this->anything()) + ->will($this->returnValue($datefield)); + + $proxy = $mock->renderDateProxyPropertyViewValue($datefield, $this->anything()); + $this->assertEquals('PhabricatorStandardCustomFieldDate', get_class($proxy)); + } + + public function testrenderDateProxyEditControl() + { + $classname = 'SprintProjectCustomField'; + $datefield = new PhabricatorStandardCustomFieldDate(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('renderDateProxyEditControl')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('renderDateProxyEditControl') + ->with($datefield, $this->anything()) + ->will($this->returnValue($datefield)); + + $proxy = $mock->renderDateProxyEditControl($datefield, $this->anything()); + $this->assertEquals('PhabricatorStandardCustomFieldDate', get_class($proxy)); + } + + public function testrenderPropertyViewValue() + { + $classname = 'SprintProjectCustomField'; + $proxy = new PhabricatorStandardCustomFieldDate(); + $handles = array(); + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('renderPropertyViewValue')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('renderPropertyViewValue') + ->with($handles) + ->will($this->returnValue($proxy)); + + $this->assertSame($proxy, $mock->renderPropertyViewValue($handles)); + } + + public function testgetStandardCustomFieldNamespace() + { + $classname = 'SprintProjectCustomField'; + + $mock = $this->getMockBuilder($classname) + ->disableOriginalConstructor() + ->setMethods(array('getStandardCustomFieldNamespace')) + ->getMockforAbstractClass(); + + $mock->expects($this->once()) + ->method('getStandardCustomFieldNamespace') + ->will($this->returnValue('project')); + + $value = $mock->getStandardCustomFieldNamespace(); + $this->assertEquals('project', $value); + } + +} \ No newline at end of file diff --git a/src/tests/SprintQueryTest.php b/src/tests/SprintQueryTest.php index a989afd..ad3b96e 100644 --- a/src/tests/SprintQueryTest.php +++ b/src/tests/SprintQueryTest.php @@ -10,7 +10,6 @@ public function testRequestSetUser() { $r = new AphrontRequest('example.com', '/'); - var_dump($r); $user = $this->generateNewTestUser(); $r->setUser($user); $this->assertEquals($user, $r->getUser()); diff --git a/src/tests/SprintTestCase.php b/src/tests/SprintTestCase.php index 26842d4..98f55af 100644 --- a/src/tests/SprintTestCase.php +++ b/src/tests/SprintTestCase.php @@ -191,6 +191,10 @@ return $user; } + protected function generateNewTestProject() { + $project = id(new PhabricatorProject()); + return $project; + } /** * Throws unless tests are currently executing. This method can be used to diff --git a/src/util/SprintValidator.php b/src/util/SprintValidator.php new file mode 100644 index 0000000..1ac0fc4 --- /dev/null +++ b/src/util/SprintValidator.php @@ -0,0 +1,17 @@ +<?php + +final class SprintValidator { + + public function checkForSprint($showfields, $project) { + $show = $showfields($project); + if ($show === false) { + return false; + } else { + return true; + } + } + + public function shouldShowSprintFields($project) { + return (stripos($project->getName(), SprintConstants::MAGIC_WORD)); + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/181866 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I02cbf925cb33d0fdd9a46bd09d458fd0f321579d Gerrit-PatchSet: 1 Gerrit-Project: phabricator/extensions/Sprint Gerrit-Branch: master Gerrit-Owner: Christopher Johnson (WMDE) <christopher.john...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits