Skip to content
Snippets Groups Projects
Select Git revision
2 results Searching

umail_pkey.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    UserAbstractTest.php 2.04 KiB
    <?php
    namespace UnicaenAuthTest\View\Helper;
    
    use PHPUnit_Framework_TestCase;
    use UnicaenAuth\View\Helper\UserAbstract;
    
    /**
     * Description of AppConnectionTest
     *
     * @property UserAbstract $helper Description
     * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
     */
    class UserAbstractTest extends PHPUnit_Framework_TestCase
    {
        protected $helper;
        protected $authService;
        
        /**
         * Sets up the fixture, for example, open a network connection.
         * This method is called before a test is executed.
         */
        protected function setUp()
        {
            $this->authService = $this->getMock('Zend\Authentication\AuthenticationService', array('hasIdentity', 'getIdentity'));
            
            $this->helper = $this->getMockForAbstractClass('UnicaenAuth\View\Helper\UserAbstract');
            $this->helper->setAuthService($this->authService);
        }
        
        public function testCanSetAuthService()
        {
            $this->assertSame($this->authService, $this->helper->getAuthService());
        }
        
        public function testGettingIdentityReturnsNullIfNoAuthServiceAvailable()
        {
            $this->helper->setAuthService(null);
            $this->assertNull($this->helper->getAuthService());
            $this->assertNull($this->helper->getIdentity());
        }
        
        public function testGettingIdentityReturnsNullIfAuthServiceHasNoIdentity()
        {
            $this->authService->expects($this->once())
                              ->method('hasIdentity')
                              ->will($this->returnValue(false));
            $this->assertNull($this->helper->getIdentity());
        }
        
        public function testGettingIdentityReturnsAuthServiceIdentity()
        {
            $this->authService->expects($this->once())
                              ->method('hasIdentity')
                              ->will($this->returnValue(true));
            $this->authService->expects($this->once())
                              ->method('getIdentity')
                              ->will($this->returnValue($identity = 'Auth Service Identity'));
            $this->assertEquals($identity, $this->helper->getIdentity());
        }
    }