CRM-17176 add Navigation api
authoreileenmcnaugton <eileen@fuzion.co.nz>
Tue, 29 Sep 2015 06:33:44 +0000 (19:33 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Tue, 29 Sep 2015 07:05:51 +0000 (20:05 +1300)
Adding this was mostly to make the syntax conformance happy since adding a navigation.reset action:

CRM/Core/BAO/Navigation.php
api/v3/Navigation.php [new file with mode: 0644]
tests/phpunit/api/v3/NavigationTest.php [new file with mode: 0644]
tests/phpunit/api/v3/SyntaxConformanceTest.php

index 14589c8ba7b7e06a9ee7ef617869e27347b13cb3..2708f737f7099095524be1db284fe80edaaa465f 100644 (file)
@@ -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 (file)
index 0000000..f6f2ff3
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This api exposes CiviCRM Navigation BAO.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Adjust metadata for navigation reset action.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_navigation_get_spec(&$params) {
+}
+
+/**
+ * Reset navigation.
+ *
+ * @param array $params
+ *   Array of name/value pairs.
+ *
+ * @return array
+ *   API result array.
+ */
+function civicrm_api3_navigation_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust metadata for navigation create action.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_navigation_create_spec(&$params) {
+}
+
+/**
+ * Create navigation item.
+ *
+ * @param array $params
+ *   Array of name/value pairs.
+ *
+ * @return array
+ *   API result array.
+ */
+function civicrm_api3_navigation_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust metadata for navigation create action.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_navigation_delete_spec(&$params) {
+}
+
+/**
+ * Create navigation item.
+ *
+ * @param array $params
+ *   Array of name/value pairs.
+ *
+ * @return array
+ *   API result array.
+ */
+function civicrm_api3_navigation_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
diff --git a/tests/phpunit/api/v3/NavigationTest.php b/tests/phpunit/api/v3/NavigationTest.php
new file mode 100644 (file)
index 0000000..3073e2d
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * +--------------------------------------------------------------------+
+ * | CiviCRM version 4.7                                                |
+ * +--------------------------------------------------------------------+
+ * | Copyright CiviCRM LLC (c) 2004-2015                                |
+ * +--------------------------------------------------------------------+
+ * | This file is a part of CiviCRM.                                    |
+ * |                                                                    |
+ * | CiviCRM is free software; you can copy, modify, and distribute it  |
+ * | under the terms of the GNU Affero General Public License           |
+ * | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ * |                                                                    |
+ * | CiviCRM is distributed in the hope that it will be useful, but     |
+ * | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ * | See the GNU Affero General Public License for more details.        |
+ * |                                                                    |
+ * | You should have received a copy of the GNU Affero General Public   |
+ * | License and the CiviCRM Licensing Exception along                  |
+ * | with this program; if not, contact CiviCRM LLC                     |
+ * | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ * | GNU Affero General Public License or the licensing of CiviCRM,     |
+ * | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ * +--------------------------------------------------------------------+
+ */
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Class api_v3_NavigationTest
+ */
+class api_v3_NavigationTest extends CiviUnitTestCase {
+  protected $_apiversion = 3;
+  protected $_params;
+
+  protected $_entity = 'Navigation';
+
+  /**
+   * Test get function.
+   */
+  public function testGet() {
+    $this->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));
+  }
+
+}
index 17d8c68d50347a6764f0033bf8d85d2870220cac..d5087c88304887b8e172ec84276330e0d103d3ee 100644 (file)
@@ -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',