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