Skip to content
Snippets Groups Projects
Select Git revision
  • 966d6b76749fe4f8dbd2312520d7ad5b292650f5
  • master default protected
  • 5.x
  • ll-php8-bs5
  • release_5_bs5
  • ll-php8
  • 4.x
  • laminas_migration
  • release_1.0.0.2
  • release_4.0.0
  • release_3.2.8
  • bootstrap4_migration
  • 1.0.0.3
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.1.1
  • 6.0.0
  • 5.1.0
  • 5.0.0
  • 4.0.2
  • 3.2.11
  • 4.0.1
  • 3.2.10
  • 4.0.0
  • 1.0.0.2
  • 3.2.9
  • 3.2.8
32 results

UserAbstractTest.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());
        }
    }