From fa6ace1a13a8aa6ffa38bfaa656bd61327c5f219 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 7 Jan 2016 19:07:56 +1300 Subject: [PATCH] Add DAO quality test - ensure titles exists This is the first DAO quality test but hopefully can be expanded later --- tests/phpunit/CRM/Core/DAOConformanceTest.php | 91 +++++++++++++++++++ xml/schema/ACL/Cache.xml | 4 + xml/schema/Contact/ACLContactCache.xml | 1 + xml/schema/Core/ActionLog.xml | 10 ++ xml/schema/Core/ActionMapping.xml | 11 ++- xml/schema/Core/AddressFormat.xml | 1 + xml/schema/Core/County.xml | 2 + xml/schema/Core/Discount.xml | 4 - xml/schema/Core/Managed.xml | 1 + xml/schema/Core/PreferencesDate.xml | 2 + xml/schema/Core/PrevNextCache.xml | 7 ++ xml/schema/Core/StateProvince.xml | 2 + xml/schema/Core/Timezone.xml | 6 ++ xml/schema/Core/UFJoin.xml | 1 - .../Financial/EntityFinancialAccount.xml | 2 +- xml/schema/Mailing/Event/Opened.xml | 2 + xml/schema/Mailing/Event/Reply.xml | 3 + xml/schema/Mailing/TrackableURL.xml | 5 +- 18 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 tests/phpunit/CRM/Core/DAOConformanceTest.php diff --git a/tests/phpunit/CRM/Core/DAOConformanceTest.php b/tests/phpunit/CRM/Core/DAOConformanceTest.php new file mode 100644 index 0000000000..1ebfc1dbf5 --- /dev/null +++ b/tests/phpunit/CRM/Core/DAOConformanceTest.php @@ -0,0 +1,91 @@ +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', + ); + } + +} diff --git a/xml/schema/ACL/Cache.xml b/xml/schema/ACL/Cache.xml index 52f34f9b46..a798dff6ac 100644 --- a/xml/schema/ACL/Cache.xml +++ b/xml/schema/ACL/Cache.xml @@ -8,6 +8,7 @@ 1.6 id + Cache ID int unsigned true Unique table ID @@ -19,6 +20,7 @@ contact_id + Cache Contact int unsigned Foreign Key to Contact 1.6 @@ -32,6 +34,7 @@ acl_id + Cache ACL int unsigned true Foreign Key to ACL @@ -51,6 +54,7 @@ modified_date + Cache Modified Date date When was this cache entry last modified 1.6 diff --git a/xml/schema/Contact/ACLContactCache.xml b/xml/schema/Contact/ACLContactCache.xml index f584a4de74..72e4bdb8a0 100644 --- a/xml/schema/Contact/ACLContactCache.xml +++ b/xml/schema/Contact/ACLContactCache.xml @@ -8,6 +8,7 @@ 3.1 id + ACL Contact Cache ID int unsigned true primary key diff --git a/xml/schema/Core/ActionLog.xml b/xml/schema/Core/ActionLog.xml index f0faf45bbb..9bfc8cbcd4 100644 --- a/xml/schema/Core/ActionLog.xml +++ b/xml/schema/Core/ActionLog.xml @@ -8,6 +8,7 @@ 3.4 id + Action Schedule ID int unsigned true 3.4 @@ -18,6 +19,7 @@ contact_id + Action Schedule Contact ID int unsigned FK to Contact ID 3.4 @@ -31,6 +33,7 @@ entity_id + Entity ID int unsigned true FK to id of the entity that the action was performed on. Pseudo - FK. @@ -39,6 +42,7 @@ entity_table varchar + Entity Table 255 name of the entity table for the above id, e.g. civicrm_activity, civicrm_participant 3.4 @@ -50,6 +54,7 @@ action_schedule_id + Schedule int unsigned true FK to the action schedule that this action originated from. @@ -64,12 +69,14 @@ action_date_time + Action Date And Time datetime date time that the action was performed on. 3.4 is_error + Error? boolean 0 Was there any error sending the reminder? @@ -77,18 +84,21 @@ message + Message text Description / text in case there was an error encountered. 3.4 repetition_number + Repetition Number int unsigned Keeps track of the sequence number of this repetition. 3.4 reference_date + Reference Date date NULL Stores the date from the entity which triggered this reminder action (e.g. membership.end_date for most membership renewal reminders) diff --git a/xml/schema/Core/ActionMapping.xml b/xml/schema/Core/ActionMapping.xml index e889c3bc3d..5ce84e6611 100644 --- a/xml/schema/Core/ActionMapping.xml +++ b/xml/schema/Core/ActionMapping.xml @@ -8,6 +8,7 @@ 3.4 id + Action Mapping ID int unsigned true 3.4 @@ -18,6 +19,7 @@ entity + Action Mapping Entity varchar 64 Entity for which the reminder is created @@ -25,6 +27,7 @@ entity_value + Action Mapping Entity Value varchar 64 Entity value @@ -32,6 +35,7 @@ entity_value_label + Value Label varchar 64 Entity value label @@ -39,6 +43,7 @@ entity_status + Status varchar 64 Entity status @@ -46,6 +51,7 @@ entity_status_label + Status Label varchar 64 Entity status label @@ -53,13 +59,15 @@ entity_date_start - varchar + Entity Start Date + varchar 64 Entity date 3.4 entity_date_end + Entity End Date varchar 64 Entity date @@ -67,6 +75,7 @@ entity_recipient + Entity Recipient varchar 64 Entity recipient diff --git a/xml/schema/Core/AddressFormat.xml b/xml/schema/Core/AddressFormat.xml index 6222cb262c..ae678018b9 100644 --- a/xml/schema/Core/AddressFormat.xml +++ b/xml/schema/Core/AddressFormat.xml @@ -7,6 +7,7 @@ 3.2 id + Address Format ID int unsigned true Address Format Id diff --git a/xml/schema/Core/County.xml b/xml/schema/Core/County.xml index 2a5ba001f7..edd4513ff8 100644 --- a/xml/schema/Core/County.xml +++ b/xml/schema/Core/County.xml @@ -7,6 +7,7 @@ 1.1 id + County ID int unsigned true County ID @@ -37,6 +38,7 @@ state_province_id + State int unsigned true ID of State/Province that County belongs diff --git a/xml/schema/Core/Discount.xml b/xml/schema/Core/Discount.xml index 12b370e530..617f2e4d8c 100644 --- a/xml/schema/Core/Discount.xml +++ b/xml/schema/Core/Discount.xml @@ -78,10 +78,6 @@ 4.3 CASCADE - - entity_id - entity_table - index_entity_option_id entity_table diff --git a/xml/schema/Core/Managed.xml b/xml/schema/Core/Managed.xml index 54eba7f419..4b8bd204c7 100644 --- a/xml/schema/Core/Managed.xml +++ b/xml/schema/Core/Managed.xml @@ -9,6 +9,7 @@ false id + Managed ID int unsigned true Surrogate Key diff --git a/xml/schema/Core/PreferencesDate.xml b/xml/schema/Core/PreferencesDate.xml index 8aa1ed7ed8..a441117ad4 100644 --- a/xml/schema/Core/PreferencesDate.xml +++ b/xml/schema/Core/PreferencesDate.xml @@ -9,6 +9,7 @@ true id + Date Preference ID int unsigned true 2.0 @@ -19,6 +20,7 @@ name + Date Preference Name varchar 64 true diff --git a/xml/schema/Core/PrevNextCache.xml b/xml/schema/Core/PrevNextCache.xml index 5db686e653..7c74a19cee 100644 --- a/xml/schema/Core/PrevNextCache.xml +++ b/xml/schema/Core/PrevNextCache.xml @@ -8,6 +8,7 @@ 3.4 id + Prev Next Cache ID int unsigned true 3.4 @@ -18,6 +19,7 @@ entity_table + Prev Next Entity Table varchar 64 physical tablename for entity being joined to discount, e.g. civicrm_event @@ -25,6 +27,7 @@ entity_id1 + Prev Next Entity ID 1 int unsigned true FK to entity table specified in entity_table column. @@ -32,6 +35,7 @@ entity_id2 + Prev Next Entity ID 2 int unsigned true FK to entity table specified in entity_table column. @@ -39,6 +43,7 @@ cacheKey + Cache Key varchar 255 Unique path name for cache element of the searched item @@ -46,12 +51,14 @@ data + Prev Next Data longtext cached snapshot of the serialized data 3.4 is_selected + Is Selected boolean 0 4.2 diff --git a/xml/schema/Core/StateProvince.xml b/xml/schema/Core/StateProvince.xml index 584945c378..f7fd037af5 100644 --- a/xml/schema/Core/StateProvince.xml +++ b/xml/schema/Core/StateProvince.xml @@ -7,6 +7,7 @@ 1.1 id + State ID int unsigned true State/Province ID @@ -37,6 +38,7 @@ country_id + County int unsigned true ID of Country that State/Province belong diff --git a/xml/schema/Core/Timezone.xml b/xml/schema/Core/Timezone.xml index edccd0778c..a7930d8609 100644 --- a/xml/schema/Core/Timezone.xml +++ b/xml/schema/Core/Timezone.xml @@ -7,6 +7,7 @@ 1.8 id + Timezone ID int unsigned true Timezone Id @@ -18,6 +19,7 @@ name + Timezone Name varchar 64 Timezone full name @@ -25,6 +27,7 @@ abbreviation + Timezone Abbreviation char 3 ISO Code for timezone abbreviation @@ -32,6 +35,7 @@ gmt + GMT Name of Timezone varchar 64 GMT name of the timezone @@ -39,12 +43,14 @@ offset + GMT Offset int 1.8 country_id + Country int unsigned true Country Id diff --git a/xml/schema/Core/UFJoin.xml b/xml/schema/Core/UFJoin.xml index f0aae07b34..c3add7f136 100644 --- a/xml/schema/Core/UFJoin.xml +++ b/xml/schema/Core/UFJoin.xml @@ -58,7 +58,6 @@ index_entity - 1.3 entity_table entity_id 1.3 diff --git a/xml/schema/Financial/EntityFinancialAccount.xml b/xml/schema/Financial/EntityFinancialAccount.xml index 29dfc30bde..de635c6874 100755 --- a/xml/schema/Financial/EntityFinancialAccount.xml +++ b/xml/schema/Financial/EntityFinancialAccount.xml @@ -34,7 +34,7 @@ 4.3 Links to an id in the entity_table, such as vid in civicrm_financial_type - + entity_id entity_table 4.3 diff --git a/xml/schema/Mailing/Event/Opened.xml b/xml/schema/Mailing/Event/Opened.xml index 8367148a56..d43ffd823b 100644 --- a/xml/schema/Mailing/Event/Opened.xml +++ b/xml/schema/Mailing/Event/Opened.xml @@ -8,6 +8,7 @@ true id + Mailing Opened ID int unsigned true @@ -17,6 +18,7 @@ event_queue_id + Event Queue int unsigned true FK to EventQueue diff --git a/xml/schema/Mailing/Event/Reply.xml b/xml/schema/Mailing/Event/Reply.xml index 0fe33e5558..a6020e186d 100644 --- a/xml/schema/Mailing/Event/Reply.xml +++ b/xml/schema/Mailing/Event/Reply.xml @@ -8,6 +8,7 @@ true id + Reply ID int unsigned true @@ -17,6 +18,7 @@ event_queue_id + Event Queue int unsigned true FK to EventQueue @@ -29,6 +31,7 @@ time_stamp + Reply Timestamp datetime true When this reply event occurred. diff --git a/xml/schema/Mailing/TrackableURL.xml b/xml/schema/Mailing/TrackableURL.xml index 36abb63210..f1b510a1d4 100644 --- a/xml/schema/Mailing/TrackableURL.xml +++ b/xml/schema/Mailing/TrackableURL.xml @@ -8,6 +8,7 @@ true id + Trackable URL ID int unsigned true @@ -17,12 +18,14 @@ url - text + Url + text true The URL to be tracked. mailing_id + Mailing int unsigned true FK to the mailing -- 2.25.1