createCustomField(); $this->getSugarWidgetFieldRelate(); $this->account = SugarTestAccountUtilities::createAccount(); $this->contact1 = SugarTestContactUtilities::createContact(); $this->contact2 = SugarTestContactUtilities::createContact(); } public function tearDown() { $this->relateField->delete($this->df); $this->rc->repairAndClearAll(array("rebuildExtensions", "clearVardefs"), array("Contact"), false, false); SugarTestAccountUtilities::removeAllCreatedAccounts(); SugarTestContactUtilities::removeAllCreatedContacts(); SugarTestHelper::tearDown(); } /** * Create the custom field with type 'relate' */ protected function createCustomField() { $field = get_widget('relate'); $field->id = 'Contacts'. $this->field_name_c; $field->name = $this->field_name_c; $field->type = 'relate'; $field->label = 'LBL_' . strtoupper($this->field_name_c); $field->ext2 = 'Accounts'; $field->view_module = 'Contacts'; $this->relateField = $field; $this->bean =BeanFactory::getBean('Contacts'); $this->df = new DynamicField($this->bean->module_name); $this->df->setup($this->bean); $field->save($this->df); $this->rc = new RepairAndClear(); $this->rc->repairAndClearAll(array("rebuildExtensions", "clearVardefs"), array('Contact'), false, false); } /** * Create SugarWidget for relate field */ public function getSugarWidgetFieldRelate() { $layoutManager = new LayoutManager(); $layoutManager->setAttribute('context', 'Report'); $db = new stdClass(); $db->db = $GLOBALS['db']; $db->report_def_str = ''; $layoutManager->setAttributePtr('reporter', $db); $this->sugarWidget = new SugarWidgetFieldrelate($layoutManager); } /* * Check correct execution of the query for Dashlets if filter contains default bean's relate field * @return void */ public function testDefaultRelateField() { $this->contact2->account_id = $this->account->id; $this->contact2->save(); $layoutDef = array( 'name' => 'account_name', 'id_name' => 'account_id', 'type' => 'relate', 'link' => 'accounts_contacts', 'table' => 'contacts', 'table_alias' => 'contacts', 'module' => 'Contacts', 'input_name0' => array( 0 => $this->account->id ), ); $out = $this->sugarWidget->queryFilterone_of($layoutDef); $this->assertContains($this->contact2->id, $out, 'The request for existing relate field was made incorrectly'); } /* * Check correct execution of the query for Dashlets * if filter contains default bean's relate field with same LHS and RHS modules * @return void */ public function testDefaultRelateFieldForSameLHSAndRHSModules() { $this->contact2->reports_to_id = $this->contact1->id; $this->contact2->save(); $layoutDef = array( 'name' => 'report_to_name', 'id_name' => 'reports_to_id', 'type' => 'relate', 'link' => 'contact_direct_reports', 'table' => 'contacts', 'table_alias' => 'contacts', 'module' => 'Contacts', 'input_name0' => array( 0 => $this->contact2->reports_to_id ), ); $out = $this->sugarWidget->queryFilterone_of($layoutDef); $this->assertContains($this->contact2->id, $out, 'The request for existing relate field which has same LHS and RHS modules was made incorrectly'); } /* * Check correct execution of the query for Dashlets if filter contains custom relate field * @return void */ public function testCustomRelateFieldInDashlet() { $id = $this->relateField->ext3; $this->contact2->$id = $this->account->id; $this->contact2->save(); $layoutDef = array( 'name' => $this->relateField->name, 'id_name' => $this->relateField->ext3, 'type' => 'relate', 'ext2' => 'Accounts', 'custom_module' => 'Contacts', 'table' => 'contacts_cstm', 'table_alias' => 'contacts', 'module' => 'Accounts', 'input_name0' => array( 0 => $this->account->id ), ); $out = $this->sugarWidget->queryFilterone_of($layoutDef); $this->assertContains($this->contact2->id, $out, 'The request for custom relate field was made incorrectly'); } }