From ed2f1070afbdead7b9b4dde3eb67eba8fd7b4106 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Tue, 11 May 2010 15:50:28 +0200 Subject: [PATCH] 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 + tests/soap/ProjectTest.php | 103 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 tests/soap/ProjectTest.php diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index da61187..9b2a248 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -995,6 +995,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 11586d2..ba3867e 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 = array( 'name' => 'development' ); // development + } else { + $t_status = $p_project['status']; + } + + if ( !isset( $p_project['view_state'] ) ) { + $t_view_state = array( 'id' => VS_PUBLIC ); + } else { + $t_view_state = $p_project['view_state']; + } + + if ( !isset( $p_project['file_path'] ) ) { + $t_file_path = ''; + } else { + $t_file_path = $p_project['file_path']; + } + + if ( !isset( $p_project['enabled'] ) ) { + $t_enabled = true; + } else { + $t_enabled = $p_project['enabled']; + } + + if ( !isset( $p_project['inherit_global'] ) ) { + $t_inherit_global = true; + } 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 c248675..7cebd00 100644 --- a/tests/soap/AllTests.php +++ b/tests/soap/AllTests.php @@ -34,6 +34,7 @@ require_once 'FilterTest.php'; require_once 'AttachmentTest.php'; require_once 'LoginTest.php'; require_once 'CategoryTest.php'; +require_once 'ProjectTest.php'; /** * @package Tests @@ -65,6 +66,7 @@ class Soap_AllTests extends PHPUnit_Framework_TestSuite $suite->addTestSuite('AttachmentTest'); $suite->addTestSuite('LoginTest'); $suite->addTestSuite('CategoryTest'); + $suite->addTestSuite('ProjectTest'); return $suite; } diff --git a/tests/soap/ProjectTest.php b/tests/soap/ProjectTest.php new file mode 100644 index 0000000..af59cd7 --- /dev/null +++ b/tests/soap/ProjectTest.php @@ -0,0 +1,103 @@ +. + +/** + * @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