aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/DailyControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/front/controller/DailyControllerTest.php')
-rw-r--r--tests/front/controller/DailyControllerTest.php84
1 files changed, 5 insertions, 79 deletions
diff --git a/tests/front/controller/DailyControllerTest.php b/tests/front/controller/DailyControllerTest.php
index 88ec116b..7ec99030 100644
--- a/tests/front/controller/DailyControllerTest.php
+++ b/tests/front/controller/DailyControllerTest.php
@@ -6,31 +6,21 @@ namespace Shaarli\Front\Controller;
6 6
7use PHPUnit\Framework\TestCase; 7use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\Bookmark; 8use Shaarli\Bookmark\Bookmark;
9use Shaarli\Bookmark\BookmarkServiceInterface;
10use Shaarli\Config\ConfigManager;
11use Shaarli\Container\ShaarliContainer;
12use Shaarli\Feed\CachedPage; 9use Shaarli\Feed\CachedPage;
13use Shaarli\Formatter\BookmarkFormatter;
14use Shaarli\Formatter\BookmarkRawFormatter;
15use Shaarli\Formatter\FormatterFactory;
16use Shaarli\Plugin\PluginManager;
17use Shaarli\Render\PageBuilder;
18use Shaarli\Render\PageCacheManager;
19use Shaarli\Security\LoginManager;
20use Slim\Http\Request; 10use Slim\Http\Request;
21use Slim\Http\Response; 11use Slim\Http\Response;
22 12
23class DailyControllerTest extends TestCase 13class DailyControllerTest extends TestCase
24{ 14{
25 /** @var ShaarliContainer */ 15 use FrontControllerMockHelper;
26 protected $container;
27 16
28 /** @var DailyController */ 17 /** @var DailyController */
29 protected $controller; 18 protected $controller;
30 19
31 public function setUp(): void 20 public function setUp(): void
32 { 21 {
33 $this->container = $this->createMock(ShaarliContainer::class); 22 $this->createContainer();
23
34 $this->controller = new DailyController($this->container); 24 $this->controller = new DailyController($this->container);
35 DailyController::$DAILY_RSS_NB_DAYS = 2; 25 DailyController::$DAILY_RSS_NB_DAYS = 2;
36 } 26 }
@@ -105,7 +95,8 @@ class DailyControllerTest extends TestCase
105 static::assertArrayHasKey('loggedin', $param); 95 static::assertArrayHasKey('loggedin', $param);
106 96
107 return $data; 97 return $data;
108 }); 98 })
99 ;
109 100
110 $result = $this->controller->index($request, $response); 101 $result = $this->controller->index($request, $response);
111 102
@@ -497,71 +488,6 @@ class DailyControllerTest extends TestCase
497 static::assertCount(0, $assignedVariables['days']); 488 static::assertCount(0, $assignedVariables['days']);
498 } 489 }
499 490
500 protected function createValidContainerMockSet(): void
501 {
502 $loginManager = $this->createMock(LoginManager::class);
503 $this->container->loginManager = $loginManager;
504
505 // Config
506 $conf = $this->createMock(ConfigManager::class);
507 $this->container->conf = $conf;
508 $this->container->conf->method('get')->willReturnCallback(function (string $parameter, $default) {
509 return $default;
510 });
511
512 // PageBuilder
513 $pageBuilder = $this->createMock(PageBuilder::class);
514 $pageBuilder
515 ->method('render')
516 ->willReturnCallback(function (string $template): string {
517 return $template;
518 })
519 ;
520 $this->container->pageBuilder = $pageBuilder;
521
522 // Plugin Manager
523 $pluginManager = $this->createMock(PluginManager::class);
524 $this->container->pluginManager = $pluginManager;
525
526 // BookmarkService
527 $bookmarkService = $this->createMock(BookmarkServiceInterface::class);
528 $this->container->bookmarkService = $bookmarkService;
529
530 // Formatter
531 $formatterFactory = $this->createMock(FormatterFactory::class);
532 $formatterFactory
533 ->method('getFormatter')
534 ->willReturnCallback(function (): BookmarkFormatter {
535 return new BookmarkRawFormatter($this->container->conf, true);
536 })
537 ;
538 $this->container->formatterFactory = $formatterFactory;
539
540 // CacheManager
541 $pageCacheManager = $this->createMock(PageCacheManager::class);
542 $this->container->pageCacheManager = $pageCacheManager;
543
544 // $_SERVER
545 $this->container->environment = [
546 'SERVER_NAME' => 'shaarli',
547 'SERVER_PORT' => '80',
548 'REQUEST_URI' => '/daily-rss',
549 ];
550 }
551
552 protected function assignTemplateVars(array &$variables): void
553 {
554 $this->container->pageBuilder
555 ->expects(static::atLeastOnce())
556 ->method('assign')
557 ->willReturnCallback(function ($key, $value) use (&$variables) {
558 $variables[$key] = $value;
559
560 return $this;
561 })
562 ;
563 }
564
565 protected static function generateContent(int $length): string 491 protected static function generateContent(int $length): string
566 { 492 {
567 // bin2hex(random_bytes) generates string twice as long as given parameter 493 // bin2hex(random_bytes) generates string twice as long as given parameter