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