Merge pull request #14840 from MegaphoneJon/core-1130
[civicrm-core.git] / tests / phpunit / CRM / Event / BAO / QueryTest.php
CommitLineData
98a9c88c
PF
1<?php
2
3/**
4 * @group headless
5 */
6class CRM_Event_BAO_QueryTest extends CiviUnitTestCase {
7
8 public function setUp() {
9 parent::setUp();
10 }
11
12 public function testParticipantNote() {
13 $event = $this->eventCreate();
14 $this->individualCreate([
15 'api.participant.create' => [
16 'event_id' => $event['id'],
17 'note' => 'some_note',
39b959db 18 ],
98a9c88c
PF
19 ]);
20 $this->individualCreate([
21 'api.participant.create' => [
22 'event_id' => $event['id'],
23 'note' => 'some_other_note',
39b959db 24 ],
98a9c88c
PF
25 ]);
26 $params = [
27 [
28 0 => 'participant_note',
29 1 => '=',
30 2 => 'some_note',
31 3 => 1,
32 4 => 0,
39b959db 33 ],
98a9c88c
PF
34 ];
35
36 $query = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS);
37 $sql = $query->query(FALSE);
38 $result = CRM_Core_DAO::executeQuery(implode(' ', $sql));
39 $this->assertEquals(1, $result->N);
40 }
41
e4bee5e7
PN
42 /**
43 * Unit test to check if participant search retrieves correct event type id.
44 *
45 */
46 public function testEventType() {
47 $event = $this->eventCreate();
48 $contactId = $this->individualCreate([
49 'api.participant.create' => [
50 'event_id' => $event['id'],
51 ],
52 ]);
53 $params = [
54 [
55 0 => 'event_id',
56 1 => '=',
57 2 => $event['id'],
58 3 => 1,
59 4 => 0,
60 ],
61 ];
62
63 $returnProperties = [
64 'event_type_id' => 1,
65 'contact_id' => 1,
66 'event_id' => 1,
67 ];
68
69 $query = new CRM_Contact_BAO_Query(
70 $params, $returnProperties, NULL,
71 FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT
72 );
73 $sql = $query->query(FALSE);
74 $result = CRM_Core_DAO::executeQuery(implode(' ', $sql));
75
76 $this->assertEquals(1, $result->N);
77 $result->fetch();
78
79 $this->assertEquals($contactId, $result->contact_id);
80 $this->assertEquals($event['id'], $result->event_id);
81 $eventTypeId = $this->callAPISuccessGetValue('Event', [
82 'id' => $event['id'],
83 'return' => 'event_type_id',
84 ]);
85 $this->assertEquals($eventTypeId, $result->event_type_id);
86 }
87
98a9c88c 88}