2 require_once('include/nusoap/nusoap.php');
8 class Bug39234Test extends Sugar_PHPUnit_Framework_TestCase
11 public $_soapClient = null;
12 public $_session = null;
13 public $_sessionId = '';
14 public $_contactId = '';
23 public function setUp()
25 $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'].'/soap.php',false,false,false,false,false,600,600);
26 $this->_setupTestUser();
30 require('include/modules.php');
31 $GLOBALS['beanList'] = $beanList;
32 $GLOBALS['beanFiles'] = $beanFiles;
35 $time = date('Y-m-d H:i:s');
37 $contact = new Contact();
38 $contact->id = 'c_'.$unid;
39 $contact->first_name = 'testfirst';
40 $contact->last_name = 'testlast';
41 $contact->email1 = 'fred@rogers.com';
42 $contact->new_with_id = true;
43 $contact->disable_custom_fields = true;
47 $account = new Account();
48 $account->id = 'a_'.$unid;
49 $account->name = 'acctfirst';
50 $account->assigned_user_id = 'SugarUser';
51 $account->new_with_id = true;
52 $account->disable_custom_fields = true;
56 $this->c1->load_relationship('accounts');
57 $this->c1->accounts->add($this->a1->id);
59 $contact2 = new Contact();
60 $contact2->id = 'c2_'.$unid;
61 $contact2->first_name = 'testfirst';
62 $contact2->last_name = 'testlast';
63 $contact2->email1 = 'fred@rogers.com';
64 $contact2->new_with_id = true;
65 $contact2->disable_custom_fields = true;
67 $this->c2 = $contact2;
71 * Remove anything that was used during this test
74 public function tearDown() {
75 global $soap_version_test_accountId, $soap_version_test_opportunityId, $soap_version_test_contactId;
76 $this->_tearDownTestUser();
78 $this->_sessionId = '';
79 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c1->id}'");
80 $GLOBALS['db']->query("DELETE FROM contacts WHERE id= '{$this->c2->id}'");
81 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c1->id}'");
82 $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id= '{$this->c2->id}'");
83 $GLOBALS['db']->query("DELETE FROM accounts WHERE id= '{$this->a1->id}'");
88 unset($soap_version_test_accountId);
89 unset($soap_version_test_opportunityId);
90 unset($soap_version_test_contactId);
91 unset($GLOBALS['beanList']);
92 unset($GLOBALS['beanFiles']);
95 public function testSetEntries() {
97 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c1->last_name), array('name'=>'email1' , 'value'=>$this->c1->email1), array('name'=>'first_name' , 'value'=>$this->c1->first_name), array('name'=>'account_name' , 'value'=>$this->a1->name)))));
98 $this->assertTrue(isset($result['ids']) && $result['ids'][0] == $this->c1->id);
101 public function testSetEntries2() {
103 $result = $this->_soapClient->call('set_entries',array('session'=>$this->_sessionId,'module_name' => 'Contacts','name_value_lists' => array(array(array('name'=>'last_name' , 'value'=>$this->c2->last_name), array('name'=>'email1' , 'value'=>$this->c2->email1), array('name'=>'first_name' , 'value'=>$this->c2->first_name), array('name'=>'account_name' , 'value'=>'joe pizza')))));
104 $this->assertTrue(isset($result['ids']) && $result['ids'][0] != $this->c1->id);
107 /**********************************
108 * HELPER PUBLIC FUNCTIONS
109 **********************************/
112 * Attempt to login to the soap server
114 * @return $set_entry_result - this should contain an id and error. The id corresponds
117 public function _login(){
118 global $current_user;
119 $result = $this->_soapClient->call('login',
121 array('user_name' => $current_user->user_name,
122 'password' => $current_user->user_hash,
124 'application_name' => 'SoapTest')
126 $this->_sessionId = $result['id'];
134 public function _setupTestUser() {
135 $this->_user = SugarTestUserUtilities::createAnonymousUser();
136 $this->_user->status = 'Active';
137 $this->_user->is_admin = 1;
138 $this->_user->save();
139 $GLOBALS['current_user'] = $this->_user;
143 * Remove user created for test
146 public function _tearDownTestUser() {
147 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
148 unset($GLOBALS['current_user']);