1+ <?php
2+
3+ namespace Intercom ;
4+
5+ class CompanyTest extends IntercomTestCase
6+ {
7+ public function testGetCompanyByID ()
8+ {
9+ $ this ->setMockResponse ($ this ->client , 'Company/Company.txt ' );
10+ $ response = $ this ->client ->getCompany (['id ' => '123456 ' ]);
11+
12+ $ this ->assertBasicAuth ('my-app ' , '1234 ' );
13+ $ this ->assertRequest ('GET ' , '/companies/123456 ' );
14+
15+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
16+ $ this ->assertEquals ('Blue Sun ' , $ response ['name ' ]);
17+ }
18+
19+ public function testGetCompanyByName ()
20+ {
21+ $ this ->setMockResponse ($ this ->client , 'Company/Company.txt ' );
22+ $ this ->client ->getCompany (['name ' => 'Blue Sun ' ]);
23+
24+ $ this ->assertRequest ('GET ' , '/companies/?name=Blue%20Sun ' );
25+ }
26+
27+ public function testGetCompanyByCompanyID ()
28+ {
29+ $ this ->setMockResponse ($ this ->client , 'Company/Company.txt ' );
30+ $ this ->client ->getCompany (['company_id ' => 'hgsdfhsasdfg ' ]);
31+
32+ $ this ->assertRequest ('GET ' , '/companies/?company_id=hgsdfhsasdfg ' );
33+ }
34+
35+ public function testCreateCompany ()
36+ {
37+ $ this ->setMockResponse ($ this ->client , 'Company/Company.txt ' );
38+ $ response = $ this ->client ->createCompany (['name ' => 'Blue Sun ' , 'company_id ' => '1234 ' ]);
39+
40+ $ this ->assertRequest ('POST ' , '/companies ' );
41+ $ this ->assertRequestJson (['company_id ' => '1234 ' , 'name ' => 'Blue Sun ' ]);
42+
43+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
44+ $ this ->assertEquals ('Blue Sun ' , $ response ['name ' ]);
45+ }
46+
47+ public function testUpdateCompany ()
48+ {
49+ $ this ->setMockResponse ($ this ->client , 'Company/Company.txt ' );
50+ $ response = $ this ->client ->updateCompany (['id ' => '123456 ' , 'company_id ' => '1234 ' , 'hi ' => 'hello ' ]);
51+
52+ $ this ->assertRequest ('POST ' , '/companies ' );
53+ $ this ->assertRequestJson (['company_id ' => '1234 ' ]);
54+
55+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
56+ $ this ->assertEquals ('Blue Sun ' , $ response ['name ' ]);
57+ }
58+
59+ public function testGetCompanies ()
60+ {
61+ $ this ->setMockResponse ($ this ->client , 'Company/CompanyList.txt ' );
62+ $ response = $ this ->client ->getCompanies ();
63+ $ companies = $ response ->get ('companies ' );
64+
65+ $ this ->assertRequest ('GET ' , '/companies ' );
66+
67+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
68+ $ this ->assertEquals (2 , count ($ companies ));
69+ $ this ->assertEquals ('Blue Sun ' , $ companies ['0 ' ]['name ' ]);
70+ $ this ->assertEquals ('Blue Moon ' , $ companies ['1 ' ]['name ' ]);
71+ }
72+
73+ public function testGetCompaniesByTagID ()
74+ {
75+ $ this ->setMockResponse ($ this ->client , 'Company/CompanyList.txt ' );
76+ $ this ->client ->getCompanies (['tag_id ' => '10 ' , 'hello ' =>'hi ' ]);
77+
78+ $ this ->assertRequest ('GET ' , '/companies?tag_id=10 ' );
79+ }
80+
81+ public function testGetCompaniesBySegmentID ()
82+ {
83+ $ this ->setMockResponse ($ this ->client , 'Company/CompanyList.txt ' );
84+ $ this ->client ->getCompanies (['segment_id ' => '20 ' , 'hello ' =>'hi ' ]);
85+
86+ $ this ->assertRequest ('GET ' , '/companies?segment_id=20 ' );
87+ }
88+
89+ public function testGetCompanyUsers ()
90+ {
91+ $ this ->setMockResponse ($ this ->client , 'User/UserList.txt ' );
92+ $ this ->client ->getCompanyUsers (['id ' => '1234 ' ]);
93+
94+ $ this ->assertRequest ('GET ' , '/companies/1234/users ' );
95+ }
96+
97+ public function testGetCompanyUsersByCompanyID ()
98+ {
99+ $ this ->setMockResponse ($ this ->client , 'User/UserList.txt ' );
100+ $ this ->client ->getCompanyUsersByCompanyID (['company_id ' => '10 ' , 'type ' => 'user ' ]);
101+
102+ $ this ->assertRequest ('GET ' , '/companies?company_id=10&type=user ' );
103+ }
104+
105+ public function testGetCompanyUsersByCompanyIDNoType ()
106+ {
107+ $ this ->setMockResponse ($ this ->client , 'User/UserList.txt ' );
108+ $ this ->client ->getCompanyUsersByCompanyID (['company_id ' => '10 ' ]);
109+
110+ $ this ->assertRequest ('GET ' , '/companies?company_id=10&type=user ' );
111+ }
112+
113+ /**
114+ * @expectedException \Guzzle\Service\Exception\ValidationException
115+ */
116+ public function testCreateCompanyNoCompanyID ()
117+ {
118+ $ this ->client ->createCompany ();
119+ }
120+
121+ /**
122+ * @expectedException \Guzzle\Service\Exception\ValidationException
123+ */
124+ public function testUpdateCompanyNoCompanyID ()
125+ {
126+ $ this ->client ->updateCompany ();
127+ }
128+ }
0 commit comments