]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/service/Bug38858Test.php
Release 6.5.11
[Github/sugarcrm.git] / tests / service / Bug38858Test.php
1 <?php
2
3 /*********************************************************************************
4  * By installing or using this file, you are confirming on behalf of the entity
5  * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
6  * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
7  * http://www.sugarcrm.com/master-subscription-agreement
8  *
9  * If Company is not bound by the MSA, then by installing or using this file
10  * you are agreeing unconditionally that Company will be bound by the MSA and
11  * certifying that you have authority to bind Company accordingly.
12  *
13  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
14  ********************************************************************************/
15
16 require_once('tests/service/SOAPTestCase.php');
17
18 /**
19  * Bug #38858
20  * set_relationships will not delete relationships via API
21  *
22  * @author mgusev@sugarcrm.com
23  * @ticked 38858
24  */
25 class Bug38858Test extends SOAPTestCase
26 {
27     /**
28      * @var Account
29      */
30     protected $account = null;
31
32     /**
33      * @var Contact
34      */
35     protected $contact = null;
36
37     public function setUp()
38     {
39         SugarTestHelper::setUp('beanFiles');
40         SugarTestHelper::setUp('beanList');
41         SugarTestHelper::setUp('current_user');
42
43         $this->_soapURL = $GLOBALS['sugar_config']['site_url'] . '/service/v4_1/soap.php';
44         parent::_setupTestUser();
45         parent::setUp();
46
47         $this->account = SugarTestAccountUtilities::createAccount();
48         $this->contact = SugarTestContactUtilities::createContact();
49
50         $this->account->load_relationship('contacts');
51         $this->account->contacts->add($this->contact->id);
52     }
53
54     public function tearDown()
55     {
56         SugarTestAccountUtilities::removeAllCreatedAccounts();
57         SugarTestContactUtilities::removeAllCreatedContacts();
58
59         parent::tearDown();
60         parent::_tearDownTestUser();
61
62         SugarTestHelper::tearDown();
63     }
64
65     /**
66      * Test checks that relationship between account & contact can be removed by soap
67      * 
68      * @group 38858
69      * @return void
70      */
71     public function testDeletionBySetRelationships()
72     {
73         $this->_login();
74
75         $result = $this->_soapClient->call('get_relationships', array(
76                 'session' => $this->_sessionId,
77                 'module_name' => 'Accounts',
78                 'module_id' => $this->account->id,
79                 'link_field_name' => 'contacts',
80                 'related_module_query' => "",
81                 'link_module_fields' => array('id'),
82                 'deleted' => '1',
83         ));
84         $this->assertEquals(1, count($result['entry_list']), 'Response is incorrect');
85
86         $contact = reset($result['entry_list']);
87         $this->assertEquals($this->contact->id, $contact['id'], 'Contact is incorrect');
88
89         $result = $this->_soapClient->call('set_relationship', array(
90             'session' => $this->_sessionId,
91             'module_name' => $this->account->module_dir,
92             'module_id' => $this->account->id,
93             'link_field_name' => 'contacts',
94             'related_ids' => array($this->contact->id),
95             'name_value_list' => array(),
96             'delete' => 1
97         ));
98         $this->assertEquals(1, $result['deleted'], 'Contact is not deleted');
99
100         $result = $this->_soapClient->call('get_relationships', array(
101             'session' => $this->_sessionId,
102             'module_name' => 'Accounts',
103             'module_id' => $this->account->id,
104             'link_field_name' => 'contacts',
105             'related_module_query' => "",
106             'link_module_fields' => array('id'),
107             'deleted' => '1',
108         ));
109
110         $this->assertEquals(0, count($result['entry_list']), 'Contact is present');
111     }
112 }