diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php
index 0e491b6d2d..7ee6b60417 100644
--- a/api/soap/mc_api.php
+++ b/api/soap/mc_api.php
@@ -124,35 +124,67 @@ function mci_get_user_lang( $p_user_id ) {
return $t_lang;
}
-function mci_get_status_id( $p_status ) {
+function mci_get_status_id( &$p_status ) {
+ if ( !isset( $p_status ) ) {
+ return (int)config_get( 'bug_submit_status' );
+ }
+
return mci_get_enum_id_from_objectref( 'status', $p_status );
}
-function mci_get_severity_id( $p_severity ) {
+function mci_get_severity_id( &$p_severity ) {
+ if ( !isset( $p_severity ) ) {
+ return (int)config_get( 'default_bug_severity' );
+ }
+
return mci_get_enum_id_from_objectref( 'severity', $p_severity );
}
-function mci_get_priority_id( $p_priority ) {
+function mci_get_priority_id( &$p_priority ) {
+ if ( !isset( $p_priority ) ) {
+ return (int)config_get( 'default_bug_priority' );
+ }
+
return mci_get_enum_id_from_objectref( 'priority', $p_priority );
}
-function mci_get_reproducibility_id( $p_reproducibility ) {
+function mci_get_reproducibility_id( &$p_reproducibility ) {
+ if ( !isset( $p_reproducibility ) ) {
+ return (int)config_get( 'default_bug_reproducibility' );
+ }
+
return mci_get_enum_id_from_objectref( 'reproducibility', $p_reproducibility );
}
-function mci_get_resolution_id( $p_resolution ) {
+function mci_get_resolution_id( &$p_resolution ) {
+ if ( !isset( $p_resolution ) ) {
+ return (int)OPEN;
+ }
+
return mci_get_enum_id_from_objectref( 'resolution', $p_resolution );
}
-function mci_get_projection_id( $p_projection ) {
+function mci_get_projection_id( &$p_projection ) {
+ if ( !isset( $p_projection ) ) {
+ return (int)10;
+ }
+
return mci_get_enum_id_from_objectref( 'projection', $p_projection );
}
-function mci_get_eta_id( $p_eta ) {
+function mci_get_eta_id( &$p_eta ) {
+ if ( !isset( $p_eta ) ) {
+ return (int)10;
+ }
+
return mci_get_enum_id_from_objectref( 'eta', $p_eta );
}
-function mci_get_view_state_id( $p_view_state ) {
+function mci_get_view_state_id( &$p_view_state ) {
+ if ( !isset( $p_view_state ) ) {
+ return (int)config_get( 'default_bug_view_status' );
+ }
+
return mci_get_enum_id_from_objectref( 'view_state', $p_view_state );
}
@@ -222,7 +254,11 @@ function mci_user_get_accessible_subprojects( $p_user_id, $p_parent_project_id,
return $t_result;
}
-function translate_category_name_to_id( $p_category_name, $p_project_id ) {
+function translate_category_name_to_id( &$p_category_name, $p_project_id ) {
+ if ( !isset( $p_category_name ) ) {
+ return 0;
+ }
+
$t_cat_array = category_get_all_rows( $p_project_id );
foreach( $t_cat_array as $t_category_row ) {
if( $t_category_row['name'] == $p_category_name ) {
@@ -379,9 +415,9 @@ function mc_error_handler( $p_type, $p_error, $p_file, $p_line, $p_context ) {
# Get a stack trace if PHP provides the facility or xdebug is present
function error_get_stack_trace() {
- $t_stack = '';
+ $t_trace = '';
- if( extension_loaded( 'xdebug' ) ) {
+ if ( extension_loaded( 'xdebug' ) ) {
#check for xdebug presence
$t_stack = xdebug_get_function_stack();
@@ -392,23 +428,22 @@ function error_get_stack_trace() {
array_shift( $t_stack );
#remove the call to this function from the stack trace
-
foreach( $t_stack as $t_frame ) {
- $t_stack .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
+ $t_trace .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
$t_args = array();
- if( isset( $t_frame['params'] ) ) {
- $t_stack .= ' Params: ';
+ if ( isset( $t_frame['params'] ) && ( count( $t_frame['params'] ) > 0 ) ) {
+ $t_trace .= ' Params: ';
foreach( $t_frame['params'] as $t_value ) {
$t_args[] = error_build_parameter_string( $t_value );
}
- $t_stack .= '(' . implode( $t_args, ', ' ) . ')';
+ $t_trace .= '(' . implode( $t_args, ', ' ) . ')';
} else {
- $t_stack .= '()';
+ $t_trace .= '()';
}
- $t_stack .= "\n";
+ $t_trace .= "\n";
}
} else {
$t_stack = debug_backtrace();
@@ -417,7 +452,7 @@ function error_get_stack_trace() {
array_shift( $t_stack ); #remove the call to the error handler from the stack trace
foreach( $t_stack as $t_frame ) {
- $t_stack .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
+ $t_trace .= ( isset( $t_frame['file'] ) ? basename( $t_frame['file'] ) : 'UnknownFile' ) . ' L' . ( isset( $t_frame['line'] ) ? $t_frame['line'] : '?' ) . ' ' . ( isset( $t_frame['function'] ) ? $t_frame['function'] : 'UnknownFunction' );
$t_args = array();
if( isset( $t_frame['args'] ) ) {
@@ -425,14 +460,14 @@ function error_get_stack_trace() {
$t_args[] = error_build_parameter_string( $t_value );
}
- $t_stack .= '(' . implode( $t_args, ', ' ) . ')';
+ $t_trace .= '(' . implode( $t_args, ', ' ) . ')';
} else {
- $t_stack .= '()';
+ $t_trace .= '()';
}
- $t_stack .= "\n";
+ $t_trace .= "\n";
}
}
- return $t_stack;
+ return $t_trace;
}
diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php
index fe3d030bd9..f0729327c6 100644
--- a/api/soap/mc_issue_api.php
+++ b/api/soap/mc_issue_api.php
@@ -429,11 +429,8 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
$t_eta_id = mci_get_eta_id( $p_issue['eta'] );
$t_view_state_id = mci_get_view_state_id( $p_issue['view_state'] );
$t_reporter_id = mci_get_user_id( $p_issue['reporter'] );
- $t_category = $p_issue['category'];
- $t_version = $p_issue['version'];
$t_summary = $p_issue['summary'];
$t_description = $p_issue['description'];
- $t_custom_fields = $p_issue['custom_fields'];
if( $t_reporter_id == 0 ) {
$t_reporter_id = $t_user_id;
@@ -469,23 +466,25 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
return new soap_fault( 'Client', '', "User '$t_handler_id' does not exist." );
}
- $t_category_id = translate_category_name_to_id( $t_category, $t_project_id );
- if( $t_category_id == 0 ) {
- if ( is_blank( $t_category ) ) {
- return new soap_fault( 'Client', '', "Category cannot be empty." );
+ $t_category_id = translate_category_name_to_id( $p_issue['category'], $t_project_id );
+ if ( $t_category_id == 0 && !config_get( 'allow_no_category' ) ) {
+ if ( !isset( $p_issue['category'] ) || is_blank( $p_issue['category'] ) ) {
+ return new soap_fault( 'Client', '', "Category field must be supplied." );
} else {
- return new soap_fault( 'Client', '', "Category '$t_category' does not exist in project '$t_project_id'." );
+ return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_id'." );
}
}
- if ( isset( $t_version ) && !is_blank( $t_version ) && !version_get_id( $t_version, $t_project_id ) ) {
+ if ( isset( $p_issue['version'] ) && !is_blank( $p_issue['version'] ) && !version_get_id( $p_issue['version'], $t_project_id ) ) {
+ $t_version = $p_issue['version'];
+
$t_error_when_version_not_found = config_get( 'mc_error_when_version_not_found' );
if( $t_error_when_version_not_found == ON ) {
$t_project_name = project_get_name( $t_project_id );
- return new soap_fault( 'Client', '', "Version '$v_version' does not exist in project '$t_project_name'." );
+ return new soap_fault( 'Client', '', "Version '$t_version' does not exist in project '$t_project_name'." );
} else {
$t_version_when_not_found = config_get( 'mc_version_when_not_found' );
- $v_version = $t_version_when_not_found;
+ $t_version = $t_version_when_not_found;
}
}
@@ -497,22 +496,6 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
return new soap_fault( 'Client', '', "Mandatory field 'description' is missing." );
}
- if ( $t_priority_id == 0 ) {
- $t_priority_id = config_get( 'default_bug_priority' );
- }
-
- if ( $t_severity_id == 0 ) {
- $t_severity_id = config_get( 'default_bug_severity' );
- }
-
- if ( $t_view_state_id == 0 ) {
- $t_view_state_id = config_get( 'default_bug_view_status' );
- }
-
- if ( $t_reproducibility_id == 0 ) {
- $t_reproducibility_id = 10;
- }
-
$t_bug_data = new BugData;
$t_bug_data->project_id = $t_project_id;
$t_bug_data->reporter_id = $t_reporter_id;
@@ -524,19 +507,19 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
$t_bug_data->resolution = $t_resolution_id;
$t_bug_data->projection = $t_projection_id;
$t_bug_data->category_id = $t_category_id;
- $t_bug_data->date_submitted = isset( $v_date_submitted ) ? $v_date_submitted : '';
- $t_bug_data->last_updated = isset( $v_last_updated ) ? $v_last_updated : '';
+ $t_bug_data->date_submitted = isset( $p_issue['date_submitted'] ) ? $p_issue['date_submitted'] : '';
+ $t_bug_data->last_updated = isset( $p_issue['last_updated'] ) ? $p_issue['last_updated'] : '';
$t_bug_data->eta = $t_eta_id;
- $t_bug_data->os = isset( $v_os ) ? $v_os : '';
- $t_bug_data->os_build = isset( $v_os_build ) ? $v_os_build : '';
- $t_bug_data->platform = isset( $v_platform ) ? $v_platform : '';
- $t_bug_data->version = isset( $v_version ) ? $v_version : '';
- $t_bug_data->fixed_in_version = isset( $v_fixed_in_version ) ? $v_fixed_in_version : '';
- $t_bug_data->target_version = isset( $v_target_version ) ? $v_target_version : '';
- $t_bug_data->build = isset( $v_build ) ? $v_build : '';
+ $t_bug_data->os = isset( $p_issue['os'] ) ? $p_issue['os'] : '';
+ $t_bug_data->os_build = isset( $p_issue['os_build'] ) ? $p_issue['os_build'] : '';
+ $t_bug_data->platform = isset( $p_issue['platform'] ) ? $p_issue['platform'] : '';
+ $t_bug_data->version = isset( $p_issue['version'] ) ? $p_issue['version'] : '';
+ $t_bug_data->fixed_in_version = isset( $p_issue['fixed_in_version'] ) ? $p_issue['fixed_in_version'] : '';
+ $t_bug_data->target_version = isset( $p_issue['target_version'] ) ? $p_issue['target_version'] : '';
+ $t_bug_data->build = isset( $p_issue['build'] ) ? $p_issue['build'] : '';
$t_bug_data->view_state = $t_view_state_id;
$t_bug_data->summary = $t_summary;
- $t_bug_data->sponsorship_total = isset( $v_sponsorship_total ) ? $v_sponsorship_total : 0;
+ $t_bug_data->sponsorship_total = isset( $p_issue['sponsorship_total'] ) ? $p_issue['sponsorship_total'] : 0;
$t_bug_data->due_date = date_get_null();
# omitted:
@@ -544,13 +527,13 @@ function mc_issue_add( $p_username, $p_password, $p_issue ) {
# $t_bug_data->profile_id;
# extended info
$t_bug_data->description = $t_description;
- $t_bug_data->steps_to_reproduce = isset( $v_steps_to_reproduce ) ? $v_steps_to_reproduce : '';
- $t_bug_data->additional_information = isset( $v_additional_information ) ? $v_additional_information : '';
+ $t_bug_data->steps_to_reproduce = isset( $p_issue['steps_to_reproduce'] ) ? $p_issue['steps_to_reproduce'] : '';
+ $t_bug_data->additional_information = isset( $p_issue['additional_information'] ) ? $p_issue['additional_information'] : '';
# submit the issue
$t_issue_id = bug_create( $t_bug_data );
- mci_issue_set_custom_fields( $t_issue_id, $t_custom_fields );
+ mci_issue_set_custom_fields( $t_issue_id, $p_issue['custom_fields'] );
if( isset( $v_notes ) && is_array( $v_notes ) ) {
foreach( $v_notes as $t_note ) {
@@ -607,7 +590,6 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
$t_view_state_id = mci_get_view_state_id( $p_issue['view_state'] );
$t_reporter_id = mci_get_user_id( $p_issue['reporter'] );
$t_project = $p_issue['project'];
- $t_category = $p_issue['category'];
$t_summary = $p_issue['summary'];
$t_description = $p_issue['description'];
$t_custom_fields = $p_issue['custom_fields'];
@@ -636,13 +618,13 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
return new soap_fault( 'Client', '', "User '$t_handler_id' does not exist." );
}
- $t_category_id = translate_category_name_to_id( $t_category, $t_project_id );
- if( $t_category_id == 0 ) {
- if ( is_blank( $t_category ) ) {
- return new soap_fault( 'Client', '', "Category cannot be empty." );
+ $t_category_id = translate_category_name_to_id( $p_issue['category'], $t_project_id );
+ if ( $t_category_id == 0 && !config_get( 'allow_no_category' ) ) {
+ if ( isset( $p_issue['category'] ) && !is_blank( $p_issue['category'] ) ) {
+ return new soap_fault( 'Client', '', "Category field must be supplied." );
+ } else {
+ return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_name'." );
}
-
- return new soap_fault( 'Client', '', "Category '$v_category' does not exist in project '$t_project_id'." );
}
if( isset( $v_version ) && !is_blank( $v_version ) && !version_get_id( $v_version, $t_project_id ) ) {
diff --git a/core/bug_api.php b/core/bug_api.php
index 218082bea3..8b6ed13aea 100644
--- a/core/bug_api.php
+++ b/core/bug_api.php
@@ -569,7 +569,9 @@ function bug_create( $p_bug_data ) {
}
# Insert the rest of the data
- $t_resolution = OPEN;
+ $c_resolution = OPEN;
+ $c_projection = 10;
+ $c_eta = 10;
$query = "INSERT INTO $t_bug_table
( project_id,
@@ -615,7 +617,7 @@ function bug_create( $p_bug_data ) {
" . db_param() . ",
" . db_param() . ",
" . db_param() . ")";
- db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status, $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version, $c_build, $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date ) );
+ db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status, $c_resolution, $c_projection, $c_category_id, db_now(), db_now(), $c_eta, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version, $c_build, $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date ) );
$t_bug_id = db_insert_id( $t_bug_table );
diff --git a/core/email_api.php b/core/email_api.php
index b7655229ce..cf77378b0d 100644
--- a/core/email_api.php
+++ b/core/email_api.php
@@ -850,15 +850,22 @@ function email_send( $p_email_data ) {
}
}
- if( !$mail->Send() ) {
- $t_success = false;
- } else {
- $t_success = true;
-
- if( $t_email_data->email_id > 0 ) {
- email_queue_delete( $t_email_data->email_id );
+ try
+ {
+ if ( !$mail->Send() ) {
+ $t_success = false;
+ } else {
+ $t_success = true;
+
+ if ( $t_email_data->email_id > 0 ) {
+ email_queue_delete( $t_email_data->email_id );
+ }
}
}
+ catch ( phpmailerException $e )
+ {
+ $t_success = false;
+ }
$mail->ClearAllRecipients();
$mail->ClearAttachments();
diff --git a/tests/soap/EnumTest.php b/tests/soap/EnumTest.php
new file mode 100644
index 0000000000..d4fac416e7
--- /dev/null
+++ b/tests/soap/EnumTest.php
@@ -0,0 +1,278 @@
+.
+
+/**
+ * @package Tests
+ * @subpackage UnitTests
+ * @copyright Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net
+ * @link http://www.mantisbt.org
+ */
+
+require_once 'SoapBase.php';
+
+/**
+ * Test fixture for enum related webservice method.
+ */
+class EnumTest extends SoapBase {
+ /**
+ * Tests mc_enum_access_levels method.
+ */
+ public function testAccessLevel() {
+ $accessLevelsObjectRefs = $this->client->mc_enum_access_levels( $this->userName, $this->password);
+
+ $accessLevels = EnumTest::ObjectRefsToAssoc( $accessLevelsObjectRefs );
+
+ // '10:viewer,25:reporter,40:updater,55:developer,70:manager,90:administrator'
+
+ $this->assertEquals( 6, count( $accessLevels ) );
+ $this->assertEquals( 'viewer', $accessLevels[10] );
+ $this->assertEquals( 'reporter', $accessLevels[25] );
+ $this->assertEquals( 'updater', $accessLevels[40] );
+ $this->assertEquals( 'developer', $accessLevels[55] );
+ $this->assertEquals( 'manager', $accessLevels[70] );
+ $this->assertEquals( 'administrator', $accessLevels[90] );
+ }
+
+ /**
+ * Tests the mc_enum_access_levels with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testAccessLevelAccessDenied() {
+ $this->client->mc_enum_access_levels( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_status method.
+ */
+ public function testStatus() {
+ $statusesObjectRefs = $this->client->mc_enum_status($this->userName, $this->password);
+
+ $statuses = EnumTest::ObjectRefsToAssoc( $statusesObjectRefs );
+
+ // '10:new,20:feedback,30:acknowledged,40:confirmed,50:assigned,80:resolved,90:closed'
+
+ $this->assertEquals( 7, count( $statuses ) );
+ $this->assertEquals( 'new', $statuses[10] );
+ $this->assertEquals( 'feedback', $statuses[20] );
+ $this->assertEquals( 'acknowledged', $statuses[30] );
+ $this->assertEquals( 'confirmed', $statuses[40] );
+ $this->assertEquals( 'assigned', $statuses[50] );
+ $this->assertEquals( 'resolved', $statuses[80] );
+ $this->assertEquals( 'closed', $statuses[90] );
+ }
+
+ /**
+ * Tests mc_enum_status method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testStatusAccessDenied() {
+ $this->client->mc_enum_status( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_priorities method.
+ */
+ public function testPriority() {
+ $prioritiesObjectRefs = $this->client->mc_enum_priorities($this->userName, $this->password);
+
+ $priorities = EnumTest::ObjectRefsToAssoc( $prioritiesObjectRefs );
+
+ // '10:none,20:low,30:normal,40:high,50:urgent,60:immediate'
+
+ $this->assertEquals( 6, count( $priorities ) );
+ $this->assertEquals( 'none', $priorities[10] );
+ $this->assertEquals( 'low', $priorities[20] );
+ $this->assertEquals( 'normal', $priorities[30] );
+ $this->assertEquals( 'high', $priorities[40] );
+ $this->assertEquals( 'urgent', $priorities[50] );
+ $this->assertEquals( 'immediate', $priorities[60] );
+ }
+
+ /**
+ * Tests mc_enum_priorities method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testPriorityAccessDenied() {
+ $this->client->mc_enum_priorities( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_reproducibilities method.
+ */
+ public function testReproducibility() {
+ $reproducibilityObjectRefs = $this->client->mc_enum_reproducibilities($this->userName, $this->password);
+
+ $reproducibilities = EnumTest::ObjectRefsToAssoc( $reproducibilityObjectRefs );
+
+ // '10:always,30:sometimes,50:random,70:have not tried,90:unable to duplicate,100:N/A'
+
+ $this->assertEquals( 6, count( $reproducibilities ) );
+ $this->assertEquals( 'always', $reproducibilities[10] );
+ $this->assertEquals( 'sometimes', $reproducibilities[30] );
+ $this->assertEquals( 'random', $reproducibilities[50] );
+ $this->assertEquals( 'have not tried', $reproducibilities[70] );
+ $this->assertEquals( 'unable to reproduce', $reproducibilities[90] );
+ $this->assertEquals( 'N/A', $reproducibilities[100] );
+ }
+
+ /**
+ * Tests mc_enum_reproducibilities method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testReproducibilityAccessDenied() {
+ $this->client->mc_enum_reproducibilities( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_severities method.
+ */
+ public function testSeverity() {
+ $severityObjectRefs = $this->client->mc_enum_severities($this->userName, $this->password);
+
+ $severities = EnumTest::ObjectRefsToAssoc( $severityObjectRefs );
+
+ // '10:feature,20:trivial,30:text,40:tweak,50:minor,60:major,70:crash,80:block'
+
+ $this->assertEquals( 8, count( $severities ) );
+ $this->assertEquals( 'feature', $severities[10] );
+ $this->assertEquals( 'trivial', $severities[20] );
+ $this->assertEquals( 'text', $severities[30] );
+ $this->assertEquals( 'tweak', $severities[40] );
+ $this->assertEquals( 'minor', $severities[50] );
+ $this->assertEquals( 'major', $severities[60] );
+ $this->assertEquals( 'crash', $severities[70] );
+ $this->assertEquals( 'block', $severities[80] );
+ }
+
+ /**
+ * Tests mc_enum_severities method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testSeverityAccessDenied() {
+ $this->client->mc_enum_severities( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_projections method.
+ */
+ public function testProjection() {
+ $projectionObjectRefs = $this->client->mc_enum_projections($this->userName, $this->password);
+
+ $projections = EnumTest::ObjectRefsToAssoc( $projectionObjectRefs );
+
+ // '10:none,30:tweak,50:minor fix,70:major rework,90:redesign'
+
+ $this->assertEquals( 5, count( $projections ) );
+ $this->assertEquals( 'none', $projections[10] );
+ $this->assertEquals( 'tweak', $projections[30] );
+ $this->assertEquals( 'minor fix', $projections[50] );
+ $this->assertEquals( 'major rework', $projections[70] );
+ $this->assertEquals( 'redesign', $projections[90] );
+ }
+
+ /**
+ * Tests mc_enum_projections method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testProjectionAccessDenied() {
+ $this->client->mc_enum_projections( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_etas method.
+ */
+ public function testEta() {
+ $etaObjectRefs = $this->client->mc_enum_etas($this->userName, $this->password);
+
+ $etas = EnumTest::ObjectRefsToAssoc( $etaObjectRefs );
+
+ // '10:none,20:< 1 day,30:2-3 days,40:< 1 week,50:< 1 month,60:> 1 month'
+
+ $this->assertEquals( 6, count( $etas ) );
+ $this->assertEquals( 'none', $etas[10] );
+ $this->assertEquals( '< 1 day', $etas[20] );
+ $this->assertEquals( '2-3 days', $etas[30] );
+ $this->assertEquals( '< 1 week', $etas[40] );
+ $this->assertEquals( '< 1 month', $etas[50] );
+ $this->assertEquals( '> 1 month', $etas[60] );
+ }
+
+ /**
+ * Tests mc_enum_etas method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testEtaAccessDenied() {
+ $this->client->mc_enum_etas( 'administrator', '' );
+ }
+
+ /**
+ * Tests mc_enum_resolutions method.
+ */
+ public function testResolution() {
+ $resolutionObjectRefs = $this->client->mc_enum_resolutions($this->userName, $this->password);
+
+ $resolutions = EnumTest::ObjectRefsToAssoc( $resolutionObjectRefs );
+
+ // '10:open,20:fixed,30:reopened,40:unable to duplicate,50:not fixable,60:duplicate,70:not a bug,80:suspended,90:wont fix'
+
+ $this->assertEquals( 9, count( $resolutions ) );
+ $this->assertEquals( 'open', $resolutions[10] );
+ $this->assertEquals( 'fixed', $resolutions[20] );
+ $this->assertEquals( 'reopened', $resolutions[30] );
+ $this->assertEquals( 'unable to reproduce', $resolutions[40] );
+ $this->assertEquals( 'not fixable', $resolutions[50] );
+ $this->assertEquals( 'duplicate', $resolutions[60] );
+ $this->assertEquals( 'no change required', $resolutions[70] );
+ $this->assertEquals( 'suspended', $resolutions[80] );
+ $this->assertEquals( 'won\'t fix', $resolutions[90] );
+ }
+
+ /**
+ * Tests mc_enum_resolutions method with invalid credentials.
+ *
+ * @expectedException SoapFault
+ */
+ public function testResolutionAccessDenied() {
+ $this->client->mc_enum_resolutions( 'administrator', '' );
+ }
+
+ // TODO: mc_enum_project_status
+ // TODO: mc_enum_project_view_states
+ // TODO: mc_enum_custom_field_types
+ // TODO: mc_enum_get
+
+ /**
+ * Converts an array of ObjectRefs array into an associate
+ * array with the enum id as the key and the enum label as
+ * the value.
+ */
+ private static function ObjectRefsToAssoc( $objectRefs ) {
+ $assocArray = array();
+
+ foreach ( $objectRefs as $objectRef ) {
+ $assocArray[$objectRef->id] = $objectRef->name;
+ }
+
+ return $assocArray;
+ }
+}
diff --git a/tests/soap/IssueAddTest.php b/tests/soap/IssueAddTest.php
new file mode 100644
index 0000000000..60cb4c2bd9
--- /dev/null
+++ b/tests/soap/IssueAddTest.php
@@ -0,0 +1,126 @@
+.
+
+/**
+ * @package Tests
+ * @subpackage UnitTests
+ * @copyright Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net
+ * @link http://www.mantisbt.org
+ */
+
+require_once 'SoapBase.php';
+
+/**
+ * Test fixture for issue creation webservice methods.
+ */
+class IssueAddTest extends SoapBase {
+ /**
+ * A test case that tests the following:
+ * 1. Ability to create an issue with only the mandatory parameters.
+ * 2. mc_issue_get_biggest_id()
+ * 3. mc_issue_get_id_from_summary()
+ * 4. The defaulting of the non-mandatory parameters.
+ */
+ public function testCreateIssue() {
+ $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssue' );
+
+ $issueId = $this->client->mc_issue_add(
+ $this->userName,
+ $this->password,
+ $issueToAdd);
+
+ $biggestId = $this->client->mc_issue_get_biggest_id(
+ $this->userName,
+ $this->password,
+ $issueToAdd['project']['id']);
+
+ $this->assertEquals( $issueId, $biggestId );
+
+ $issueIdFromSummary = $this->client->mc_issue_get_id_from_summary(
+ $this->userName,
+ $this->password,
+ $issueToAdd['summary']);
+
+ $this->assertEquals( $issueId, $issueIdFromSummary );
+
+ $issue = $this->client->mc_issue_get(
+ $this->userName,
+ $this->password,
+ $issueId);
+
+ // explicitly specified fields
+ $this->assertEquals( $issueToAdd['category'], $issue->category );
+ $this->assertEquals( $issueToAdd['summary'], $issue->summary );
+ $this->assertEquals( $issueToAdd['description'], $issue->description );
+ $this->assertEquals( $issueToAdd['project']['id'], $issue->project->id );
+
+ // defaulted fields
+ $this->assertEquals( $issueId, $issue->id );
+ $this->assertEquals( 10, $issue->view_state->id );
+ $this->assertEquals( 'public', $issue->view_state->name );
+ $this->assertEquals( 30, $issue->priority->id );
+ $this->assertEquals( 'normal', $issue->priority->name );
+ $this->assertEquals( 50, $issue->severity->id );
+ $this->assertEquals( 'minor', $issue->severity->name );
+ $this->assertEquals( 10, $issue->status->id );
+ $this->assertEquals( 'new', $issue->status->name );
+ $this->assertEquals( $this->userName, $issue->reporter->name );
+ $this->assertEquals( 70, $issue->reproducibility->id );
+ $this->assertEquals( 'have not tried', $issue->reproducibility->name );
+ $this->assertEquals( 0, $issue->sponsorship_total );
+ $this->assertEquals( 10, $issue->projection->id );
+ $this->assertEquals( 'none', $issue->projection->name );
+ $this->assertEquals( 10, $issue->eta->id );
+ $this->assertEquals( 'none', $issue->eta->name );
+ $this->assertEquals( 10, $issue->resolution->id );
+ $this->assertEquals( 'open', $issue->resolution->name );
+
+ $this->client->mc_issue_delete(
+ $this->userName,
+ $this->password,
+ $issueId);
+ }
+
+ /**
+ * A test cases that tests the creation of issues with html markup in summary
+ * and description.
+ */
+ public function testCreateIssueWithHtmlMarkup() {
+ $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithHtmlMarkup' );
+
+ $issueToAdd['summary'] .= " WithHtmlMarkup";
+ $issueToAdd['description'] .= " WithHtmlMarkup";
+
+ $issueId = $this->client->mc_issue_add(
+ $this->userName,
+ $this->password,
+ $issueToAdd);
+
+ $issue = $this->client->mc_issue_get(
+ $this->userName,
+ $this->password,
+ $issueId);
+
+ // explicitly specified fields
+ $this->assertEquals( $issueToAdd['summary'], $issue->summary );
+ $this->assertEquals( $issueToAdd['description'], $issue->description );
+
+ $this->client->mc_issue_delete(
+ $this->userName,
+ $this->password,
+ $issueId);
+ }
+}
diff --git a/tests/soap/SoapBase.php b/tests/soap/SoapBase.php
new file mode 100644
index 0000000000..adec6be13c
--- /dev/null
+++ b/tests/soap/SoapBase.php
@@ -0,0 +1,64 @@
+.
+
+/**
+ * @package Tests
+ * @subpackage UnitTests
+ * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
+ * @copyright Copyright (C) 2002 - 2009 MantisBT Team - mantisbt-dev@lists.sourceforge.net
+ * @link http://www.mantisbt.org
+ */
+
+require_once 'PHPUnit/Framework.php';
+
+$t_root_path = dirname( dirname( dirname( __FILE__ ) ) ) . DIRECTORY_SEPARATOR;
+
+/**
+ * Test cases for SoapEnum class.
+ */
+class SoapBase extends PHPUnit_Framework_TestCase {
+ protected $client;
+ protected $userName = 'administrator';
+ protected $password = 'root';
+
+ protected function setUp()
+ {
+ $this->client = new
+ SoapClient(
+ "http://localhost/mantis12x/api/soap/mantisconnect.php?wsdl",
+ array( 'trace' => true,
+ 'exceptions' => true,
+ )
+
+ );
+ }
+
+ protected function getProjectId() {
+ return 1;
+ }
+
+ protected function getCategory() {
+ return 'General';
+ }
+
+ protected function getIssueToAdd( $testCase ) {
+ return array(
+ 'summary' => $testCase . ': test issue: ' . rand(1, 1000000),
+ 'description' => 'description of test issue.',
+ 'project' => array( 'id' => $this->getProjectId() ),
+ 'category' => $this->getCategory() );
+ }
+}