Add DAO quality test - ensure titles exists
authoreileen <emcnaughton@wikimedia.org>
Thu, 7 Jan 2016 06:07:56 +0000 (19:07 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 7 Jan 2016 07:03:33 +0000 (20:03 +1300)
This is the first DAO quality test but hopefully can be expanded later

18 files changed:
tests/phpunit/CRM/Core/DAOConformanceTest.php [new file with mode: 0644]
xml/schema/ACL/Cache.xml
xml/schema/Contact/ACLContactCache.xml
xml/schema/Core/ActionLog.xml
xml/schema/Core/ActionMapping.xml
xml/schema/Core/AddressFormat.xml
xml/schema/Core/County.xml
xml/schema/Core/Discount.xml
xml/schema/Core/Managed.xml
xml/schema/Core/PreferencesDate.xml
xml/schema/Core/PrevNextCache.xml
xml/schema/Core/StateProvince.xml
xml/schema/Core/Timezone.xml
xml/schema/Core/UFJoin.xml
xml/schema/Financial/EntityFinancialAccount.xml
xml/schema/Mailing/Event/Opened.xml
xml/schema/Mailing/Event/Reply.xml
xml/schema/Mailing/TrackableURL.xml

diff --git a/tests/phpunit/CRM/Core/DAOConformanceTest.php b/tests/phpunit/CRM/Core/DAOConformanceTest.php
new file mode 100644 (file)
index 0000000..1ebfc1d
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Class for testing new DAO meet required standards.
+ *
+ * Class CRM_Core_DAOTest
+ */
+class CRM_Core_DAOConformanceTest extends CiviUnitTestCase {
+
+  /**
+   * Check all fields have defined titles.
+   *
+   * @dataProvider getAllDAO
+   */
+  public function testFieldsHaveTitles($class) {
+    $dao = new $class();
+    $fields = $dao->fields();
+    foreach ($fields as $name => $field) {
+      $this->assertArrayHasKey('title', $field, "A title must be defined for $name in $class");
+    }
+  }
+
+  /**
+   * Get all DAO classes.
+   */
+  public function getAllDAO() {
+    $classList = CRM_Core_DAO_AllCoreTables::getClasses();
+    $return = array();
+    $notYetTitledDAO = $this->getClassesWithoutTitlesYet();
+    foreach ($classList as $class) {
+      if (!in_array($class, $notYetTitledDAO)) {
+        $return[] = array($class);
+      }
+    }
+    return $return;
+  }
+
+  /**
+   * Classes that do not yet conform to expectation they will have a title for each field.
+   *
+   * When we start enforcing a new standard we have to grandfather it in & these classes need titles added.
+   *
+   * Note that we want titles so that things like views integration can rely on using them and so the person
+   * introducing the DAO is responsible for it's titles - not the person who adds it to the api later.
+   */
+  public function getClassesWithoutTitlesYet() {
+    return array(
+      'CRM_Contact_DAO_ACLContactCache',
+      'CRM_Core_DAO_Managed',
+      'CRM_Core_DAO_PreferencesDate',
+      'CRM_Event_Cart_DAO_EventInCart',
+      'CRM_PCP_DAO_PCPBlock',
+      'CRM_Case_DAO_CaseActivity',
+      'CRM_Core_DAO_Discount',
+      'CRM_Price_DAO_PriceSetEntity',
+      'CRM_Case_DAO_CaseContact',
+      'CRM_Contribute_DAO_Widget',
+      'CRM_Contribute_DAO_PremiumsProduct',
+      'CRM_Core_DAO_Persistent',
+      'CRM_Mailing_Event_DAO_TrackableURLOpen',
+      'CRM_Mailing_Event_DAO_Reply',
+      'CRM_Mailing_Event_DAO_Delivered',
+      'CRM_Mailing_Event_DAO_Forward',
+      'CRM_Mailing_Event_DAO_Bounce',
+      'CRM_Mailing_Event_DAO_Opened',
+      'CRM_Mailing_DAO_Spool',
+      'CRM_Mailing_DAO_TrackableURL',
+      'CRM_Contact_DAO_GroupContactCache',
+      'CRM_Contact_DAO_SubscriptionHistory',
+      'CRM_Core_DAO_Menu',
+      'CRM_Core_DAO_Log',
+      'CRM_Core_DAO_EntityFile',
+      'CRM_PCP_DAO_PCP',
+      'CRM_Queue_DAO_QueueItem',
+      'CRM_Pledge_DAO_PledgeBlock',
+      'CRM_Friend_DAO_Friend',
+      'CRM_Dedupe_DAO_Exception',
+      'CRM_Dedupe_DAO_Rule',
+      'CRM_Dedupe_DAO_RuleGroup',
+      'CRM_Event_Cart_DAO_Cart',
+      'CRM_Campaign_DAO_CampaignGroup',
+      'CRM_Financial_DAO_EntityFinancialAccount',
+      'CRM_Financial_DAO_Currency',
+      'CRM_Mailing_DAO_BouncePattern',
+      'CRM_Mailing_DAO_BounceType',
+    );
+  }
+
+}
index 52f34f9b466ed83903d6816f20424cce59b223d2..a798dff6ac8bf5b41b1bb3feeccfb96a700506cb 100644 (file)
@@ -8,6 +8,7 @@
   <add>1.6</add>
   <field>
     <name>id</name>
+    <title>Cache ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Unique table ID</comment>
@@ -19,6 +20,7 @@
   </primaryKey>
   <field>
     <name>contact_id</name>
+    <title>Cache Contact</title>
     <type>int unsigned</type>
     <comment>Foreign Key to Contact</comment>
     <add>1.6</add>
@@ -32,6 +34,7 @@
   </foreignKey>
   <field>
     <name>acl_id</name>
+    <title>Cache ACL</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Foreign Key to ACL</comment>
@@ -51,6 +54,7 @@
   </index>
   <field>
     <name>modified_date</name>
+    <title>Cache Modified Date</title>
     <type>date</type>
     <comment>When was this cache entry last modified</comment>
     <add>1.6</add>
index f584a4de74da6b05ba5c0b3b26be58904c0ba0e0..72e4bdb8a010cc028746f3d48f883f259dcf55b2 100644 (file)
@@ -8,6 +8,7 @@
   <add>3.1</add>
   <field>
     <name>id</name>
+    <title>ACL Contact Cache ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>primary key</comment>
index f0faf45bbbce32160eed12137cb11bab65280d75..9bfc8cbcd4807235fa92dcfa5ba5f3b44854468e 100644 (file)
@@ -8,6 +8,7 @@
   <add>3.4</add>
   <field>
     <name>id</name>
+    <title>Action Schedule ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <add>3.4</add>
@@ -18,6 +19,7 @@
   </primaryKey>
   <field>
     <name>contact_id</name>
+    <title>Action Schedule Contact ID</title>
     <type>int unsigned</type>
     <comment>FK to Contact ID</comment>
     <add>3.4</add>
@@ -31,6 +33,7 @@
   </foreignKey>
   <field>
     <name>entity_id</name>
+    <title>Entity ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to id of the entity that the action was performed on. Pseudo - FK.</comment>
@@ -39,6 +42,7 @@
   <field>
     <name>entity_table</name>
     <type>varchar</type>
+    <title>Entity Table</title>
     <length>255</length>
     <comment>name of the entity table for the above id, e.g. civicrm_activity, civicrm_participant</comment>
     <add>3.4</add>
@@ -50,6 +54,7 @@
   </dynamicForeignKey>
   <field>
     <name>action_schedule_id</name>
+    <title>Schedule</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to the action schedule that this action originated from.</comment>
   </foreignKey>
   <field>
     <name>action_date_time</name>
+    <title>Action Date And Time</title>
     <type>datetime</type>
     <comment>date time that the action was performed on.</comment>
     <add>3.4</add>
   </field>
   <field>
     <name>is_error</name>
+    <title>Error?</title>
     <type>boolean</type>
     <default>0</default>
     <comment>Was there any error sending the reminder?</comment>
   </field>
   <field>
     <name>message</name>
+    <title>Message</title>
     <type>text</type>
     <comment>Description / text in case there was an error encountered.</comment>
     <add>3.4</add>
   </field>
   <field>
     <name>repetition_number</name>
+    <title>Repetition Number</title>
     <type>int unsigned</type>
     <comment>Keeps track of the sequence number of this repetition.</comment>
     <add>3.4</add>
   </field>
   <field>
     <name>reference_date</name>
+    <title>Reference Date</title>
     <type>date</type>
     <default>NULL</default>
     <comment>Stores the date from the entity which triggered this reminder action (e.g. membership.end_date for most membership renewal reminders)</comment>
index e889c3bc3dfd545bd8e5bf1f538958e8e31656d3..5ce84e661146581b17b8512234cf2daf01297821 100644 (file)
@@ -8,6 +8,7 @@
   <add>3.4</add>
   <field>
     <name>id</name>
+    <title>Action Mapping ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <add>3.4</add>
@@ -18,6 +19,7 @@
   </primaryKey>
   <field>
     <name>entity</name>
+    <title>Action Mapping Entity</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity for which the reminder is created</comment>
@@ -25,6 +27,7 @@
   </field>
   <field>
     <name>entity_value</name>
+    <title>Action Mapping Entity Value</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity value</comment>
@@ -32,6 +35,7 @@
   </field>
   <field>
     <name>entity_value_label</name>
+    <title>Value Label</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity value label</comment>
@@ -39,6 +43,7 @@
   </field>
   <field>
     <name>entity_status</name>
+    <title>Status</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity status</comment>
@@ -46,6 +51,7 @@
   </field>
   <field>
     <name>entity_status_label</name>
+    <title>Status Label</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity status label</comment>
   </field>
   <field>
     <name>entity_date_start</name>
-    <type>varchar</type>
+      <title>Entity Start Date</title>
+      <type>varchar</type>
     <length>64</length>
     <comment>Entity date</comment>
     <add>3.4</add>
   </field>
   <field>
     <name>entity_date_end</name>
+    <title>Entity End Date</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity date</comment>
@@ -67,6 +75,7 @@
   </field>
   <field>
     <name>entity_recipient</name>
+    <title>Entity Recipient</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Entity recipient</comment>
index 6222cb262c8fb68f0107d1e5876fc0f813ffbd25..ae678018b9e8b8102406f597e46ab068e6bb0faf 100644 (file)
@@ -7,6 +7,7 @@
   <add>3.2</add>
   <field>
     <name>id</name>
+    <title>Address Format ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Address Format Id</comment>
index 2a5ba001f7461c98c269c217261fb35d5e2941d8..edd4513ff880df44a65e3c72d8c12080d00980f2 100644 (file)
@@ -7,6 +7,7 @@
   <add>1.1</add>
   <field>
     <name>id</name>
+    <title>County ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>County ID</comment>
@@ -37,6 +38,7 @@
   </field>
   <field>
     <name>state_province_id</name>
+    <title>State</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>ID of State/Province that County belongs</comment>
index 12b370e5303b916c32bfaf225a9736ea891c97b1..617f2e4d8c59e7a06973fd0617f9f54d7ae6b665 100644 (file)
     <add>4.3</add>
     <onDelete>CASCADE</onDelete>
   </foreignKey>
-  <dynamicForeignKey>
-    <idColumn>entity_id</idColumn>
-    <typeColumn>entity_table</typeColumn>
-  </dynamicForeignKey>
   <index>
     <name>index_entity_option_id</name>
     <fieldName>entity_table</fieldName>
index 54eba7f4199edb8de14fc566776934549efbec8c..4b8bd204c75ff70181667dc96a9d75e3b4595774 100644 (file)
@@ -9,6 +9,7 @@
   <log>false</log>
   <field>
     <name>id</name>
+    <title>Managed ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Surrogate Key</comment>
index 8aa1ed7ed860fa00f49a27854b2d137e3ccaa7e8..a441117ad4f164e146192ccaa6a526ebbfb7b12e 100644 (file)
@@ -9,6 +9,7 @@
   <log>true</log>
   <field>
     <name>id</name>
+    <title>Date Preference ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <add>2.0</add>
@@ -19,6 +20,7 @@
   </primaryKey>
   <field>
     <name>name</name>
+    <title>Date Preference Name</title>
     <type>varchar</type>
     <length>64</length>
     <required>true</required>
index 5db686e6532e372e94a0074803bec8a0c9d36698..7c74a19cee3757458d52d0ce529bcd9a3161161c 100644 (file)
@@ -8,6 +8,7 @@
   <add>3.4</add>
   <field>
     <name>id</name>
+    <title>Prev Next Cache ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <add>3.4</add>
@@ -18,6 +19,7 @@
   </primaryKey>
   <field>
     <name>entity_table</name>
+    <title>Prev Next Entity Table</title>
     <type>varchar</type>
     <length>64</length>
     <comment>physical tablename for entity being joined to discount, e.g. civicrm_event</comment>
@@ -25,6 +27,7 @@
   </field>
   <field>
     <name>entity_id1</name>
+    <title>Prev Next Entity ID 1</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to entity table specified in entity_table column.</comment>
@@ -32,6 +35,7 @@
   </field>
   <field>
     <name>entity_id2</name>
+    <title>Prev Next Entity ID 2</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to entity table specified in entity_table column.</comment>
@@ -39,6 +43,7 @@
   </field>
   <field>
     <name>cacheKey</name>
+    <title>Cache Key</title>
     <type>varchar</type>
     <length>255</length>
     <comment>Unique path name for cache element of the searched item</comment>
   </field>
   <field>
     <name>data</name>
+    <title>Prev Next Data</title>
     <type>longtext</type>
     <comment>cached snapshot of the serialized data</comment>
     <add>3.4</add>
   </field>
   <field>
     <name>is_selected</name>
+    <title>Is Selected</title>
     <type>boolean</type>
     <default>0</default>
     <add>4.2</add>
index 584945c3784b509b012a81dadf58901b0f6b5626..f7fd037af55624765ad700ced17f023184152bd3 100644 (file)
@@ -7,6 +7,7 @@
   <add>1.1</add>
   <field>
     <name>id</name>
+    <title>State ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>State/Province ID</comment>
@@ -37,6 +38,7 @@
   </field>
   <field>
     <name>country_id</name>
+    <title>County</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>ID of Country that State/Province belong</comment>
index edccd0778c9526c44a565fd18a1755ff6181e810..a7930d860930485c139bd2aa73e9539aad453acd 100644 (file)
@@ -7,6 +7,7 @@
   <add>1.8</add>
   <field>
     <name>id</name>
+    <title>Timezone ID</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Timezone Id</comment>
@@ -18,6 +19,7 @@
   </primaryKey>
   <field>
     <name>name</name>
+    <title>Timezone Name</title>
     <type>varchar</type>
     <length>64</length>
     <comment>Timezone full name</comment>
@@ -25,6 +27,7 @@
   </field>
   <field>
     <name>abbreviation</name>
+    <title>Timezone Abbreviation</title>
     <type>char</type>
     <length>3</length>
     <comment>ISO Code for timezone abbreviation</comment>
@@ -32,6 +35,7 @@
   </field>
   <field>
     <name>gmt</name>
+    <title>GMT Name of Timezone</title>
     <type>varchar</type>
     <length>64</length>
     <comment>GMT name of the timezone</comment>
   </field>
   <field>
     <name>offset</name>
+    <title>GMT Offset</title>
     <type>int</type>
     <comment></comment>
     <add>1.8</add>
   </field>
   <field>
     <name>country_id</name>
+    <title>Country</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>Country Id</comment>
index f0aae07b34cb97ba703d7c98e75c75ec5e63875e..c3add7f1366551289e0f308edda259d520cb03e1 100644 (file)
@@ -58,7 +58,6 @@
   </dynamicForeignKey>
   <index>
     <name>index_entity</name>
-    <add>1.3</add>
     <fieldName>entity_table</fieldName>
     <fieldName>entity_id</fieldName>
     <add>1.3</add>
index 29dfc30bde425c9fbe4bf4749976dc695de9911b..de635c6874dc50ba5e11447c9255595f5a73fa80 100755 (executable)
@@ -34,7 +34,7 @@
     <add>4.3</add>
     <comment>Links to an id in the entity_table, such as vid in civicrm_financial_type</comment>
   </field>
-  <dynamicForeignKey>
+      <dynamicForeignKey>
     <idColumn>entity_id</idColumn>
     <typeColumn>entity_table</typeColumn>
     <add>4.3</add>
index 8367148a563de55aef0e39378bde5de893067620..d43ffd823b27f4a740b31b0c1268dc96becda848 100644 (file)
@@ -8,6 +8,7 @@
   <archive>true</archive>
   <field>
     <name>id</name>
+    <title>Mailing Opened ID</title>
     <type>int unsigned</type>
     <required>true</required>
   </field>
@@ -17,6 +18,7 @@
   </primaryKey>
   <field>
     <name>event_queue_id</name>
+    <title>Event Queue</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to EventQueue</comment>
index 0fe33e555844bb9cf3fe3c6ce54dacaddae9822d..a6020e186dbf45d6b8c524c257003c6072166474 100644 (file)
@@ -8,6 +8,7 @@
   <archive>true</archive>
   <field>
     <name>id</name>
+    <title>Reply ID</title>
     <type>int unsigned</type>
     <required>true</required>
   </field>
@@ -17,6 +18,7 @@
   </primaryKey>
   <field>
     <name>event_queue_id</name>
+    <title>Event Queue</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to EventQueue</comment>
@@ -29,6 +31,7 @@
   </foreignKey>
   <field>
     <name>time_stamp</name>
+    <title>Reply Timestamp</title>
     <type>datetime</type>
     <required>true</required>
     <comment>When this reply event occurred.</comment>
index 36abb63210605507ab5e5b1ee788b52f6dbdf3be..f1b510a1d4593fee358372385926de2a470e9443 100644 (file)
@@ -8,6 +8,7 @@
   <archive>true</archive>
   <field>
     <name>id</name>
+    <title>Trackable URL ID</title>
     <type>int unsigned</type>
     <required>true</required>
   </field>
   </primaryKey>
   <field>
     <name>url</name>
-    <type>text</type>    
+    <title>Url</title>
+    <type>text</type>
     <required>true</required>
     <comment>The URL to be tracked.</comment>
   </field>
   <field>
     <name>mailing_id</name>
+    <title>Mailing</title>
     <type>int unsigned</type>
     <required>true</required>
     <comment>FK to the mailing</comment>