1+ <?php
2+
3+ namespace Intercom ;
4+
5+ class ConversationTest extends IntercomTestCase
6+ {
7+ public function testGetMessage ()
8+ {
9+ $ this ->setMockResponse ($ this ->client , 'Conversation/Message.txt ' );
10+ $ response = $ this ->client ->createMessage ([
11+ 'message_type ' => 'email ' ,
12+ 'subject ' => 'Hey ' ,
13+ 'body ' => 'An important message ' ,
14+ 'from ' => [
15+ 'type ' => 'admin ' ,
16+ 'id ' => '25 '
17+ ],
18+ 'to ' => [
19+ 'type ' => 'user ' ,
20+ 'id ' => '536e564f316c83104c000020 '
21+ ]
22+ ]);
23+
24+ $ this ->assertBasicAuth ('my-app ' , '1234 ' );
25+ $ this ->assertRequest ('POST ' , '/messages ' );
26+
27+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
28+ $ this ->
assertEquals (
'[email protected] ' ,
$ response[
'owner ' ][
'email ' ]);
29+ $ this ->assertEquals ('An important message ' , $ response ['body ' ]);
30+ }
31+
32+ public function testGetConversation ()
33+ {
34+ $ this ->setMockResponse ($ this ->client , 'Conversation/Conversation.txt ' );
35+ $ response = $ this ->client ->getConversation (['id ' => '123456 ' ]);
36+
37+ $ this ->assertRequest ('GET ' , '/conversations/123456 ' );
38+
39+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
40+ $ this ->assertEquals ('25 ' , $ response ['conversation_message ' ]['author ' ]['id ' ]);
41+ $ this ->assertEquals (true , $ response ['open ' ]);
42+ }
43+
44+ public function testGetConversations ()
45+ {
46+ $ this ->setMockResponse ($ this ->client , 'Conversation/ConversationList.txt ' );
47+ $ response = $ this ->client ->getConversations ();
48+ $ conversations = $ response ->get ('conversations ' );
49+
50+ $ this ->assertRequest ('GET ' , '/conversations?type=user ' );
51+
52+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
53+ $ this ->assertEquals (1 , count ($ conversations ));
54+ $ this ->assertEquals (1400850973 , $ conversations ['0 ' ]['created_at ' ]);
55+ $ this ->assertEquals ('536e564f316c83104c000020 ' , $ conversations ['0 ' ]['user ' ]['id ' ]);
56+ $ this ->assertEquals ('admin ' , $ conversations ['0 ' ]['assignee ' ]['type ' ]);
57+ }
58+
59+ public function testReplyToConversation ()
60+ {
61+ $ this ->setMockResponse ($ this ->client , 'Conversation/Conversation.txt ' );
62+ $ this ->client ->replyToConversation (['id ' => '123456 ' ]);
63+
64+ $ this ->assertRequest ('POST ' , '/conversations/123456/reply?type=json ' );
65+ }
66+
67+ public function testMarkConversationAsRead ()
68+ {
69+ $ this ->setMockResponse ($ this ->client , 'Conversation/Conversation.txt ' );
70+ $ this ->client ->markConversationAsRead (['id ' => '123456 ' , 'read ' => true ]);
71+
72+ $ this ->assertRequest ('PUT ' , '/conversations/123456 ' );
73+ }
74+
75+ /**
76+ * @expectedException \Guzzle\Service\Exception\ValidationException
77+ */
78+ public function testGetConversationNoID ()
79+ {
80+ $ this ->client ->getConversation ();
81+ }
82+
83+ /**
84+ * @expectedException \Guzzle\Service\Exception\ValidationException
85+ */
86+ public function testReplyConversationNoID ()
87+ {
88+ $ this ->client ->replyToConversation ();
89+ }
90+
91+ /**
92+ * @expectedException \Guzzle\Service\Exception\ValidationException
93+ */
94+ public function testMarkConversationAsReadNoID ()
95+ {
96+ $ this ->client ->markConversationAsRead ();
97+ }
98+ }
0 commit comments