Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / api / v3 / ExtensionTest.php
index 62ca11fa81a920c1564a66c978dc3438e6d58b08..c208db048a27020090b2861811522127104ad595 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -61,7 +61,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
    * Test getting a single extension
    * CRM-20532
    */
-  public function testExtesnionGetSingleExtension() {
+  public function testExtensionGetSingleExtension() {
     $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest'));
     $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
     $this->assertEquals('module', $result['values'][$result['id']]['type']);
@@ -72,7 +72,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
    * Test single Extension get with specific fields in return
    * CRM-20532
    */
-  public function testSingleExtesnionGetWithReturnFields() {
+  public function testSingleExtensionGetWithReturnFields() {
     $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest', 'return' => array('name', 'status', 'key')));
     $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
     $this->assertFalse(isset($result['values'][$result['id']]['type']));
@@ -81,15 +81,35 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test Extension Get resturns detailed information
+   * Test Extension Get returns detailed information
    * Note that this is likely to fail locally but will work on Jenkins due to the result count check
    * CRM-20532
    */
-  public function testExtesnionGet() {
+  public function testExtensionGet() {
     $result = $this->callAPISuccess('extension', 'get', array());
     $testExtensionResult = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.paymenttest'));
     $this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']);
-    $this->assertEquals(6, $result['count']);
+    $this->assertTrue($result['count'] >= 6);
+  }
+
+  /**
+   * Filtering by status=installed or status=uninstalled should produce different results.
+   */
+  public function testExtensionGetByStatus() {
+    $installed = $this->callAPISuccess('extension', 'get', array('status' => 'installed'));
+    $uninstalled = $this->callAPISuccess('extension', 'get', array('status' => 'uninstalled'));
+
+    // If the filter works, then results should be strictly independent.
+    $this->assertEquals(
+      array(),
+      array_intersect(
+        CRM_Utils_Array::collect('key', $installed['values']),
+        CRM_Utils_Array::collect('key', $uninstalled['values'])
+      )
+    );
+
+    $all = $this->callAPISuccess('extension', 'get', array());
+    $this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']);
   }
 
   public function testGetMultipleExtensions() {
@@ -97,4 +117,20 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
     $this->assertEquals(2, $result['count']);
   }
 
+  /**
+   * Test that extension get works with api request with parameter full_name as build by api explorer.
+   */
+  public function testGetMultipleExtensionsApiExplorer() {
+    $result = $this->callAPISuccess('extension', 'get', array('full_name' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest')));
+    $this->assertEquals(2, $result['count']);
+  }
+
+  /**
+   * Test that extension get can be filtered by id.
+   */
+  public function testGetExtensionByID() {
+    $result = $this->callAPISuccess('extension', 'get', array('id' => 2, 'return' => array('label')));
+    $this->assertEquals(1, $result['count']);
+  }
+
 }