Commit 8a956b26 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Aide de vue AppConnection : tests unitaires.

parent 0f3ff9e4
......@@ -4,11 +4,6 @@ namespace UnicaenAuth\View\Helper;
/**
* Aide de vue générant le lien et les infos concernant la connexion à l'application.
*
* En l'occurence, cette aide de vue ne génère rien car une application n'utilisant
* que le module UnicaenApp ne fournit rien permettant à l'utilisateur de se connecter.
*
* Cette aide de vue existe simplement dans le but d'être surchargée par le module UnicaenAuth.
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class AppConnection extends \UnicaenApp\View\Helper\AppConnection
......@@ -23,14 +18,13 @@ class AppConnection extends \UnicaenApp\View\Helper\AppConnection
{
$connexion = array();
if (($tmp = $this->getView()->userCurrent())) {
if (($tmp = $this->getView()->getPlugin('userCurrent'))) {
$connexion[] = "" . $tmp;
}
if (($tmp = $this->getView()->userConnection())) {
if (($tmp = $this->getView()->getPlugin('userConnection'))) {
$connexion[] = "" . $tmp;
}
return implode(' | ', $connexion);
}
}
\ No newline at end of file
<?php
namespace UnicaenAuthTest\View\Helper;
use UnicaenAppTest\View\Helper\AbstractTest;
use UnicaenAuth\View\Helper\AppConnection;
/**
* Description of AppConnectionTest
*
* @property AppConnection $helper Description
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class AppConnectionTest extends AbstractTest
{
protected $helperClass = 'UnicaenAuth\View\Helper\AppConnection';
protected $renderer;
protected $userCurrentHelper;
protected $userConnectionHelper;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
$this->renderer = $this->getMock('Zend\View\Renderer\PhpRenderer', array('getPlugin'));
$this->helper->setView($this->renderer);
}
protected function getUserCurrentHelper()
{
if (null === $this->userCurrentHelper) {
$this->userCurrentHelper = $this->getMock('UnicaenAuth\View\Helper\UserCurrent', array('__toString'));
$this->userCurrentHelper
->expects($this->any())
->method('__toString')
->will($this->returnValue('UserCurrent markup'));
}
return $this->userCurrentHelper;
}
protected function getUserConnectionHelper()
{
if (null === $this->userConnectionHelper) {
$this->userConnectionHelper = $this->getMock('UnicaenAuth\View\Helper\UserConnection', array('__toString'));
$this->userConnectionHelper
->expects($this->any())
->method('__toString')
->will($this->returnValue('UserConnection markup'));
}
return $this->userConnectionHelper;
}
public function getHelpersAndExpectedResult()
{
return array(
array(
null,
null,
''),
array(
null,
$this->getUserConnectionHelper(),
'UserConnection markup'),
array(
$this->getUserCurrentHelper(),
null,
'UserCurrent markup'),
array(
$this->getUserCurrentHelper(),
$this->getUserConnectionHelper(),
"UserCurrent markup | UserConnection markup"),
);
}
/**
* @dataProvider getHelpersAndExpectedResult
*/
public function testToStringMethodReturnsCorrectMarkup($userCurrentHelper, $userConnectionHelper, $expectedMarkup)
{
$this->renderer
->expects($this->any())
->method('getPlugin')
->will($this->returnCallback(function ($plugin) use ($userCurrentHelper, $userConnectionHelper) {
if ('usercurrent' === strtolower($plugin)) {
return $userCurrentHelper;
}
if ('userconnection' === strtolower($plugin)) {
return $userConnectionHelper;
}
return null;
}));
$this->assertEquals($expectedMarkup, (string) $this->helper);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment