2020-05-22 13:20:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Shaarli\Front\Controller\Admin;
|
|
|
|
|
|
|
|
use Shaarli\Container\ShaarliTestContainer;
|
|
|
|
use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper;
|
2020-05-30 14:00:06 +02:00
|
|
|
use Shaarli\History;
|
2020-05-22 13:20:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trait FrontControllerMockHelper
|
|
|
|
*
|
|
|
|
* Helper trait used to initialize the ShaarliContainer and mock its services for admin controller tests.
|
|
|
|
*
|
|
|
|
* @property ShaarliTestContainer $container
|
|
|
|
*/
|
|
|
|
trait FrontAdminControllerMockHelper
|
|
|
|
{
|
|
|
|
use FrontControllerMockHelper {
|
|
|
|
FrontControllerMockHelper::createContainer as parentCreateContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mock the container instance
|
|
|
|
*/
|
|
|
|
protected function createContainer(): void
|
|
|
|
{
|
|
|
|
$this->parentCreateContainer();
|
|
|
|
|
2020-05-30 14:00:06 +02:00
|
|
|
$this->container->history = $this->createMock(History::class);
|
|
|
|
|
2020-05-22 13:20:31 +02:00
|
|
|
$this->container->loginManager->method('isLoggedIn')->willReturn(true);
|
2020-05-27 13:35:48 +02:00
|
|
|
$this->container->sessionManager->method('checkToken')->willReturn(true);
|
2020-05-22 13:20:31 +02:00
|
|
|
}
|
2020-05-30 14:00:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass a reference of an array which will be populated by `sessionManager->setSessionParameter`
|
|
|
|
* calls during execution.
|
|
|
|
*
|
|
|
|
* @param mixed $variables Array reference to populate.
|
|
|
|
*/
|
|
|
|
protected function assignSessionVars(array &$variables): void
|
|
|
|
{
|
|
|
|
$this->container->sessionManager
|
|
|
|
->expects(static::atLeastOnce())
|
|
|
|
->method('setSessionParameter')
|
|
|
|
->willReturnCallback(function ($key, $value) use (&$variables) {
|
|
|
|
$variables[$key] = $value;
|
|
|
|
|
|
|
|
return $this->container->sessionManager;
|
|
|
|
})
|
|
|
|
;
|
|
|
|
}
|
2020-05-22 13:20:31 +02:00
|
|
|
}
|