forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request parse-community#198 from phelipealves/master
Add class ParseApp
- Loading branch information
Showing
4 changed files
with
269 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
namespace Parse; | ||
|
||
class ParseApp | ||
{ | ||
public static $APP_NAME = 'appName'; | ||
public static $CLIENT_CLASS_CREATION_ENABLED = 'clientClassCreationEnabled'; | ||
public static $CLIENT_PUSH_ENABLED = 'clientPushEnabled'; | ||
public static $REQUIRE_REVOCABLE_SESSION = 'requireRevocableSessions'; | ||
public static $REVOKE_SESSION_ON_PASSWORD_CHANGE = 'revokeSessionOnPasswordChange'; | ||
|
||
/** | ||
* To fetch the keys and settings for all of the apps that you are a collaborator on. | ||
* | ||
* @throws ParseException | ||
* | ||
* @return array Containing the keys and settings for your apps. | ||
*/ | ||
public static function fetchApps() | ||
{ | ||
$result = ParseClient::_request( | ||
'GET', | ||
'apps', | ||
null, | ||
null, | ||
false, | ||
true | ||
); | ||
|
||
return $result['results']; | ||
} | ||
|
||
/** | ||
* To fetch the keys and settings of a single app. | ||
* | ||
* @param string $application_id | ||
* | ||
* @throws ParseException | ||
* | ||
* @return array Containing the keys and settings for your app. | ||
*/ | ||
public static function fetchApp($application_id) | ||
{ | ||
$result = ParseClient::_request( | ||
'GET', | ||
'apps/'.$application_id, | ||
null, | ||
null, | ||
false, | ||
true | ||
); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Create a new app, that is owned by your account. The only required field for creating an app is the app name. | ||
* | ||
* @param array $data | ||
* | ||
* @throws ParseException | ||
* | ||
* @return array | ||
*/ | ||
public static function createApp(array $data) | ||
{ | ||
$result = ParseClient::_request( | ||
'POST', | ||
'apps', | ||
null, | ||
json_encode($data), | ||
false, | ||
true | ||
); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* You can change your app's name, as well as change your app's settings. | ||
* | ||
* @param string $application_id | ||
* @param array $data | ||
* | ||
* @throws ParseException | ||
* | ||
* @return array | ||
*/ | ||
public static function updateApp($application_id, array $data) | ||
{ | ||
$result = ParseClient::_request( | ||
'PUT', | ||
'apps/'.$application_id, | ||
null, | ||
json_encode($data), | ||
false, | ||
true | ||
); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Parse\Test; | ||
|
||
use Parse\ParseApp; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class ParseAppTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public static function setUpBeforeClass() | ||
{ | ||
Helper::setUp(); | ||
} | ||
|
||
public function testFetchingApps() | ||
{ | ||
self::_createApp(self::_getNewName()); | ||
self::_createApp(self::_getNewName()); | ||
|
||
$apps = ParseApp::fetchApps(); | ||
$this->assertGreaterThanOrEqual(2, $apps); | ||
} | ||
|
||
public function testFetchSingleApp() | ||
{ | ||
$app_created = self::_createApp(self::_getNewName()); | ||
|
||
$app = ParseApp::fetchApp($app_created['applicationId']); | ||
|
||
$this->assertCount(13, $app); | ||
} | ||
|
||
public function testFetchNotFound() | ||
{ | ||
$invalid_application_id = '1YkU7V110nEDUqU7ctCEbLr6xcgQgdEkePuBaw6P'; | ||
|
||
$this->setExpectedException('Parse\ParseException', 'requested resource was not found'); | ||
ParseApp::fetchApp($invalid_application_id); | ||
} | ||
|
||
public function testCreateApp() | ||
{ | ||
$app_name = self::_getNewName(); | ||
|
||
$app = ParseApp::createApp([ | ||
'appName' => $app_name, | ||
]); | ||
|
||
$this->assertEquals($app_name, $app['appName']); | ||
$this->assertEquals(true, $app['clientClassCreationEnabled']); | ||
$this->assertEquals(false, $app['clientPushEnabled']); | ||
$this->assertEquals(true, $app['requireRevocableSessions']); | ||
$this->assertEquals(true, $app['revokeSessionOnPasswordChange']); | ||
} | ||
|
||
public function testNameAlreadyInAccount() | ||
{ | ||
$app_name = self::_getNewName(); | ||
|
||
ParseApp::createApp([ | ||
'appName' => $app_name, | ||
]); | ||
|
||
$this->setExpectedException('Parse\ParseException', 'App name must not already be used in your account'); | ||
ParseApp::createApp([ | ||
'appName' => $app_name, | ||
]); | ||
} | ||
|
||
public function testUpdateApp() | ||
{ | ||
$app_name = self::_getNewName(); | ||
$updated_name = self::_getNewName(); | ||
$this->assertNotEquals($app_name, $updated_name); | ||
|
||
$app = ParseApp::createApp([ | ||
'appName' => $app_name, | ||
]); | ||
|
||
$updated_app = ParseApp::updateApp($app['applicationId'], [ | ||
'appName' => $updated_name, | ||
'clientClassCreationEnabled' => false, | ||
'clientPushEnabled' => true, | ||
'requireRevocableSessions' => false, | ||
'revokeSessionOnPasswordChange' => false, | ||
]); | ||
|
||
$this->assertEquals($updated_name, $updated_app['appName']); | ||
$this->assertNotTrue($updated_name['clientClassCreationEnabled']); | ||
$this->assertNotFalse($updated_name['clientPushEnabled']); | ||
$this->assertNotTrue($updated_name['requireRevocableSessions']); | ||
$this->assertNotTrue($updated_name['revokeSessionOnPasswordChange']); | ||
} | ||
|
||
private static function _createApp($name) | ||
{ | ||
return ParseApp::createApp([ | ||
'appName' => $name, | ||
]); | ||
} | ||
|
||
private static function _getNewName() | ||
{ | ||
return md5(uniqid(rand(), true)); | ||
} | ||
} |