From 6e244f417f755aa5aee8909f3cfdb0c6ca787a73 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Thu, 3 Jun 2010 10:59:41 +0200 Subject: [PATCH 1/2] SOAP API feature : add update project description of a specific project --- tests/soap/ProjectTest.php | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 104 insertions(+), 0 deletions(-) create mode 100644 tests/soap/ProjectTest.php diff --git a/tests/soap/ProjectTest.php b/tests/soap/ProjectTest.php new file mode 100644 index 0000000..c7447de --- /dev/null +++ b/tests/soap/ProjectTest.php @@ -0,0 +1,104 @@ +. + +/** + * @package Tests + * @subpackage UnitTests + * @copyright Copyright (C) 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + +require_once 'SoapBase.php'; + +/** + * Test fixture for project webservice methods. + */ +class ProjectTest extends SoapBase { + + private $projectIdToDelete = array(); + + /** + * A test case that tests the following: + * 1. Create a project. + * 2. Rename the project. + * 3. Delete the project. + */ + public function testAddRenameDeleteProject() { + $projectName = $this->getOriginalNameProject(); + $projectNewName = $this->getNewNameProject(); + + $projectDataStructure = array(); + $projectDataStructure['name'] = $projectName; + $projectDataStructure['status'] = "development"; + $projectDataStructure['view_state'] = 10; + + $projectId = $this->client->mc_project_add( + $this->userName, + $this->password, + $projectDataStructure); + + $this->projectIdToDelete[] = $projectId; + + $projectArray = mc_project_as_array_by_id( + $this->userName, + $this->password, + $projectId); + + $this->assertContains($projectName, $projectArray); + + $projectDataStructure['name'] = $projectNewName; + + $return_bool = $this->client->mc_project_update( + $this->userName, + $this->password, + $projectId, + $projectDataStructure); + + $projectArray = mc_project_as_array_by_id( + $this->userName, + $this->password, + $projectId); + + $this->assertContains($projectNewName, $projectArray); + + $return_bool = $this->client->mc_project_delete ( + $this->userName, + $this->password, + $projectId); + } + + protected function tearDown() { + + parent::tearDown(); + + foreach ( $this->projectIdToDelete as $projectId ) { + $this->client->mc_project_delete( + $this->userName, + $this->password, + $projectId); + } + } + + private function getOriginalNameProject() { + return 'my_project_name'; + } + + private function getNewNameProject() { + return 'my_new_project_name'; + } + +} + -- 1.6.4.4 From af08a75720bd3f6c800c4de8dabc07200670418a Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Thu, 3 Jun 2010 11:00:40 +0200 Subject: [PATCH 2/2] SOAP API feature : add update project description of a specific project --- api/soap/mantisconnect.php | 16 +++++++++ api/soap/mc_project_api.php | 78 +++++++++++++++++++++++++++++++++++++++++++ tests/soap/AllTests.php | 2 + 3 files changed, 96 insertions(+), 0 deletions(-) diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index b2a46ab..0dab667 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -1001,6 +1001,22 @@ $l_oServer->register( 'mc_project_delete', 'Add a new project to the tracker (must have admin privileges)' ); +### mc_project_update +$l_oServer->register( 'mc_project_update', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'project' => 'tns:ProjectData' + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Update a specific project to the tracker (must have admin privileges)' +); + ### mc_project_get_issues $l_oServer->register( 'mc_project_get_issues', array( diff --git a/api/soap/mc_project_api.php b/api/soap/mc_project_api.php index 00a5d6b..1d3046d 100644 --- a/api/soap/mc_project_api.php +++ b/api/soap/mc_project_api.php @@ -726,6 +726,84 @@ function mc_project_add( $p_username, $p_password, $p_project ) { } /** + * Update a project + * + * @param string $p_username The name of the user + * @param string $p_password The password of the user + * @param integer $p_project_id A project's id + * @param Array $p_project A new ProjectData structure + * @return bool returns true or false depending on the success of the update action + */ +function mc_project_update( $p_username, $p_password, $p_project_id, $p_project ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect' ); + } + + if( !mci_has_administrator_access( $t_user_id, $p_project_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access' ); + } + + if ( !isset( $p_project['name'] ) ) { + return new soap_fault( 'Client', '', 'Missing Field', 'Required Field Missing' ); + } else { + $t_name = $p_project['name']; + } + + if ( !isset( $p_project['description'] ) ) { + $t_description = project_get_field( $p_project_id, 'description' ); + } else { + $t_description = $p_project['description']; + } + + if ( !isset( $p_project['status'] ) ) { + $t_status = project_get_field( $p_project_id, 'status' ); + } else { + $t_status = $p_project['status']; + } + + if ( !isset( $p_project['view_state'] ) ) { + $t_view_state = project_get_field( $p_project_id, 'view_state' ); + } else { + $t_view_state = $p_project['view_state']; + } + + if ( !isset( $p_project['file_path'] ) ) { + $t_file_path = project_get_field( $p_project_id, 'file_path' ); + } else { + $t_file_path = $p_project['file_path']; + } + + if ( !isset( $p_project['enabled'] ) ) { + $t_enabled = project_get_field( $p_project_id, 'enabled' ); + } else { + $t_enabled = $p_project['enabled']; + } + + if ( !isset( $p_project['inherit_global'] ) ) { + $t_inherit_global = project_get_field( $p_project_id, 'inherit_global' ); + } else { + $t_inherit_global = $p_project['inherit_global']; + } + + if( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + + // check to make sure project doesn't already exist + if ( $t_name != project_get_name( $p_project_id ) ) { + if( !project_is_name_unique( $t_name ) ) { + return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' ); + } + } + + $t_project_status = mci_get_project_status_id( $t_status ); + $t_project_view_state = mci_get_project_view_state_id( $t_view_state ); + + return project_update( $p_project_id, $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global ); +} + +/** * Delete a project. * * @param string $p_username The name of the user trying to access the versions. diff --git a/tests/soap/AllTests.php b/tests/soap/AllTests.php index 59efc29..e20cc92 100644 --- a/tests/soap/AllTests.php +++ b/tests/soap/AllTests.php @@ -35,6 +35,7 @@ require_once 'AttachmentTest.php'; require_once 'LoginTest.php'; require_once 'CategoryTest.php'; require_once 'CompressionTest.php'; +require_once 'ProjectTest.php'; /** * @package Tests @@ -67,6 +68,7 @@ class Soap_AllTests extends PHPUnit_Framework_TestSuite $suite->addTestSuite('LoginTest'); $suite->addTestSuite('CategoryTest'); $suite->addTestSuite('CompressionTest'); + $suite->addTestSuite('ProjectTest'); return $suite; } -- 1.6.4.4