CRM-15168 fix test to cope with problems with getactions
[civicrm-core.git] / tests / phpunit / api / v3 / SyntaxConformanceTest.php
index 13dc3b441b2ee73d3a01b6c295f299e757ee2b2d..b79acae7ff86b9452fe1251ea25e8cea87f45021 100644 (file)
@@ -159,6 +159,12 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     return static::entities(static::toBeSkipped_delete(TRUE));
   }
 
+  /**
+   * @return array
+   */
+  public static function entities_getfields() {
+    return static::entities(static::toBeSkipped_getfields(TRUE));
+  }
   /**
    * @return array
    */
@@ -250,6 +256,23 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     return $entities;
   }
 
+  /**
+   * @param bool $sequential
+   *
+   * @return array
+   * @todo add metadata for ALL these entities
+   */
+  public static function toBeSkipped_getfields($sequential = FALSE) {
+    $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
+    if ($sequential === TRUE) {
+      return $entitiesWithMetadataNotYetFixed ;
+    }
+    $entities = array();
+    foreach ($entitiesWithMetadataNotYetFixed as $e) {
+      $entities[] = array($e);
+    }
+    return $entities;
+  }
 /**
  * Generate list of entities to test for get by id functions
  * @param boolean $sequential
@@ -1100,6 +1123,50 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     );
   }
 
+  /**
+   * Create two entities and make sure delete action only deletes one!
+   *
+   * @dataProvider entities_getfields
+   *
+   */
+  public function testGetfieldsHasTitle($entity) {
+    $entities = $this->getEntitiesSupportingCustomFields();
+    if (in_array($entity, $entities)) {
+      $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $entity . 'Test.php');
+    }
+    $actions =  $this->callAPISuccess($entity, 'getactions', array());
+    foreach ($actions['values'] as $action) {
+      if (substr($action, -7) == '_create'  || substr($action, -4) == '_get' || substr($action, -7) == '_delete') {
+        //getactions can't distinguish between contribution_page.create & contribution_page.create
+        continue;
+      }
+      $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action));
+      if (!empty($ids) && in_array($action, array('create', 'get'))) {
+        $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']);
+      }
+
+      foreach ($fields['values'] as $fieldName => $fieldSpec) {
+        $this->assertArrayHasKey('title', $fieldSpec, "no title for $entity - $fieldName on action $action");
+        $this->assertNotEmpty($fieldSpec['title'], "empty title for $entity - $fieldName");
+      }
+    }
+    if (!empty($ids)) {
+      $this->customFieldDelete($ids['custom_field_id']);
+      $this->customGroupDelete($ids['custom_group_id']);
+    }
+  }
+
+  /**
+   * @return array
+   */
+  public function getEntitiesSupportingCustomFields() {
+    $entities = self::custom_data_entities_get();
+    $returnEntities = array();
+    foreach ($entities as $entityArray) {
+      $returnEntities[] = $entityArray[0];
+    }
+    return $returnEntities;
+  }
   /**
    * @param $entityName
    * @param int $count
@@ -1274,5 +1341,4 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       1 => array($eventId, 'Integer')
     ));
   }
-
 }