1+ <?php
2+
3+ namespace Intercom ;
4+
5+ class NoteTest extends IntercomTestCase
6+ {
7+ public function testGetNote ()
8+ {
9+ $ this ->setMockResponse ($ this ->client , 'Note/Note.txt ' );
10+ $ response = $ this ->client ->getNote (['id ' => '123456 ' ]);
11+
12+ $ this ->assertBasicAuth ('my-app ' , '1234 ' );
13+ $ this ->assertRequest ('GET ' , '/notes/123456 ' );
14+
15+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
16+ $ this ->assertEquals ('Jayne Cobb ' , $ response ['author ' ]['name ' ]);
17+ }
18+
19+ public function testGetNotesForUserByID ()
20+ {
21+ $ this ->setMockResponse ($ this ->client , 'Note/NoteList.txt ' );
22+ $ response = $ this ->client ->getNotesForUser (['id ' => '1234 ' ]);
23+ $ notes = $ response ->get ('notes ' );
24+
25+ $ this ->assertRequest ('GET ' , '/notes?id=1234 ' );
26+
27+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
28+ $ this ->assertEquals (2 , count ($ notes ));
29+ $ this ->assertEquals ('Jayne Cobb ' , $ notes ['0 ' ]['author ' ]['name ' ]);
30+ $ this ->assertEquals ('<p>Text for my note</p> ' , $ notes ['1 ' ]['body ' ]);
31+ }
32+
33+ public function testGetNotesForUserByUserID ()
34+ {
35+ $ this ->setMockResponse ($ this ->client , 'Note/NoteList.txt ' );
36+ $ this ->client ->getNotesForUser (['user_id ' => 'aabb ' ]);
37+
38+ $ this ->assertRequest ('GET ' , '/notes?user_id=aabb ' );
39+ }
40+
41+ public function testGetNotesForUserByEmail ()
42+ {
43+ $ this ->setMockResponse ($ this ->client , 'Note/NoteList.txt ' );
44+ $ this ->
client ->
getNotesForUser ([
'email ' =>
'[email protected] ' ]);
45+
46+ $ this ->assertRequest ('GET ' , '/notes?email=bob%40example.org ' );
47+ }
48+
49+ public function testCreateNote ()
50+ {
51+ $ this ->setMockResponse ($ this ->client , 'Note/Note.txt ' );
52+ $ this ->
client ->
createNote ([
'admin_id ' =>
'6 ' ,
'user ' => [
'email ' =>
'[email protected] ' ],
'body ' =>
'Hi ' ]);
53+
54+ $ this ->assertRequest ('POST ' , '/notes ' );
55+ $ this ->
assertRequestJson ([
'admin_id ' =>
'6 ' ,
'user ' => [
'email ' =>
'[email protected] ' ],
'body ' =>
'Hi ' ]);
56+ }
57+
58+ /**
59+ * @expectedException \Guzzle\Service\Exception\ValidationException
60+ */
61+ public function testGetNoteNoID ()
62+ {
63+ $ this ->client ->getNote ();
64+ }
65+
66+ /**
67+ * @expectedException \Guzzle\Service\Exception\ValidationException
68+ */
69+ public function testCreateNoteNoArguments ()
70+ {
71+ $ this ->client ->getNote ();
72+ }
73+
74+ /**
75+ * @expectedException \Guzzle\Service\Exception\ValidationException
76+ */
77+ public function testCreateNoteNoAdminID ()
78+ {
79+ $ this ->
client ->
getNote ([
'user ' => [
'email ' =>
'[email protected] ' ],
'body ' =>
'Hi ' ]);
80+ }
81+
82+ /**
83+ * @expectedException \Guzzle\Service\Exception\ValidationException
84+ */
85+ public function testCreateNoteNoUser ()
86+ {
87+ $ this ->client ->getNote (['admin_id ' => '6 ' , 'body ' => 'Hi ' ]);
88+ }
89+
90+ /**
91+ * @expectedException \Guzzle\Service\Exception\ValidationException
92+ */
93+ public function testCreateNoteNoBody ()
94+ {
95+ $ this ->
client ->
getNote ([
'admin_id ' =>
'6 ' ,
'user ' => [
'email ' =>
'[email protected] ' ]]);
96+ }
97+ }
0 commit comments