/** * Test Validate if Deferred Account is set for Financial Type. */ public function testValidateTogglingDeferredRevenue() { $orgContactID = $this->organizationCreate(); //create relationship $params = array('name_a_b' => 'Relation 1', 'name_b_a' => 'Relation 2', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1); $relationshipTypeId = $this->relationshipTypeCreate($params); $ids = array(); $params = array('name' => 'test type', 'domain_id' => 1, 'description' => NULL, 'minimum_fee' => 10, 'duration_unit' => 'year', 'member_of_contact_id' => $orgContactID, 'relationship_type_id' => $relationshipTypeId, 'period_type' => 'fixed', 'duration_interval' => 1, 'financial_type_id' => 1, 'visibility' => 'Public', 'is_active' => 1); $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); $membership = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $orgContactID, 'name', 'member_of_contact_id', 'Database check on updated membership record.'); $error = CRM_Financial_BAO_FinancialAccount::validateTogglingDeferredRevenue(); $this->assertTrue(!empty($error), "Error message did not appear"); $this->membershipTypeDelete(array('id' => $membershipType->id)); }
/** * Global validation rules for the form. * * @param array $values * posted values of the form * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($values, $files, $self) { $errors = array(); if (CRM_Utils_Array::value('deferred_revenue_enabled', $values)) { $errorMessage = CRM_Financial_BAO_FinancialAccount::validateTogglingDeferredRevenue(); if ($errorMessage) { // Since the error msg is too long and // takes the whole space to display inline // therefore setting blank text to highlight the field // setting actual error msg to _qf_default to show in pop-up screen $errors['deferred_revenue_enabled'] = ' '; $errors['_qf_default'] = $errorMessage; } } return $errors; }