aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/visitor
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-06-13 11:22:14 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit818b3193ffabec57501e3bdfa997206e3c0671ef (patch)
treef5a4d3cc23ac367dde617b849561177fc20d767a /tests/front/controller/visitor
parentc22fa57a5505fe95fd01860e3d3dfbb089f869cd (diff)
downloadShaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.gz
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.tar.zst
Shaarli-818b3193ffabec57501e3bdfa997206e3c0671ef.zip
Explicitly define base and asset path in templates
With the new routes, all pages are not all at the same folder level anymore (e.g. /shaare and /shaare/123), so we can't just use './' everywhere. The most consistent way to handle this is to prefix all path with the proper variable, and handle the actual path in controllers.
Diffstat (limited to 'tests/front/controller/visitor')
-rw-r--r--tests/front/controller/visitor/FrontControllerMockHelper.php2
-rw-r--r--tests/front/controller/visitor/ShaarliVisitorControllerTest.php (renamed from tests/front/controller/visitor/ShaarliPublicControllerTest.php)22
2 files changed, 11 insertions, 13 deletions
diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php
index fecd0c82..7f560662 100644
--- a/tests/front/controller/visitor/FrontControllerMockHelper.php
+++ b/tests/front/controller/visitor/FrontControllerMockHelper.php
@@ -81,6 +81,8 @@ trait FrontControllerMockHelper
81 'SERVER_PORT' => '80', 81 'SERVER_PORT' => '80',
82 'REQUEST_URI' => '/daily-rss', 82 'REQUEST_URI' => '/daily-rss',
83 ]; 83 ];
84
85 $this->container->basePath = '/subfolder';
84 } 86 }
85 87
86 /** 88 /**
diff --git a/tests/front/controller/visitor/ShaarliPublicControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
index 899b280b..83d08358 100644
--- a/tests/front/controller/visitor/ShaarliPublicControllerTest.php
+++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php
@@ -8,15 +8,14 @@ use PHPUnit\Framework\TestCase;
8use Shaarli\Bookmark\BookmarkFilter; 8use Shaarli\Bookmark\BookmarkFilter;
9use Slim\Http\Request; 9use Slim\Http\Request;
10use Slim\Http\Response; 10use Slim\Http\Response;
11use Slim\Http\Uri;
12 11
13/** 12/**
14 * Class ShaarliControllerTest 13 * Class ShaarliControllerTest
15 * 14 *
16 * This class is used to test default behavior of ShaarliController abstract class. 15 * This class is used to test default behavior of ShaarliVisitorController abstract class.
17 * It uses a dummy non abstract controller. 16 * It uses a dummy non abstract controller.
18 */ 17 */
19class ShaarliPublicControllerTest extends TestCase 18class ShaarliVisitorControllerTest extends TestCase
20{ 19{
21 use FrontControllerMockHelper; 20 use FrontControllerMockHelper;
22 21
@@ -49,20 +48,15 @@ class ShaarliPublicControllerTest extends TestCase
49 Request $request, 48 Request $request,
50 Response $response, 49 Response $response,
51 array $loopTerms = [], 50 array $loopTerms = [],
52 array $clearParams = [] 51 array $clearParams = [],
52 string $anchor = null
53 ): Response { 53 ): Response {
54 return parent::redirectFromReferer($request, $response, $loopTerms, $clearParams); 54 return parent::redirectFromReferer($request, $response, $loopTerms, $clearParams, $anchor);
55 } 55 }
56 }; 56 };
57 $this->assignedValues = []; 57 $this->assignedValues = [];
58 58
59 $this->request = $this->createMock(Request::class); 59 $this->request = $this->createMock(Request::class);
60 $this->request->method('getUri')->willReturnCallback(function (): Uri {
61 $uri = $this->createMock(Uri::class);
62 $uri->method('getBasePath')->willReturn('/subfolder');
63
64 return $uri;
65 });
66 } 60 }
67 61
68 public function testAssignView(): void 62 public function testAssignView(): void
@@ -102,6 +96,8 @@ class ShaarliPublicControllerTest extends TestCase
102 static::assertSame(10, $this->assignedValues['linkcount']); 96 static::assertSame(10, $this->assignedValues['linkcount']);
103 static::assertSame(5, $this->assignedValues['privateLinkcount']); 97 static::assertSame(5, $this->assignedValues['privateLinkcount']);
104 static::assertSame(['error'], $this->assignedValues['plugin_errors']); 98 static::assertSame(['error'], $this->assignedValues['plugin_errors']);
99 static::assertSame('/subfolder', $this->assignedValues['base_path']);
100 static::assertSame('/subfolder/tpl/default', $this->assignedValues['asset_path']);
105 101
106 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']); 102 static::assertSame('templateName', $this->assignedValues['plugins_includes']['render_includes']['target']);
107 static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']); 103 static::assertTrue($this->assignedValues['plugins_includes']['render_includes']['loggedin']);
@@ -153,7 +149,7 @@ class ShaarliPublicControllerTest extends TestCase
153 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'controller']); 149 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'controller']);
154 150
155 static::assertSame(302, $result->getStatusCode()); 151 static::assertSame(302, $result->getStatusCode());
156 static::assertSame(['/subfolder'], $result->getHeader('location')); 152 static::assertSame(['/subfolder/'], $result->getHeader('location'));
157 } 153 }
158 154
159 /** 155 /**
@@ -168,7 +164,7 @@ class ShaarliPublicControllerTest extends TestCase
168 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'other']); 164 $result = $this->controller->redirectFromReferer($this->request, $response, ['nope', 'other']);
169 165
170 static::assertSame(302, $result->getStatusCode()); 166 static::assertSame(302, $result->getStatusCode());
171 static::assertSame(['/subfolder'], $result->getHeader('location')); 167 static::assertSame(['/subfolder/'], $result->getHeader('location'));
172 } 168 }
173 169
174 /** 170 /**