From 97accd6abfe5122ead2e4939e8543ad8b322cf9e Mon Sep 17 00:00:00 2001 From: Robert Munteanu Date: Wed, 21 Oct 2009 17:21:37 +0300 Subject: [PATCH 3/3] Issue #8612: Test exposing time tracking on notes using the SOAP API A utility test method has been added for skipping tests when the Mantis installation does not have time tracking enabled. The following scenarios are tested: - adding a note with time tracking data; - adding an issue with an embedded time tracking note; - updating an issue with a new time tracking note. --- tests/soap/IssueAddTest.php | 41 ++++++++++++++++++++++++++++++- tests/soap/IssueNoteTest.php | 53 ++++++++++++++++++++++++++++++++++++++- tests/soap/IssueUpdateTest.php | 51 ++++++++++++++++++++++++++++++++++++++ tests/soap/SoapBase.php | 8 ++++++ 4 files changed, 150 insertions(+), 3 deletions(-) diff --git a/tests/soap/IssueAddTest.php b/tests/soap/IssueAddTest.php index a062136..266d37c 100644 --- a/tests/soap/IssueAddTest.php +++ b/tests/soap/IssueAddTest.php @@ -130,7 +130,7 @@ class IssueAddTest extends SoapBase { $this->password, $issueId); } - + /** * This issue tests the following: * 1. Creating an issue with some fields that are typically not used at creation time. @@ -173,4 +173,43 @@ class IssueAddTest extends SoapBase { $this->password, $issueId); } + + /** + * A test cases that tests the creation of issues + * with a note passed in which contains time tracking data. + */ + public function testCreateIssueWithTimeTrackingNote() { + + $this->skipIfTimeTrackingIsNotEnabled(); + + $issueToAdd = $this->getIssueToAdd( 'testCreateIssueWithNote' ); + $issueToAdd['notes'] = array( + array( + 'text' => "first note", + 'time_tracking' => "30" + ) + ); + + $issueId = $this->client->mc_issue_add( + $this->userName, + $this->password, + $issueToAdd); + + $issue = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + // verify note existence and time tracking data + $this->assertEquals( 1, count( $issue->notes ) ); + + $note = $issue->notes[0]; + + $this->assertEquals( 30, $note->time_tracking ); + + $this->client->mc_issue_delete( + $this->userName, + $this->password, + $issueId); + } } diff --git a/tests/soap/IssueNoteTest.php b/tests/soap/IssueNoteTest.php index 7a3fba6..0107497 100644 --- a/tests/soap/IssueNoteTest.php +++ b/tests/soap/IssueNoteTest.php @@ -53,9 +53,9 @@ class IssueNoteTest extends SoapBase { $issueId); $noteData = array( - 'text' => "first note", + 'text' => "first note" ); - + $issueNoteId = $this->client->mc_issue_note_add( $this->userName, $this->password, @@ -95,6 +95,55 @@ class IssueNoteTest extends SoapBase { /** * A test case that tests the following: * 1. Create an issue. + * 2. Add a note to the issue by specifying the text and time_tracking. + * 3. Get the issue. + * 4. Verify the note id against the one returned when adding the note. + * 5. Verify the time_tracking entry + * 6. Delete the issue. + */ + public function testAddNoteWithTimeTracking() { + + $this->skipIfTimeTrackingIsNotEnabled(); + + $issueToAdd = $this->getIssueToAdd( 'IssueNoteTest.testAddNoteWithTimeTracking' ); + + $issueId = $this->client->mc_issue_add( + $this->userName, + $this->password, + $issueToAdd); + + $noteData = array( + 'text' => "first note", + 'time_tracking' => "30" + ); + + $issueNoteId = $this->client->mc_issue_note_add( + $this->userName, + $this->password, + $issueId, + $noteData); + + $issueWithNote = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + $this->assertEquals( 1, count( $issueWithNote->notes ) ); + + $note = $issueWithNote->notes[0]; + + $this->assertEquals( 30, $note->time_tracking ); + + $this->client->mc_issue_delete( + $this->userName, + $this->password, + $issueId); + + } + + /** + * A test case that tests the following: + * 1. Create an issue. * 2. Add a note to the issue. * 3. Get the issue. * 4. Verify that the issue has one note. diff --git a/tests/soap/IssueUpdateTest.php b/tests/soap/IssueUpdateTest.php index 1762549..ba88ca4 100644 --- a/tests/soap/IssueUpdateTest.php +++ b/tests/soap/IssueUpdateTest.php @@ -232,4 +232,55 @@ class IssueUpdateTest extends SoapBase { $this->password, $issueId); } + + /** + * This test case tests the following: + * 1. Creation of an issue. + * 2. Updating the issue with a time tracking note + * 3. Verifying that the time tracking note on the issue is preseved + * 4. Deleting the issue. + */ + public function testUpdateWithTimeTrackingNote() { + + $this->skipIfTimeTrackingIsNotEnabled(); + + $issueToAdd = $this->getIssueToAdd( 'IssueUpdateTest.testUpdateWithTimeTrackingNote' ); + + $issueId = $this->client->mc_issue_add( + $this->userName, + $this->password, + $issueToAdd); + + $createdIssue = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + $createdIssue->notes = array( + array ( + 'text' => "first note", + 'time_tracking' => "30" + ) + ); + + $this->client->mc_issue_update( + $this->userName, + $this->password, + $issueId, + $createdIssue); + + $issueWithNote = $this->client->mc_issue_get( + $this->userName, + $this->password, + $issueId); + + $this->assertEquals( 1, count( $issueWithNote->notes ) ); + + $this->assertEquals( 30, $issueWithNote->notes[0]->time_tracking); + + $this->client->mc_issue_delete( + $this->userName, + $this->password, + $issueId); + } } diff --git a/tests/soap/SoapBase.php b/tests/soap/SoapBase.php index eba48f1..ad20e86 100644 --- a/tests/soap/SoapBase.php +++ b/tests/soap/SoapBase.php @@ -59,6 +59,14 @@ class SoapBase extends PHPUnit_Framework_TestCase { protected function getCategory() { return 'General'; } + + protected function skipIfTimeTrackingIsNotEnabled() { + + $timeTrackingEnabled = $this->client->mc_config_get_string($this->userName, $this->password, 'time_tracking_enabled'); + if ( !$timeTrackingEnabled ) { + $this->markTestSkipped('Time tracking is not enabled'); + } + } protected function getIssueToAdd( $testCase ) { return array( -- 1.6.4.2