Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
3 | require_once 'CiviTest/Contact.php'; | |
4 | class CRM_Core_BAO_IMTest extends CiviUnitTestCase { | |
5 | function get_info() { | |
6 | return array( | |
7 | 'name' => 'IM BAOs', | |
8 | 'description' => 'Test all Core_BAO_IM methods.', | |
9 | 'group' => 'CiviCRM BAO Tests', | |
10 | ); | |
11 | } | |
12 | ||
13 | function setUp() { | |
14 | parent::setUp(); | |
15 | } | |
16 | ||
17 | /** | |
18 | * add() method (create and update modes) | |
19 | */ | |
20 | function testAdd() { | |
21 | $contactId = Contact::createIndividual(); | |
22 | ||
23 | $params = array(); | |
24 | $params = array( | |
25 | 'name' => 'jane.doe', | |
26 | 'provider_id' => 1, | |
27 | 'is_primary' => 1, | |
28 | 'location_type_id' => 1, | |
29 | 'contact_id' => $contactId, | |
30 | ); | |
31 | ||
32 | CRM_Core_BAO_IM::add($params); | |
33 | ||
34 | $imId = $this->assertDBNotNull('CRM_Core_DAO_IM', 'jane.doe', 'id', 'name', | |
35 | 'Database check for created IM name.' | |
36 | ); | |
37 | ||
38 | // Now call add() to modify an existing IM | |
39 | ||
40 | $params = array(); | |
41 | $params = array( | |
42 | 'id' => $imId, | |
43 | 'contact_id' => $contactId, | |
44 | 'provider_id' => 3, | |
45 | 'name' => 'doe.jane', | |
46 | ); | |
47 | ||
48 | CRM_Core_BAO_IM::add($params); | |
49 | ||
50 | $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'provider_id', 'id', 'Database check on updated IM provider_name record.'); | |
51 | $this->assertEquals($isEditIM, 3, 'Verify IM provider_id value is 3.'); | |
52 | $isEditIM = $this->assertDBNotNull('CRM_Core_DAO_IM', $imId, 'name', 'id', 'Database check on updated IM name record.'); | |
53 | $this->assertEquals($isEditIM, 'doe.jane', 'Verify IM provider_id value is doe.jane.'); | |
54 | ||
55 | Contact::delete($contactId); | |
56 | } | |
57 | ||
58 | /** | |
59 | * AllIMs() method - get all IMs for our contact, with primary IM first | |
60 | */ | |
61 | function testAllIMs() { | |
62 | $op = new PHPUnit_Extensions_Database_Operation_Insert; | |
63 | $op->execute( | |
64 | $this->_dbconn, | |
65 | new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml') | |
66 | ); | |
67 | ||
68 | $contactId = 69; | |
69 | $IMs = CRM_Core_BAO_IM::allIMs($contactId); | |
70 | ||
71 | $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.'); | |
72 | ||
73 | $firstIMValue = array_slice($IMs, 0, 1); | |
74 | ||
75 | $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.'); | |
76 | $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.'); | |
77 | ||
78 | Contact::delete($contactId); | |
79 | } | |
80 | } | |
81 | ||
82 |