]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/soap/Bug61159Test.php
Release 6.5.14
[Github/sugarcrm.git] / tests / soap / Bug61159Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38 require_once('tests/service/SOAPTestCase.php');
39 require_once('soap/SoapHelperFunctions.php');
40
41 /**
42  * Bug #61159
43  * Soap API add_create_account bug
44  *
45  * @author bsitnikovski@sugarcrm.com
46  * @ticket 61159
47  */
48 class Bug61159Test extends Sugar_PHPUnit_Framework_TestCase
49 {
50
51     private $_account1, $_account2, $_contact;
52     private $_deletedAcc, $_deletedAccContact;
53     private $_contact2;
54     private $_tmpacc;
55
56     /**
57      * Create contact function
58      */
59     public function createContact($account_id, $account_name)
60     {
61         $contact = SugarTestContactUtilities::createContact();
62         $contact->account_id = $account_id;
63         $contact->account_name = $account_name;
64         $contact->save();
65         $GLOBALS['db']->commit();
66         return $contact;
67     }
68
69     /**
70      * Create account function
71      */
72     public function createAccount($name, $deleted = 0)
73     {
74         $account = SugarTestAccountUtilities::createAccount();
75         $account->name = $account->account_name = $name;
76         $account->deleted = $deleted;
77         $account->save();
78         $GLOBALS['db']->commit();
79         return $account;
80     }
81
82     /**
83      * Create user, account, contact
84      */
85     public function setUp()
86     {
87         $this->_account1 = $this->createAccount("Account Bug61159Test");
88         $this->_account2 = $this->createAccount("Account Bug61159Test");
89         $this->_contact = $this->createContact($this->_account2->id, "Account Bug61159Test");
90         $this->_contact2 = $this->createContact(0, "Account Bug61159Test");
91
92         $this->_deletedAcc = $this->createAccount("Account Bug61159Test 2", 1);
93         $this->_deletedAccContact = $this->createContact($this->_deletedAcc->id, "Account Bug61159Test 2");
94
95         parent::setUp();
96     }
97
98     /**
99      * Remove account, contact, user
100      */
101     public function tearDown()
102     {
103         $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$this->_account1->id}' OR id = '{$this->_account2->id}' OR id = '{$this->_deletedAcc->id}' OR id = '{$this->_deletedAccContact->account_id}'");
104         $GLOBALS['db']->query("DELETE FROM contacts WHERE id = '{$this->_contact->id}' OR id = '{$this->_deletedAccContact->id}' OR id = '{$this->_contact2->id}'");
105         $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id = '{$this->_contact->id}' OR contact_id = '{$this->_deletedAccContact->id}' OR contact_id = '{$this->_contact2->id}'");
106         if (isset($this->_tmpacc))
107         {
108             $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$this->_tmpacc->id}'");
109         }
110     }
111
112     /**
113      * Test add_create_account() to see if it reassigns the contact's account (by Account id)
114      */
115     public function testReassignContactById()
116     {
117         add_create_account($this->_contact);
118         $this->assertEquals($this->_contact->account_id, $this->_account2->id);
119     }
120
121     /**
122      * Test add_create_account() to see if it will assign an account to a contact without accounts
123      */
124     public function testAssignAccountToContact()
125     {
126         add_create_account($this->_contact2);
127         $this->assertNotEquals($this->_contact2->account_id, 0);
128     }
129
130     /**
131      * Test add_create_account() to see if it will delete a deleted account and create a new one
132      */
133     public function testDeletedAccountCreateNew()
134     {
135         add_create_account($this->_deletedAccContact);
136         $this->assertNotEquals($this->_deletedAcc->id, $this->_deletedAccContact->account_id);
137     }
138
139     /**
140      * Test add_create_account() to see if it will create a new account (non-existent by ID and non-existent by Name)
141      */
142     public function testNotFoundCreateNew()
143     {
144         $dummyContact = new Contact();
145         $dummyContact->account_name = "UniqueAccountNameTest123";
146         add_create_account($dummyContact);
147         $this->_tmpacc = new Account();
148         $this->_tmpacc->retrieve_by_string_fields(array('name' => 'UniqueAccountNameTest123'));
149         $this->assertNotNull($this->_tmpacc->id);
150     }
151
152 }