_user = SugarTestUserUtilities::createAnonymousUser(); $GLOBALS['current_user'] = $this->_user; $this->_account = SugarTestAccountUtilities::createAccount(); } public function tearDown() { if ($this->email_id) { $GLOBALS['db']->query("delete from emails where id='{$this->email_id}'"); } SugarTestAccountUtilities::removeAllCreatedAccounts(); SugarTestUserUtilities::removeAllCreatedAnonymousUsers(); unset($GLOBALS['current_user']); } public function testSaveNewEmailWithParent() { $email = new Email(); $email->type = 'out'; $email->status = 'sent'; $email->from_addr_name = $email->cleanEmails("sender@domain.eu"); $email->to_addrs_names = $email->cleanEmails("to@domain.eu"); $email->cc_addrs_names = $email->cleanEmails("cc@domain.eu"); // set a few parent info to test the scenario $email->parent_type = 'Accounts'; $email->parent_id = $this->_account->id; $email->fetched_row['parent_type'] = 'Accounts'; $email->fetched_row['parent_id'] = $this->_account->id; $email->save(); $this->assertNotNull($email->id, 'Null email id'); $this->email_id = $email->id; // ensure record is inserted into emails_beans table $query = "select count(*) as CNT from emails_beans eb WHERE eb.bean_id = '{$this->_account->id}' AND eb.bean_module = 'Accounts' AND eb.email_id = '{$email->id}' AND eb.deleted=0"; $result = $GLOBALS['db']->query($query); $count = $GLOBALS['db']->fetchByAssoc($result); $this->assertEquals(1, $count['CNT'], 'Incorrect emails_beans count'); } }