Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backend/design/html/campaign_edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<span>{$btr->general_open|escape}</span>
</a>
{/if}
<a class="btn btn_small btn_border-info ml-1" href="{if $smarty.get.return}{$smarty.get.return|escape}{else}{url controller=CampaignListAdmin}{/if}">
<a class="btn btn_small btn_border-info ml-1" href="{if $smarty.get.return}{$smarty.get.return|escape}{else}{url controller=[Sviat,Promo,CampaignListAdmin] id=null}{/if}">
{include file='svg_icon.tpl' svgId='return'}
<span>{$btr->general_back|escape}</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion Init/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Okay": "4.5.3",
"version": "2.2.1",
"version": "2.2.2",
"moduleName": "Promo: акції та знижки",
"vendor": {
"email": "devsviat@proton.me",
Expand Down
44 changes: 44 additions & 0 deletions tests/BackendLinksControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Modules\Sviat\Promo;

use Okay\Modules\Sviat\Promo\Backend\Controllers\CampaignListAdmin;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* {url controller=CampaignListAdmin} без вендора й модуля адмінка шукає серед контролерів
* ядра, не знаходить і віддає «Товари»: так поводилась кнопка «Назад» на картці акції,
* відкритій без ?return=.
*/
class BackendLinksControllerTest extends TestCase
{
public function testEveryLinkNamesAnExistingController(): void
{
$designDir = dirname((string) (new ReflectionClass(CampaignListAdmin::class))->getFileName(), 2) . '/design/html';
$templates = glob($designDir . '/*.tpl') ?: [];
self::assertNotSame([], $templates);

$unresolved = [];
foreach ($templates as $template) {
preg_match_all('/\{url\b[^}]*\bcontroller=([^\s}]+)/', (string) file_get_contents($template), $matches);
foreach ($matches[1] as $controller) {
if (!$this->resolves(trim($controller, '\'"'))) {
$unresolved[] = basename($template) . ': ' . $controller;
}
}
}

self::assertSame([], $unresolved);
}

private function resolves(string $controller): bool
{
if (preg_match('/^\[(\w+),\s*(\w+),\s*(\w+)\]$/', $controller, $parts)
|| preg_match('/^(\w+)\.(\w+)\.(\w+)$/', $controller, $parts)) {
return class_exists("Okay\\Modules\\{$parts[1]}\\{$parts[2]}\\Backend\\Controllers\\{$parts[3]}");
}

return class_exists("Okay\\Admin\\Controllers\\{$controller}");
}
}