View Issue Details

IDProjectCategoryView StatusLast Update
0008612mantisbtapi soappublic2010-02-22 14:34
Reporterrprouse Assigned Torombert  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.1.0rc3 
Target Version1.2.0Fixed in Version1.2.0 
Summary0008612: MantisConnect does not expose Time Tracking on Notes or Issues
Description

None of the new Billing/Time Tracking information is exposed through the SOAP API.

  • Should be able to get/set time for each note in the IssueNoteData structure.
  • It would be nice to include a getter for the total time for an issue in the IssueData structure.
  • Needs to take into account the minimum user level for access to billing information.
Additional Information

If I get the time, I will submit a patch. I have been using the billing extensively lately and want to write a quick program to pull the data out for me so that I can use it for invoicing.

Tagspatch
Attached Files
0001-Configure-the-SOAP-client-to-never-cache-the-WSDL.patch (941 bytes)   
From f4f39c8334e5c7b4755ed5c9122cfbd3e61e9c9a Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Wed, 21 Oct 2009 17:48:19 +0300
Subject: [PATCH 1/3] Configure the SOAP client to never cache the WSDL

This causes strange issue when testing, and changes in the actual
WSDL definition are propagated to the client, which is
not desired when developing against the SOAP API.
---
 tests/soap/SoapBase.php |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tests/soap/SoapBase.php b/tests/soap/SoapBase.php
index 34c665f..eba48f1 100644
--- a/tests/soap/SoapBase.php
+++ b/tests/soap/SoapBase.php
@@ -46,6 +46,7 @@ class SoapBase extends PHPUnit_Framework_TestCase {
 		       $GLOBALS['MANTIS_TESTSUITE_SOAP_HOST'],
 		        array(  'trace'      => true,
 		                'exceptions' => true,
+		        		'cache_wsdl' => WSDL_CACHE_NONE
 		             )
 		     
 		    );
-- 
1.6.4.2

0002-Issue-8612-MantisConnect-does-not-expose-Time-Tracki.patch (7,524 bytes)   
From 4fe6c22c9e3cba3e959298c67d7916dc8c11dfa4 Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Wed, 21 Oct 2009 15:45:12 +0300
Subject: [PATCH 2/3] Issue #8612: MantisConnect does not expose Time Tracking on Notes or Issues

Expose the invidual time spent on each IssueNoteData. Checks are performed
to see if the user has the required access level.

A new utility function mci_get_time_tracking_from_note has been added to
centralise access control checks and conversions.
---
 api/soap/mantisconnect.php |    3 ++-
 api/soap/mc_api.php        |   19 +++++++++++++++++++
 api/soap/mc_issue_api.php  |   24 +++++++++++++++---------
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index ca0f4cc..c757cc7 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -211,7 +211,8 @@ $l_oServer->wsdl->addComplexType(
 		'text'				=>	array( 'name' => 'text',			'type' => 'xsd:string', 'minOccurs' => '0'),
 		'view_state'		=>	array( 'name' => 'view_state',		'type' => 'tns:ObjectRef', 'minOccurs' => '0'),
 		'date_submitted'	=>	array( 'name' => 'date_submitted',	'type' => 'xsd:dateTime', 'minOccurs' => '0'),
-		'last_modified'		=>	array( 'name' => 'last_modified',	'type' => 'xsd:dateTime', 'minOccurs' => '0')
+		'last_modified'		=>	array( 'name' => 'last_modified',	'type' => 'xsd:dateTime', 'minOccurs' => '0'),
+		'time_tracking'		=> 	array( 'name' => 'time_tracking',	'type' => 'xsd:integer', 'minOccurs' => '0')
 	)
 );
 
diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php
index 707808f..52c61de 100644
--- a/api/soap/mc_api.php
+++ b/api/soap/mc_api.php
@@ -329,6 +329,25 @@ function mci_category_as_array_by_id( $p_category_id ) {
 }
 
 /**
+ * Returns time tracking information from a bug note.
+ * 
+ * @param int $p_issue_id The id of the issue
+ * @param Array $p_note A note as passed to the soap api methods
+ * 
+ * @return String the string time entry to be added to the bugnote, in 'HH:mm' format
+ */
+function mci_get_time_tracking_from_note( $p_issue_id, $p_note) {
+	
+	if ( !access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id ) )
+		return '00:00';
+
+	if ( !isset( $p_note['time_tracking'] ))
+		return '00:00';
+		
+	return db_minutes_to_hhmm($p_note['time_tracking']);
+}
+
+/**
  * SECURITY NOTE: these globals are initialized here to prevent them
  * being spoofed if register_globals is turned on
  */
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index f2d5536..7b93a9b 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -258,7 +258,8 @@ function mci_issue_get_notes( $p_issue_id ) {
 	$t_lang = mci_get_user_lang( $t_user_id );
 	$t_project_id = bug_get_field( $p_issue_id, 'project_id' );
 	$t_user_bugnote_order = 'ASC'; // always get the notes in ascending order for consistency to the calling application.
-
+	$t_has_time_tracking_access = access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id );
+	
 	$t_result = array();
 	foreach( bugnote_get_all_visible_bugnotes( $p_issue_id, $t_user_bugnote_order, 0 ) as $t_value ) {
 		$t_bugnote = array();
@@ -268,6 +269,8 @@ function mci_issue_get_notes( $p_issue_id ) {
 		$t_bugnote['last_modified'] = timestamp_to_iso8601( $t_value->last_modified );
 		$t_bugnote['text'] = $t_value->note;
 		$t_bugnote['view_state'] = mci_enum_get_array_by_id( $t_value->view_state, 'view_state', $t_lang );
+		$t_bugnote['time_tracking'] = $t_has_time_tracking_access ? $t_value->time_tracking : 0;
+		
 		$t_result[] = $t_bugnote;
 	}
 
@@ -419,7 +422,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
 	$t_priority_id = isset( $p_issue['priority'] ) ? mci_get_priority_id( $p_issue['priority'] ) : config_get( 'default_bug_priority' );
 	$t_severity_id = isset( $p_issue['severity'] ) ?  mci_get_severity_id( $p_issue['severity'] ) : config_get( 'default_bug_severity' );
 	$t_status_id = isset ( $p_issue['status'] ) ? mci_get_status_id( $p_issue['status'] ) : config_get( 'bug_submit_status' );
-	$t_reproducibility_id = isset ( $p_issue['reproducibility'] ) ?  mci_get_reproducibility_id( $p_issue['reproducibility'] ) : config_get( 'default_bug_reproducibility' );
+	$t_reproducibility_id = isset ( $p_issue['reproducibility'] ) ? mci_get_reproducibility_id( $p_issue['reproducibility'] ) : config_get( 'default_bug_reproducibility' );
 	$t_resolution_id =  isset ( $p_issue['resolution'] ) ? mci_get_resolution_id( $p_issue['resolution'] ) : config_get('default_bug_resolution');
 	$t_projection_id = isset ( $p_issue['projection'] ) ? mci_get_projection_id( $p_issue['projection'] ) : config_get('default_bug_resolution');
 	$t_eta_id = isset ( $p_issue['eta'] ) ? mci_get_eta_id( $p_issue['eta'] ) : config_get('default_bug_eta');
@@ -535,7 +538,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
 	$t_issue_id = $t_bug_data->create();
 
 	mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'] );
-
+	
 	if( isset( $t_notes ) && is_array( $t_notes ) ) {
 		foreach( $t_notes as $t_note ) {
 			if( isset( $t_note['view_state'] ) ) {
@@ -545,7 +548,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
 			}
 
 			$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-			bugnote_add( $t_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
+			bugnote_add( $t_issue_id, $t_note['text'], mci_get_time_tracking_from_note($t_issue_id, $t_note), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
 		}
 	}
 
@@ -700,9 +703,9 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
 
 	# submit the issue
 	$t_is_success = $t_bug_data->update( /* update_extended */ true, /* bypass_email */ true );
-
+	
 	mci_issue_set_custom_fields( $p_issue_id, $p_issue['custom_fields'] );
-
+	
 	if ( isset( $p_issue['notes'] ) && is_array( $p_issue['notes'] ) ) {
 		foreach ( $p_issue['notes'] as $t_note ) {
 			if ( isset( $t_note['view_state'] ) ) {
@@ -718,10 +721,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
 					bugnote_set_text( $t_bugnote_id, $t_note['text'] );
 					bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
 					bugnote_date_update( $t_bugnote_id );
+					if ( isset( $t_note['time_tracking'] ))
+						bugnote_set_time_tracking($t_bugnote_id, mci_get_time_tracking_from_note($p_issue_id, $t_note));
 				}
 			} else {
 				$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-				bugnote_add( $p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
+				
+				bugnote_add( $p_issue_id, $t_note['text'], mci_get_time_tracking_from_note($p_issue_id, $t_note), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
 			}
 		}
 	}
@@ -802,9 +808,9 @@ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, $p_note ) {
 			'id' => config_get( 'default_bug_view_status' ),
 		);
 	}
-
+	
 	$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-	return bugnote_add( $p_issue_id, $p_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id );
+	return bugnote_add( $p_issue_id, $p_note['text'], mci_get_time_tracking_from_note($p_issue_id, $p_note), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id );
 }
 
 /**
-- 
1.6.4.2

0003-Added-separate-testAddNoteWithTimeTracking.patch (2,465 bytes)   
From 6766016e7b77827223a42a4d1693058b5bc78b1f Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Wed, 21 Oct 2009 17:21:37 +0300
Subject: [PATCH 3/3] Added separate testAddNoteWithTimeTracking

The test is skipped if time tracking is not enabled on the server.
---
 tests/soap/IssueNoteTest.php |   56 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/tests/soap/IssueNoteTest.php b/tests/soap/IssueNoteTest.php
index 7a3fba6..b72aec2 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,58 @@ 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() {
+
+		$timeTrackingEnabled = $this->client->mc_config_get_string($this->userName, $this->password, 'time_tracking_enabled');
+		if ( !$timeTrackingEnabled ) {
+			$this->markTestSkipped('Time tracking is not enabled');
+		}
+
+		$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.
-- 
1.6.4.2

0002-Issue-8612-Expose-time-tracking-on-notes-using-the-S.patch (6,299 bytes)   
From b06bb059b6d971fbcd6c304df87f68e90b385ecd Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Wed, 21 Oct 2009 15:45:12 +0300
Subject: [PATCH 2/3] Issue #8612: Expose time tracking on notes using the SOAP API

Expose the invidual time spent on each IssueNoteData. Checks are performed
to see if the user has the required access level.

A new utility function mci_get_time_tracking_from_note has been added to
centralise access control checks and conversions.
---
 api/soap/mantisconnect.php |    3 ++-
 api/soap/mc_api.php        |   19 +++++++++++++++++++
 api/soap/mc_issue_api.php  |   22 ++++++++++++++--------
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php
index ca0f4cc..c757cc7 100644
--- a/api/soap/mantisconnect.php
+++ b/api/soap/mantisconnect.php
@@ -211,7 +211,8 @@ $l_oServer->wsdl->addComplexType(
 		'text'				=>	array( 'name' => 'text',			'type' => 'xsd:string', 'minOccurs' => '0'),
 		'view_state'		=>	array( 'name' => 'view_state',		'type' => 'tns:ObjectRef', 'minOccurs' => '0'),
 		'date_submitted'	=>	array( 'name' => 'date_submitted',	'type' => 'xsd:dateTime', 'minOccurs' => '0'),
-		'last_modified'		=>	array( 'name' => 'last_modified',	'type' => 'xsd:dateTime', 'minOccurs' => '0')
+		'last_modified'		=>	array( 'name' => 'last_modified',	'type' => 'xsd:dateTime', 'minOccurs' => '0'),
+		'time_tracking'		=> 	array( 'name' => 'time_tracking',	'type' => 'xsd:integer', 'minOccurs' => '0')
 	)
 );
 
diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php
index dae2345..440f551 100644
--- a/api/soap/mc_api.php
+++ b/api/soap/mc_api.php
@@ -294,6 +294,25 @@ function mci_category_as_array_by_id( $p_category_id ) {
 }
 
 /**
+ * Returns time tracking information from a bug note.
+ * 
+ * @param int $p_issue_id The id of the issue
+ * @param Array $p_note A note as passed to the soap api methods
+ * 
+ * @return String the string time entry to be added to the bugnote, in 'HH:mm' format
+ */
+function mci_get_time_tracking_from_note( $p_issue_id, $p_note) {
+	
+	if ( !access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id ) )
+		return '00:00';
+
+	if ( !isset( $p_note['time_tracking'] ))
+		return '00:00';
+		
+	return db_minutes_to_hhmm($p_note['time_tracking']);
+}
+
+/**
  * SECURITY NOTE: these globals are initialized here to prevent them
  * being spoofed if register_globals is turned on
  */
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index 9c0c588..31ef3d7 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -258,7 +258,8 @@ function mci_issue_get_notes( $p_issue_id ) {
 	$t_lang = mci_get_user_lang( $t_user_id );
 	$t_project_id = bug_get_field( $p_issue_id, 'project_id' );
 	$t_user_bugnote_order = 'ASC'; // always get the notes in ascending order for consistency to the calling application.
-
+	$t_has_time_tracking_access = access_has_bug_level( config_get( 'time_tracking_view_threshold' ), $p_issue_id );
+	
 	$t_result = array();
 	foreach( bugnote_get_all_visible_bugnotes( $p_issue_id, $t_user_bugnote_order, 0 ) as $t_value ) {
 		$t_bugnote = array();
@@ -268,6 +269,8 @@ function mci_issue_get_notes( $p_issue_id ) {
 		$t_bugnote['last_modified'] = timestamp_to_iso8601( $t_value->last_modified );
 		$t_bugnote['text'] = $t_value->note;
 		$t_bugnote['view_state'] = mci_enum_get_array_by_id( $t_value->view_state, 'view_state', $t_lang );
+		$t_bugnote['time_tracking'] = $t_has_time_tracking_access ? $t_value->time_tracking : 0;
+		
 		$t_result[] = $t_bugnote;
 	}
 
@@ -535,7 +538,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
 	$t_issue_id = $t_bug_data->create();
 
 	mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'] );
-
+	
 	if( isset( $t_notes ) && is_array( $t_notes ) ) {
 		foreach( $t_notes as $t_note ) {
 			if( isset( $t_note['view_state'] ) ) {
@@ -545,7 +548,7 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
 			}
 
 			$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-			bugnote_add( $t_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
+			bugnote_add( $t_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $t_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
 		}
 	}
 
@@ -700,9 +703,9 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
 
 	# submit the issue
 	$t_is_success = $t_bug_data->update( /* update_extended */ true, /* bypass_email */ true );
-
+	
 	mci_issue_set_custom_fields( $p_issue_id, $p_issue['custom_fields'] );
-
+	
 	if ( isset( $p_issue['notes'] ) && is_array( $p_issue['notes'] ) ) {
 		foreach ( $p_issue['notes'] as $t_note ) {
 			if ( isset( $t_note['view_state'] ) ) {
@@ -718,10 +721,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
 					bugnote_set_text( $t_bugnote_id, $t_note['text'] );
 					bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
 					bugnote_date_update( $t_bugnote_id );
+					if ( isset( $t_note['time_tracking'] ) )
+						bugnote_set_time_tracking( $t_bugnote_id, mci_get_time_tracking_from_note( $p_issue_id, $t_note ) );
 				}
 			} else {
 				$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-				bugnote_add( $p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
+				
+				bugnote_add( $p_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
 			}
 		}
 	}
@@ -802,9 +808,9 @@ function mc_issue_note_add( $p_username, $p_password, $p_issue_id, $p_note ) {
 			'id' => config_get( 'default_bug_view_status' ),
 		);
 	}
-
+	
 	$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
-	return bugnote_add( $p_issue_id, $p_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id );
+	return bugnote_add( $p_issue_id, $p_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $p_note ), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id );
 }
 
 /**
-- 
1.6.4.2

0003-Issue-8612-Test-exposing-time-tracking-on-notes-usin.patch (6,361 bytes)   
From 97accd6abfe5122ead2e4939e8543ad8b322cf9e Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
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

Activities

vboctor

vboctor

2007-12-29 04:21

manager   ~0016519

Makes sense to add this functionality. I'll review the patch when available and provide feedback. Once done, I will integrate it.

rombert

rombert

2009-10-21 11:02

reporter   ~0023270

Last edited: 2009-10-21 11:03

I'm going to post a series of patches for feedback. This is a work on progress, and is rebased against the fixes from 0011061.

I'm interested in both developer and tester feedback. Please note that there are more SOAP tests to be added, I just created one to verify the general workflow.

And, if you pick nothing else, please apply the first patch in the series. It just might save someone a couple of very frustrating hours.

rombert

rombert

2009-10-22 11:37

reporter   ~0023281

I've added two more tests and reviewed the code. As far as I can tell, it should be correct - no logic or syntax errors and safe - as it uses the same access level logic that as the bug view page.

I've added test cases to support all paths.

I'm going to hold now and patiently wait for some feedback.

Thanks,

Robert

dhx

dhx

2009-10-26 08:15

reporter   ~0023336

This is a little offtopic... but I was actually half thinking that the inbuilt time tracking features of Mantis should be ripped out and placed into a plugin. So is there currently any way for plugins to expose information or communicate via the SOAP API?

rombert

rombert

2009-10-26 08:56

reporter   ~0023344

(In reply to comment 0000004)

This is a little offtopic... but I was actually half thinking that the inbuilt
time tracking features of Mantis should be ripped out and placed into a plugin.
So is there currently any way for plugins to expose information or communicate
via the SOAP API?

I'm not intimately aware of how the plugin system works, but I can tell you that the SOAP API properly exposes custom fields on issues, but has no provisions for adding data to notes.

IMO any move of the time tracking data to a plugin system should be accompanied by allowing the SOAP API to read such plugin-provided data. I can try and handle the SOAP API part when the time comes.

rombert

rombert

2009-10-27 13:01

reporter   ~0023413

@vboctor : what would you say of this commit landing in master and possibly target for a 1.2.1 release, after more testing?

rombert

rombert

2009-11-24 17:18

reporter   ~0023801

1.3 is too far away to wait.

Related Changesets

MantisBT: master-1.2.x 878cc23e

2009-10-21 08:45

rombert


Details Diff
Issue 0008612: Expose time tracking on notes using the SOAP API

Expose the invidual time spent on each IssueNoteData. Checks are performed
to see if the user has the required access level.

A new utility function mci_get_time_tracking_from_note has been added to
centralise access control checks and conversions.
Affected Issues
0008612
mod - api/soap/mc_api.php Diff File
mod - api/soap/mantisconnect.php Diff File
mod - api/soap/mc_issue_api.php Diff File

MantisBT: master 8b69aa2a

2009-10-21 08:45

rombert


Details Diff
Issue 0008612: Expose time tracking on notes using the SOAP API

Expose the invidual time spent on each IssueNoteData. Checks are performed
to see if the user has the required access level.

A new utility function mci_get_time_tracking_from_note has been added to
centralise access control checks and conversions.
Affected Issues
0008612
mod - api/soap/mc_api.php Diff File
mod - api/soap/mantisconnect.php Diff File
mod - api/soap/mc_issue_api.php Diff File

MantisBT: master-1.2.x 952fb1d8

2009-10-21 10:21

rombert


Details Diff
Issue 0008612: 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.
Affected Issues
0008612
mod - tests/soap/IssueAddTest.php Diff File
mod - tests/soap/SoapBase.php Diff File
mod - tests/soap/IssueNoteTest.php Diff File
mod - tests/soap/IssueUpdateTest.php Diff File

MantisBT: master b8711140

2009-10-21 10:21

rombert


Details Diff
Issue 0008612: 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.
Affected Issues
0008612
mod - tests/soap/IssueAddTest.php Diff File
mod - tests/soap/SoapBase.php Diff File
mod - tests/soap/IssueNoteTest.php Diff File
mod - tests/soap/IssueUpdateTest.php Diff File