From 3523b615bc4e212d226605c25373c20efc365f3c Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Tue, 29 Sep 2015 19:33:44 +1300 Subject: [PATCH] CRM-17176 add Navigation api Adding this was mostly to make the syntax conformance happy since adding a navigation.reset action: --- CRM/Core/BAO/Navigation.php | 7 +- api/v3/Navigation.php | 95 +++++++++++++++++++ tests/phpunit/api/v3/NavigationTest.php | 68 +++++++++++++ .../phpunit/api/v3/SyntaxConformanceTest.php | 6 ++ 4 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 api/v3/Navigation.php create mode 100644 tests/phpunit/api/v3/NavigationTest.php diff --git a/CRM/Core/BAO/Navigation.php b/CRM/Core/BAO/Navigation.php index 14589c8ba7..2708f737f7 100644 --- a/CRM/Core/BAO/Navigation.php +++ b/CRM/Core/BAO/Navigation.php @@ -90,9 +90,10 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation { */ public static function add(&$params) { $navigation = new CRM_Core_DAO_Navigation(); - - $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); - $params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE); + if (empty($params['id'])) { + $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); + $params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE); + } if (!isset($params['id']) || (CRM_Utils_Array::value('parent_id', $params) != CRM_Utils_Array::value('current_parent_id', $params)) diff --git a/api/v3/Navigation.php b/api/v3/Navigation.php new file mode 100644 index 0000000000..f6f2ff34d1 --- /dev/null +++ b/api/v3/Navigation.php @@ -0,0 +1,95 @@ +callAPISuccess($this->_entity, 'getsingle', array('label' => 'Manage Groups', 'domain_id' => 1)); + } + + /** + * Test create function. + */ + public function testCreate() { + $params = array('label' => 'Feed the Goats', 'domain_id' => 1); + $result = $this->callAPISuccess($this->_entity, 'create', $params); + $this->getAndCheck($params, $result['id'], $this->_entity, TRUE); + } + + /** + * Test delete function. + */ + public function testDelete() { + $getParams = array( + 'return' => 'id', + 'options' => array('limit' => 1), + ); + $result = $this->callAPISuccess('Navigation', 'getvalue', $getParams); + $this->callAPISuccess('Navigation', 'delete', array('id' => $result)); + $this->callAPIFailure('Navigation', 'getvalue', array('id' => $result)); + } + +} diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 17d8c68d50..d5087c8830 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -572,6 +572,12 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { 'is_primary', ), ), + 'Navigation' => array( + 'cant_update' => array( + // Weight is deliberately altered when this is changed - skip. + 'parent_id', + ), + ), 'Pledge' => array( 'cant_update' => array( 'pledge_original_installment_amount', -- 2.25.1