Skip to content

Commit a5cd7ac

Browse files
author
Benjamin Wilson Friedman
authored
Add getters to ParseInstallation (#303)
* Added property getters to ParseInstallation * Added additional tests
1 parent c4f21b8 commit a5cd7ac

File tree

2 files changed

+286
-0
lines changed

2 files changed

+286
-0
lines changed

src/Parse/ParseInstallation.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,148 @@
1010
class ParseInstallation extends ParseObject
1111
{
1212
public static $parseClassName = '_Installation';
13+
14+
/**
15+
* Gets the installation id for this installation
16+
*
17+
* @return string
18+
*/
19+
public function getInstallationId()
20+
{
21+
return $this->get('installationId');
22+
23+
}
24+
25+
/**
26+
* Gets the device token for this installation
27+
*
28+
* @return string
29+
*/
30+
public function getDeviceToken()
31+
{
32+
return $this->get('deviceToken');
33+
34+
}
35+
36+
/**
37+
* Get channels for this installation
38+
*
39+
* @return array
40+
*/
41+
public function getChannels()
42+
{
43+
return $this->get('channels');
44+
45+
}
46+
47+
/**
48+
* Gets the device type of this installation
49+
*
50+
* @return string
51+
*/
52+
public function getDeviceType()
53+
{
54+
return $this->get('deviceType');
55+
56+
}
57+
58+
/**
59+
* Gets the push type of this installation
60+
*
61+
* @return string
62+
*/
63+
public function getPushType()
64+
{
65+
return $this->get('pushType');
66+
67+
}
68+
69+
/**
70+
* Gets the GCM sender id of this installation
71+
*
72+
* @return string
73+
*/
74+
public function getGCMSenderId()
75+
{
76+
return $this->get('GCMSenderId');
77+
78+
}
79+
80+
/**
81+
* Gets the time zone of this installation
82+
*
83+
* @return string
84+
*/
85+
public function getTimeZone()
86+
{
87+
return $this->get('timeZone');
88+
89+
}
90+
91+
/**
92+
* Gets the locale id for this installation
93+
*
94+
* @return string
95+
*/
96+
public function getLocaleIdentifier()
97+
{
98+
return $this->get('localeIdentifier');
99+
100+
}
101+
102+
/**
103+
* Gets the badge number of this installation
104+
*
105+
* @return int
106+
*/
107+
public function getBadge()
108+
{
109+
return $this->get('badge');
110+
111+
}
112+
113+
/**
114+
* Gets the app version of this installation
115+
*
116+
* @return string
117+
*/
118+
public function getAppVersion()
119+
{
120+
return $this->get('appVersion');
121+
122+
}
123+
124+
/**
125+
* Get the app name for this installation
126+
*
127+
* @return string
128+
*/
129+
public function getAppName()
130+
{
131+
return $this->get('appName');
132+
133+
}
134+
135+
/**
136+
* Gets the app identifier for this installation
137+
*
138+
* @return string
139+
*/
140+
public function getAppIdentifier()
141+
{
142+
return $this->get('appIdentifier');
143+
144+
}
145+
146+
/**
147+
* Gets the parse version for this installation
148+
*
149+
* @return string
150+
*/
151+
public function getParseVersion()
152+
{
153+
return $this->get('parseVersion');
154+
155+
}
156+
13157
}

tests/Parse/ParseInstallationTest.php

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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

Comments
 (0)