1<?php 2 3declare(strict_types=1); 4 5namespace dokuwiki\plugin\today\test; 6 7use DokuWikiTest; 8use TestRequest; 9 10/** 11 * Tests for the `?do=today&namespace=foo:bar` action component of the today plugin 12 * 13 * @group plugin_today 14 * @group plugins 15 */ 16final class ActionTest extends DokuWikiTest { 17 protected $pluginsEnabled = ['today']; 18 19 public static function dataProvider(): iterable 20 { 21 yield 'no format' => [ 22 'extraParams' => [ 23 'namespace' => 'foo:bar', 24 ], 25 'expectedUrl' => '/doku.php?id=foo:bar:' . date('Y-m-d'), 26 ]; 27 28 yield 'with format' => [ 29 'extraParams' => [ 30 'namespace' => 'foo:bar', 31 'format' => 'Y:Y-m-d', 32 ], 33 'expectedUrl' => '/doku.php?id=foo:bar:' . date('Y:Y-m-d'), 34 ]; 35 36 yield 'weekly' => [ 37 'extraParams' => [ 38 'namespace' => 'journal:weekly', 39 'format' => 'Y:W', 40 ], 41 'expectedUrl' => '/doku.php?id=journal:weekly:' . date('Y:W'), 42 ]; 43 } 44 45 /** 46 * @dataProvider dataProvider 47 */ 48 public function testRedirect(array $extraParams, $expectedUrl): void 49 { 50 $request = new TestRequest(); 51 $response = $request->get( array_merge(['do' => 'today'], $extraParams) ); 52 53 $actualUrl = $response->getData('send_redirect')[0]; 54 55 $this->assertSame( $expectedUrl, $actualUrl); 56 } 57} 58