-
Notifications
You must be signed in to change notification settings - Fork 6
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 #5 from zf-fr/test
Add tests
- Loading branch information
Showing
6 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
tests/ZfrOAuth2ModuleTest/Server/Controller/TokenControllerTest.php
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,68 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Controller; | ||
|
||
use Zend\Http\Request as HttpRequest; | ||
use Zend\Http\Response as HttpResponse; | ||
use ZfrOAuth2Module\Server\Controller\TokenController; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Controller\TokenController | ||
*/ | ||
class TokenControllerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDoNothingIfNotHttpRequest() | ||
{ | ||
$authorizationServer = $this->getMock('ZfrOAuth2\Server\AuthorizationServer', [], [], '', false); | ||
$controller = new TokenController($authorizationServer); | ||
|
||
$request = $this->getMock('Zend\Stdlib\RequestInterface'); | ||
|
||
$reflProperty = new \ReflectionProperty($controller, 'request'); | ||
$reflProperty->setAccessible(true); | ||
$reflProperty->setValue($controller, $request); | ||
|
||
$authorizationServer->expects($this->never())->method('handleTokenRequest'); | ||
|
||
$this->assertNull($controller->tokenAction($request)); | ||
} | ||
|
||
public function testDelegateToAuthorizationServerIfHttpRequest() | ||
{ | ||
$authorizationServer = $this->getMock('ZfrOAuth2\Server\AuthorizationServer', [], [], '', false); | ||
$controller = new TokenController($authorizationServer); | ||
|
||
$request = new HttpRequest(); | ||
$response = new HttpResponse(); | ||
|
||
$reflProperty = new \ReflectionProperty($controller, 'request'); | ||
$reflProperty->setAccessible(true); | ||
$reflProperty->setValue($controller, $request); | ||
|
||
$authorizationServer->expects($this->once()) | ||
->method('handleTokenRequest') | ||
->with($request) | ||
->will($this->returnValue($response)); | ||
|
||
$this->assertSame($response, $controller->tokenAction($request)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/ZfrOAuth2ModuleTest/Server/Factory/AccessTokenStorageFactoryTest.php
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,51 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Factory; | ||
|
||
use Zend\Http\Request as HttpRequest; | ||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrOAuth2Module\Server\Factory\AccessTokenStorageFactory; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Factory\AccessTokenStorageFactory | ||
*/ | ||
class AccessTokenStorageFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCanCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2\Server\ResourceServer', | ||
$this->getMock('ZfrOAuth2\Server\ResourceServer', [], [], '', false) | ||
); | ||
|
||
$application = $this->getMock('Zend\Mvc\ApplicationInterface'); | ||
$application->expects($this->once())->method('getRequest')->will($this->returnValue(new HttpRequest())); | ||
$serviceManager->setService('Application', $application); | ||
|
||
$factory = new AccessTokenStorageFactory(); | ||
$service = $factory->createService($serviceManager); | ||
|
||
$this->assertInstanceOf('ZfrOAuth2Module\Server\Authentication\Storage\AccessTokenStorage', $service); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/ZfrOAuth2ModuleTest/Server/Factory/GrantPluginManagerFactoryTest.php
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,53 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Factory; | ||
|
||
use Zend\Http\Request as HttpRequest; | ||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrOAuth2Module\Server\Factory\AccessTokenStorageFactory; | ||
use ZfrOAuth2Module\Server\Factory\GrantPluginManagerFactory; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Factory\GrantPluginManagerFactory | ||
*/ | ||
class GRantPluginManagerFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCanCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$serviceManager->setService( | ||
'Config', | ||
[ | ||
'zfr_oauth2_server' => [ | ||
'grant_manager' => [] | ||
] | ||
] | ||
); | ||
|
||
$factory = new GrantPluginManagerFactory(); | ||
$service = $factory->createService($serviceManager); | ||
|
||
$this->assertInstanceOf('ZfrOAuth2Module\Server\Grant\GrantPluginManager', $service); | ||
$this->assertSame($serviceManager, $service->getServiceLocator()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/ZfrOAuth2ModuleTest/Server/Factory/PasswordGrantFactoryTest.php
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,65 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Factory; | ||
|
||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrOAuth2Module\Server\Factory\PasswordGrantFactory; | ||
use ZfrOAuth2Module\Server\Factory\RefreshTokenGrantFactory; | ||
use ZfrOAuth2Module\Server\Options\ModuleOptions; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Factory\PasswordGrantFactory | ||
*/ | ||
class PasswordGrantFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCanCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$pluginManager = $this->getMock('Zend\ServiceManager\AbstractPluginManager'); | ||
$pluginManager->expects($this->once())->method('getServiceLocator')->will($this->returnValue($serviceManager)); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2Module\Server\Options\ModuleOptions', | ||
new ModuleOptions([ | ||
'owner_callable' => 'MyOwnerCallable' | ||
]) | ||
); | ||
|
||
$serviceManager->setService('MyOwnerCallable', function() {}); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2\Server\Service\AccessTokenService', | ||
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false) | ||
); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2\Server\Service\RefreshTokenService', | ||
$this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false) | ||
); | ||
|
||
$factory = new PasswordGrantFactory(); | ||
$service = $factory->createService($pluginManager); | ||
|
||
$this->assertInstanceOf('ZfrOAuth2\Server\Grant\PasswordGrant', $service); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/ZfrOAuth2ModuleTest/Server/Factory/ScopeServiceFactoryTest.php
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,56 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Factory; | ||
|
||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrOAuth2Module\Server\Factory\ClientServiceFactory; | ||
use ZfrOAuth2Module\Server\Factory\ScopeServiceFactory; | ||
use ZfrOAuth2Module\Server\Options\ModuleOptions; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Factory\ScopeServiceFactory | ||
*/ | ||
class ScopeServiceFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCanCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2Module\Server\Options\ModuleOptions', | ||
new ModuleOptions(['object_manager' => 'my_object_manager']) | ||
); | ||
|
||
$objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); | ||
$serviceManager->setService('my_object_manager', $objectManager); | ||
|
||
$objectManager->expects($this->once()) | ||
->method('getRepository') | ||
->with('ZfrOAuth2\Server\Entity\Scope') | ||
->will($this->returnValue($this->getMock('Doctrine\Common\Persistence\ObjectRepository'))); | ||
|
||
$factory = new ScopeServiceFactory(); | ||
$service = $factory->createService($serviceManager); | ||
|
||
$this->assertInstanceOf('ZfrOAuth2\Server\Service\ScopeService', $service); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/ZfrOAuth2ModuleTest/Server/Factory/TokenControllerFactoryTest.php
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,49 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrOAuth2ModuleTest\Server\Factory; | ||
|
||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrOAuth2Module\Server\Factory\TokenControllerFactory; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
* | ||
* @covers ZfrOAuth2Module\Server\Factory\TokenControllerFactory | ||
*/ | ||
class TokenControllerFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCanCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$pluginManager = $this->getMock('Zend\ServiceManager\AbstractPluginManager'); | ||
$pluginManager->expects($this->once())->method('getServiceLocator')->will($this->returnValue($serviceManager)); | ||
|
||
$serviceManager->setService( | ||
'ZfrOAuth2\Server\AuthorizationServer', | ||
$this->getMock('ZfrOAuth2\Server\AuthorizationServer', [], [], '', false) | ||
); | ||
|
||
$factory = new TokenControllerFactory(); | ||
$service = $factory->createService($pluginManager); | ||
|
||
$this->assertInstanceOf('ZfrOAuth2Module\Server\Controller\TokenController', $service); | ||
} | ||
} |