Skip to content

Commit

Permalink
Merge branch 'hotfix/2.0.6' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Aug 13, 2014
2 parents 79ad243 + 35519af commit 709361c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/AuthBucket/OAuth2/Controller/ModelController.php
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\Validator\ValidatorInterface;

/**
* OAuth2 model endpocontroller implementation.
* OAuth2 model endpoint controller implementation.
*
* @author Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
*/
Expand Down
134 changes: 80 additions & 54 deletions tests/src/AuthBucket/OAuth2/Tests/Controller/ModelControllerTest.php
Expand Up @@ -18,142 +18,168 @@ class ModelControllerTest extends WebTestCase
{
public function testCreateModelJson()
{
$content = $this->app['serializer']->encode(array('scope' => 'demoscopeJson'), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.json', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.json', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals('demoscopeJson', $response['scope']);
$this->assertEquals($username, $response['username']);
}

public function testCreateModelXml()
{
$content = $this->app['serializer']->encode(array('scope' => 'demoscopeXml'), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.xml', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.xml', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals('demoscopeXml', $response['scope']);
$this->assertEquals($username, $response['username']);
}

public function testReadModelJson()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/oauth2/model/scope/1.json');
$crawler = $client->request('GET', '/oauth2/model/user/1.json');
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals('debug', $response['scope']);
$this->assertEquals('demousername1', $response['username']);
}

public function testReadModelXml()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/oauth2/model/scope/1.xml');
$crawler = $client->request('GET', '/oauth2/model/user/1.xml');
$response = simplexml_load_string($client->getResponse()->getContent());
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals('debug', $response['scope']);
$this->assertEquals('demousername1', $response['username']);
}

public function testUpdateModelJson()
{
$scope = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scope), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.json', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.json', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$id = $response['id'];
$scopeUpdated = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scopeUpdated), 'json');
$usernameUpdated = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('username' => $usernameUpdated), 'json');
$client = $this->createClient();
$crawler = $client->request('PUT', "/oauth2/model/scope/${id}.json", array(), array(), array(), $content);
$crawler = $client->request('PUT', "/oauth2/model/user/${id}.json", array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals($scopeUpdated, $response['scope']);
$this->assertEquals($usernameUpdated, $response['username']);

$client = $this->createClient();
$crawler = $client->request('GET', "/oauth2/model/scope/${id}.json");
$crawler = $client->request('GET', "/oauth2/model/user/${id}.json");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals($scopeUpdated, $response['scope']);
$this->assertEquals($usernameUpdated, $response['username']);
}

public function testUpdateModelXml()
{
$scope = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scope), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.xml', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.xml', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$id = $response['id'];
$scopeUpdated = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scopeUpdated), 'xml');
$usernameUpdated = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('username' => $usernameUpdated), 'xml');
$client = $this->createClient();
$crawler = $client->request('PUT', "/oauth2/model/scope/${id}.xml", array(), array(), array(), $content);
$crawler = $client->request('PUT', "/oauth2/model/user/${id}.xml", array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals($scopeUpdated, $response['scope']);
$this->assertEquals($usernameUpdated, $response['username']);

$client = $this->createClient();
$crawler = $client->request('GET', "/oauth2/model/scope/${id}.xml");
$crawler = $client->request('GET', "/oauth2/model/user/${id}.xml");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals($scopeUpdated, $response['scope']);
$this->assertEquals($usernameUpdated, $response['username']);
}

public function testDeleteModelJson()
{
$scope = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scope), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.json', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'json');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.json', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$id = $response['id'];
$client = $this->createClient();
$crawler = $client->request('DELETE', "/oauth2/model/scope/${id}.json");
$crawler = $client->request('DELETE', "/oauth2/model/user/${id}.json");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals(null, $response['id']);
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$client = $this->createClient();
$crawler = $client->request('GET', "/oauth2/model/scope/${id}.json");
$crawler = $client->request('GET', "/oauth2/model/user/${id}.json");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals(null, $response);
}

public function testDeleteModelXml()
{
$scope = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array('scope' => $scope), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/scope.xml', array(), array(), array(), $content);
$username = substr(md5(uniqid(null, true)), 0, 8);
$password = substr(md5(uniqid(null, true)), 0, 8);
$content = $this->app['serializer']->encode(array(
'username' => $username,
'password' => $password,
), 'xml');
$client = $this->createClient();
$crawler = $client->request('POST', '/oauth2/model/user.xml', array(), array(), array(), $content);
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$id = $response['id'];
$client = $this->createClient();
$crawler = $client->request('DELETE', "/oauth2/model/scope/${id}.xml");
$crawler = $client->request('DELETE', "/oauth2/model/user/${id}.xml");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals(null, $response['id']);
$this->assertEquals($scope, $response['scope']);
$this->assertEquals($username, $response['username']);

$client = $this->createClient();
$crawler = $client->request('GET', "/oauth2/model/scope/${id}.xml");
$crawler = $client->request('GET', "/oauth2/model/user/${id}.xml");
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals(null, $response);
}

public function testListModelJson()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/oauth2/model/scope.json');
$crawler = $client->request('GET', '/oauth2/model/user.json');
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'json');
$this->assertEquals('debug', $response[0]['scope']);
$this->assertEquals('demousername1', $response[0]['username']);
}

public function testListModelXml()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/oauth2/model/scope.xml');
$crawler = $client->request('GET', '/oauth2/model/user.xml');
$response = $this->app['serializer']->decode($client->getResponse()->getContent(), 'xml');
$this->assertEquals('debug', $response[0]['scope']);
$this->assertEquals('demousername1', $response[0]['username']);
}
}

0 comments on commit 709361c

Please sign in to comment.