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