From 343ce1ade0829b65acab813aebccd8f85689d9a6 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Mon, 3 May 2010 15:40:40 +0200 Subject: [PATCH 1/3] add API SOAP features : add, delete, rename categories for a specific project --- api/soap/mantisconnect.php | 52 +++++++++++++++++++++++ api/soap/mc_project_api.php | 95 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 0 deletions(-) diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index f2bae97..da61187 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -1074,6 +1074,58 @@ $l_oServer->register( 'mc_project_get_categories', 'Get the categories belonging to the specified project.' ); +### mc_project_add_category +$l_oServer->register( 'mc_project_add_category', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'p_category_name' => 'xsd:string', + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Add a category of specific project.' +); + + +### mc_project_delete_category +$l_oServer->register( 'mc_project_delete_category', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'p_category_name' => 'xsd:string', + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Delete a category of specific project.' +); + + +### mc_project_rename_category_by_name +$l_oServer->register( 'mc_project_rename_category_by_name', + array( + 'username' => 'xsd:string', + 'password' => 'xsd:string', + 'project_id' => 'xsd:integer', + 'p_category_name' => 'xsd:string', + 'p_category_name_new' => 'xsd:string', + 'p_assigned_to' => 'xsd:integer', + ), + array( + 'return' => 'xsd:integer' + ), + $t_namespace, + false, false, false, + 'Rename a category of specific project.' +); + ### mc_project_get_versions $l_oServer->register( 'mc_project_get_versions', array( diff --git a/api/soap/mc_project_api.php b/api/soap/mc_project_api.php index cad8336..f114bfd 100644 --- a/api/soap/mc_project_api.php +++ b/api/soap/mc_project_api.php @@ -105,6 +105,101 @@ function mc_project_get_categories( $p_username, $p_password, $p_project_id ) { } /** + * Add a new category to a project + * @param string $p_username The name of the user trying to access the categories. + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to retrieve the categories for. + * @param string $p_category_name The name of the new category to add + * @return integer id of the new category + */ + +function mc_project_add_category($p_username, $p_password, $p_project_id, $p_category_name ) { + $t_user_id = mci_check_login( $p_username, $p_password ); + + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + + if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + return category_add( $p_project_id, $p_category_name ); +} + +/** + * Delete a category of a project + * @param string $p_username The name of the user trying to access the categories. + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to retrieve the categories for. + * @param string $p_category_name The name of the category to delete + * @return bool returns true or false depending on the success of the delete action + */ + +function mc_project_delete_category ($p_username, $p_password, $p_project_id, $p_category_name) { + $t_user_id = mci_check_login( $p_username, $p_password ); + + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + + if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + // find the id of the category + $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id ); + + // delete the category and link all the issue to the general category by default + return category_remove( $p_category_id, 1 ); +} + +/** + * Update a category of a project + * @param string $p_username The name of the user trying to access the categories. + * @param string $p_password The password of the user. + * @param integer $p_project_id The id of the project to retrieve the categories for. + * @param string $p_category_name The name of the category to rename + * @param string $p_category_name_new The new name of the category to rename + * @param int $p_assigned_to User ID that category is assigned to + * @return bool returns true or false depending on the success of the update action + */ + +function mc_project_rename_category_by_name ($p_username, $p_password, $p_project_id, $p_category_name, $p_category_name_new, $p_assigned_to) { + $t_user_id = mci_check_login( $p_username, $p_password ); + + if ( null === $p_assigned_to ) { + return new soap_fault( 'Client', '', 'p_assigned_to needed' ); + } + + if( $t_user_id === false ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + if( !project_exists( $p_project_id ) ) { + return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." ); + } + + if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) { + return new soap_fault( 'Client', '', 'Access Denied' ); + } + + // find the id of the category + $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id ); + + // update the category + return category_update( $p_category_id, $p_category_name_new, $p_assigned_to ); +} + +/** * Get all versions of a project. * * @param string $p_username The name of the user trying to access the versions. -- 1.6.4.4 From ce64b10a1f5f31e90642e5e1321b50e3fa528373 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Mon, 3 May 2010 15:55:42 +0200 Subject: [PATCH 2/3] add new file CategoryTest.php in loop for SOAP API test suite --- tests/soap/AllTests.php | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/tests/soap/AllTests.php b/tests/soap/AllTests.php index 988d948..2280031 100644 --- a/tests/soap/AllTests.php +++ b/tests/soap/AllTests.php @@ -33,6 +33,7 @@ require_once 'IssueUpdateTest.php'; require_once 'FilterTest.php'; require_once 'AttachmentTest.php'; require_once 'LoginTest.php'; +require_once 'CategoryTest.php'; /** * @package Tests -- 1.6.4.4 From 70a7df62e0896ef8aa96220ef96157fa5458b900 Mon Sep 17 00:00:00 2001 From: Franck Villaume Date: Mon, 3 May 2010 16:22:57 +0200 Subject: [PATCH 3/3] simple phpunit test for soap api feature : add,rename,delete category --- tests/soap/AllTests.php | 1 + tests/soap/CategoryTest.php | 87 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 tests/soap/CategoryTest.php diff --git a/tests/soap/AllTests.php b/tests/soap/AllTests.php index 2280031..c248675 100644 --- a/tests/soap/AllTests.php +++ b/tests/soap/AllTests.php @@ -64,6 +64,7 @@ class Soap_AllTests extends PHPUnit_Framework_TestSuite $suite->addTestSuite('FilterTest'); $suite->addTestSuite('AttachmentTest'); $suite->addTestSuite('LoginTest'); + $suite->addTestSuite('CategoryTest'); return $suite; } diff --git a/tests/soap/CategoryTest.php b/tests/soap/CategoryTest.php new file mode 100644 index 0000000..5f5ddca --- /dev/null +++ b/tests/soap/CategoryTest.php @@ -0,0 +1,87 @@ +. + +/** + * @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 category webservice methods. + */ +class CategoryTest extends SoapBase { + /** + * A test case that tests the following: + * 1. Get the project id. + * 2. Add a category. + * 3. Get the category list. + * 4. Verify the category name in the list. + * 5. Rename the category. + * 6. Get the new category list + * 7. Verify the cateogory name in the list + * 8. Delete the category + * 9. Verify the category is not in the list anymore + */ + public function testAddRenameDeleteCategory() { + $projectId = $this->getProjectId(); + + $categoryId = $this->client->mc_project_add_category( + $this->userName, + $this->password, + $projectId, + 'my_category_name'); + + $categoryList = $this->client->mc_project_get_categories( + $this->userName, + $this->password, + $projectId); + + $this->assertArrayHasKey('my_category_name', $categoryList); + + $return_bool = $this->client->mc_project_rename_category_by_name ( + $this->userName, + $this->password, + $projectId, + 'my_category_name', + 'my_brand_new_name_category', + ''); + + $categoryList = $this->client->mc_project_get_categories( + $this->userName, + $this->password, + $projectId); + + $this->assertArrayNotHasKey('my_category_name', $categoryList); + $this->assertArrayHasKey('my_brand_new_name_category', $categoryList); + + $return_bool = $this->client->mc_project_delete_category ( + $this->userName, + $this->password, + $projectId, + 'my_brand_new_name_category'); + + $categoryList = $this->client->mc_project_get_categories( + $this->userName, + $this->password, + $projectId); + + $this->assertArrayNotHasKey('my_brand_new_name_category', $categoryList); + } +} -- 1.6.4.4