1+ <?php
2+
3+ namespace Intercom ;
4+
5+ class TagTest extends IntercomTestCase
6+ {
7+
8+ public function testCreateTag ()
9+ {
10+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
11+ $ response = $ this ->client ->createTag (['does_not_exist ' => true ,'name ' => 'New ' ]);
12+
13+ $ this ->assertRequest ('POST ' , '/tags ' );
14+ $ this ->assertRequestJson (['name ' => 'New ' ]);
15+
16+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
17+ $ this ->assertEquals ('independent ' , $ response ['name ' ]);
18+ }
19+
20+ public function testUpdateTag ()
21+ {
22+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
23+ $ response = $ this ->client ->updateTag (['id ' => '123456 ' , 'name ' => 'New ' , 'hi ' => 'hello ' ]);
24+
25+ $ this ->assertRequest ('POST ' , '/tags ' );
26+ $ this ->assertRequestJson (['id ' => '123456 ' , 'name ' => 'New ' ]);
27+
28+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
29+ $ this ->assertEquals ('independent ' , $ response ['name ' ]);
30+ }
31+
32+ public function testGetTags ()
33+ {
34+ $ this ->setMockResponse ($ this ->client , 'Tag/TagList.txt ' );
35+ $ response = $ this ->client ->getTags ();
36+ $ tags = $ response ->get ('tags ' );
37+
38+ $ this ->assertRequest ('GET ' , '/tags ' );
39+
40+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
41+ $ this ->assertEquals (3 , count ($ tags ));
42+ $ this ->assertEquals ('Beta User ' , $ tags ['0 ' ]['name ' ]);
43+ $ this ->assertEquals ('Amazing User ' , $ tags ['1 ' ]['name ' ]);
44+ $ this ->assertEquals ('Epic User ' , $ tags ['2 ' ]['name ' ]);
45+ }
46+
47+ public function testTagUsers ()
48+ {
49+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
50+ $ this ->
client ->
tagUsers ([
'name ' =>
'independent ' ,
'users ' => [[
'id ' =>
'12 ' ], [
'email ' =>
'[email protected] ' ]]]);
51+
52+ $ this ->assertRequest ('POST ' , '/tags ' );
53+ $ this ->
assertRequestJson ([
'name ' =>
'independent ' ,
'users ' => [[
'id ' =>
'12 ' ], [
'email ' =>
'[email protected] ' ]]]);
54+ }
55+
56+ public function testUntagUsers ()
57+ {
58+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
59+ $ this ->client ->tagUsers (['name ' => 'independent ' , 'users ' => [['id ' => '12 ' , 'untag ' => true ]]]);
60+
61+ $ this ->assertRequest ('POST ' , '/tags ' );
62+ $ this ->assertRequestJson (['name ' => 'independent ' , 'users ' => [['id ' => '12 ' , 'untag ' => true ]]]);
63+ }
64+
65+ public function testTagCompanies ()
66+ {
67+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
68+ $ this ->client ->tagCompanies (['name ' => 'independent ' , 'companies ' => [['id ' => '20 ' ]]]);
69+
70+ $ this ->assertRequest ('POST ' , '/tags ' );
71+ $ this ->assertRequestJson (['name ' => 'independent ' , 'companies ' => [['id ' => '20 ' ]]]);
72+ }
73+
74+ public function testUntagCompanies ()
75+ {
76+ $ this ->setMockResponse ($ this ->client , 'Tag/Tag.txt ' );
77+ $ this ->client ->tagCompanies (['name ' => 'independent ' , 'companies ' => [['id ' => '20 ' , 'untag ' => true ]]]);
78+
79+ $ this ->assertRequest ('POST ' , '/tags ' );
80+ $ this ->assertRequestJson (['name ' => 'independent ' , 'companies ' => [['id ' => '20 ' , 'untag ' => true ]]]);
81+ }
82+
83+ /**
84+ * @expectedException \Guzzle\Service\Exception\ValidationException
85+ */
86+ public function testCreateTagNoName ()
87+ {
88+ $ this ->client ->createTag ();
89+ }
90+
91+ /**
92+ * @expectedException \Guzzle\Service\Exception\ValidationException
93+ */
94+ public function testUpdateTagNoID ()
95+ {
96+ $ this ->client ->updateTag (['name ' => 'New ' ]);
97+ }
98+
99+ /**
100+ * @expectedException \Guzzle\Service\Exception\ValidationException
101+ */
102+ public function testUpdateTagNoName ()
103+ {
104+ $ this ->client ->updateTag (['id ' => '123456 ' ]);
105+ }
106+ }
0 commit comments