1+ <?php
2+
3+ namespace Parse \Test ;
4+
5+
6+ use Parse \ParseException ;
7+ use Parse \ParseInstallation ;
8+
9+ class ParseInstallationTest extends \PHPUnit_Framework_TestCase
10+ {
11+ public function setUp ()
12+ {
13+ Helper::setUp ();
14+ }
15+
16+ public function tearDown ()
17+ {
18+ Helper::clearClass (ParseInstallation::$ parseClassName );
19+ }
20+
21+ /**
22+ * @group installation-tests
23+ */
24+ public function testMissingIdentifyingField ()
25+ {
26+ $ this ->setExpectedException (ParseException::class,
27+ 'at least one ID field (deviceToken, installationId) must be specified in this operation ' );
28+
29+ (new ParseInstallation ())->save ();
30+ }
31+
32+ /**
33+ * @group installation-tests
34+ */
35+ public function testMissingDeviceType ()
36+ {
37+ $ this ->setExpectedException (ParseException::class,
38+ 'deviceType must be specified in this operation ' );
39+
40+ $ installation = new ParseInstallation ();
41+ $ installation ->set ('deviceToken ' , '12345 ' );
42+ $ installation ->save ();
43+
44+ }
45+
46+ /**
47+ * @group installation-tests
48+ */
49+ public function testClientsCannotFindWithoutMasterKey ()
50+ {
51+ $ this ->setExpectedException (ParseException::class,
52+ 'Clients aren \'t allowed to perform the find operation on the installation collection. ' );
53+
54+ $ query = ParseInstallation::query ();
55+ $ query ->first ();
56+
57+ }
58+
59+ /**
60+ * @group installation-tests
61+ */
62+ public function testClientsCannotDestroyWithoutMasterKey ()
63+ {
64+ $ installation = new ParseInstallation ();
65+ $ installation ->set ('deviceToken ' , '12345 ' );
66+ $ installation ->set ('deviceType ' , 'android ' );
67+ $ installation ->save ();
68+
69+ $ this ->setExpectedException (ParseException::class,
70+ "Clients aren't allowed to perform the delete operation on the installation collection. " );
71+
72+ // try destroying, without using the master key
73+ $ installation ->destroy ();
74+
75+ }
76+
77+ /**
78+ * @group installation-tests
79+ */
80+ public function testInstallation ()
81+ {
82+ $ installationId = '12345 ' ;
83+ $ deviceToken = 'device-token ' ;
84+ $ deviceType = 'android ' ;
85+ $ channels = [
86+ 'one ' ,
87+ 'zwei ' ,
88+ 'tres '
89+ ];
90+ $ pushType = 'a-push-type ' ;
91+ $ GCMSenderId = 'gcm-sender-id ' ;
92+ $ timeZone = 'Time/Zone ' ;
93+ $ localeIdentifier = 'locale ' ;
94+ $ badge = 32 ;
95+ $ appVersion = '1.0.0 ' ;
96+ $ appName = 'Foo Bar App ' ;
97+ $ appIdentifier = 'foo-bar-app-id ' ;
98+ $ parseVersion = '1.2.3 ' ;
99+
100+ $ installation = new ParseInstallation ();
101+ $ installation ->set ('installationId ' , $ installationId );
102+ $ installation ->set ('deviceToken ' , $ deviceToken );
103+ $ installation ->setArray ('channels ' , $ channels );
104+ $ installation ->set ('deviceType ' , $ deviceType );
105+ $ installation ->set ('pushType ' , $ pushType );
106+ $ installation ->set ('GCMSenderId ' , $ GCMSenderId );
107+ $ installation ->set ('timeZone ' , $ timeZone );
108+ $ installation ->set ('localeIdentifier ' , $ localeIdentifier );
109+ $ installation ->set ('badge ' , $ badge );
110+ $ installation ->set ('appVersion ' , $ appVersion );
111+ $ installation ->set ('appName ' , $ appName );
112+ $ installation ->set ('appIdentifier ' , $ appIdentifier );
113+ $ installation ->set ('parseVersion ' , $ parseVersion );
114+
115+ $ installation ->save ();
116+
117+ // query for this installation now
118+ $ query = ParseInstallation::query ();
119+ $ inst = $ query ->first (true );
120+
121+ $ this ->assertNotNull ($ inst , 'Installation not found ' );
122+
123+ $ this ->assertEquals ($ inst ->getInstallationId (), $ installationId );
124+ $ this ->assertEquals ($ inst ->getDeviceToken (), $ deviceToken );
125+ $ this ->assertEquals ($ inst ->getChannels (), $ channels );
126+ $ this ->assertEquals ($ inst ->getDeviceType (), $ deviceType );
127+ $ this ->assertEquals ($ inst ->getPushType (), $ pushType );
128+ $ this ->assertEquals ($ inst ->getGCMSenderId (), $ GCMSenderId );
129+ $ this ->assertEquals ($ inst ->getTimeZone (), $ timeZone );
130+ $ this ->assertEquals ($ inst ->getLocaleIdentifier (), $ localeIdentifier );
131+ $ this ->assertEquals ($ inst ->getBadge (), $ badge );
132+ $ this ->assertEquals ($ inst ->getAppVersion (), $ appVersion );
133+ $ this ->assertEquals ($ inst ->getAppName (), $ appName );
134+ $ this ->assertEquals ($ inst ->getAppIdentifier (), $ appIdentifier );
135+ $ this ->assertEquals ($ inst ->getParseVersion (), $ parseVersion );
136+
137+ // cleanup
138+ $ installation ->destroy (true );
139+
140+ }
141+
142+ }
0 commit comments