added test cases, remove activeClass from output if no target set
All checks were successful
CI / testsuite (sqlite, 8.2, ) (push) Successful in 12m46s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Successful in 12m35s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 10m20s
CI / Coding Standard & Static Analysis (push) Successful in 13m51s
CI / testsuite (mysql, 8.2, ) (push) Successful in 5m9s
CI / testsuite (mysql, 8.4, ) (push) Successful in 6m20s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 5m16s
CI / testsuite (pgsql, 8.4, ) (push) Successful in 5m51s
All checks were successful
CI / testsuite (sqlite, 8.2, ) (push) Successful in 12m46s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Successful in 12m35s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 10m20s
CI / Coding Standard & Static Analysis (push) Successful in 13m51s
CI / testsuite (mysql, 8.2, ) (push) Successful in 5m9s
CI / testsuite (mysql, 8.4, ) (push) Successful in 6m20s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 5m16s
CI / testsuite (pgsql, 8.4, ) (push) Successful in 5m51s
This commit is contained in:
@@ -42,6 +42,8 @@ class ActiveLinkHelper extends Helper {
|
|||||||
public function link(array|string $title, array|string|null $url = null, array $options = []): string {
|
public function link(array|string $title, array|string|null $url = null, array $options = []): string {
|
||||||
$currentUrl = $options['current'] ?? Router::parseRequest($this->getView()->getRequest());
|
$currentUrl = $options['current'] ?? Router::parseRequest($this->getView()->getRequest());
|
||||||
if (!array_key_exists('target', $options) || !$currentUrl) {
|
if (!array_key_exists('target', $options) || !$currentUrl) {
|
||||||
|
unset($options['activeClass']);
|
||||||
|
|
||||||
return $this->Html->link($title, $url, $options);
|
return $this->Html->link($title, $url, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ class ActiveLinkHelperTest extends TestCase {
|
|||||||
'/',
|
'/',
|
||||||
['controller' => 'Tests', 'action' => 'index'],
|
['controller' => 'Tests', 'action' => 'index'],
|
||||||
);
|
);
|
||||||
|
$routes->get(
|
||||||
|
'/home',
|
||||||
|
['controller' => 'Tests', 'action' => 'index'],
|
||||||
|
);
|
||||||
$routes->get(
|
$routes->get(
|
||||||
'/admin/users',
|
'/admin/users',
|
||||||
['prefix' => 'Admin', 'controller' => 'Users', 'action' => 'index'],
|
['prefix' => 'Admin', 'controller' => 'Users', 'action' => 'index'],
|
||||||
@@ -39,6 +43,20 @@ class ActiveLinkHelperTest extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLinkNoTargetSet(): void {
|
||||||
|
$request = new ServerRequest(['url' => '/']);
|
||||||
|
$view = new View($request);
|
||||||
|
$helper = new ActiveLinkHelper($view);
|
||||||
|
|
||||||
|
$result = $helper->link('goto', '/', [
|
||||||
|
'activeClass' => 'awesome-active-class',
|
||||||
|
]);
|
||||||
|
$this->assertStringNotContainsString('awesome-active-class', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testLinkMatchesString(): void {
|
public function testLinkMatchesString(): void {
|
||||||
$request = new ServerRequest(['url' => '/']);
|
$request = new ServerRequest(['url' => '/']);
|
||||||
@@ -50,6 +68,19 @@ class ActiveLinkHelperTest extends TestCase {
|
|||||||
'activeClass' => 'awesome-active-class',
|
'activeClass' => 'awesome-active-class',
|
||||||
]);
|
]);
|
||||||
$this->assertStringContainsString('awesome-active-class', $result);
|
$this->assertStringContainsString('awesome-active-class', $result);
|
||||||
|
$this->assertStringNotContainsString('activeClass', $result);
|
||||||
|
|
||||||
|
$request = new ServerRequest(['url' => '/home']);
|
||||||
|
$view = new View($request);
|
||||||
|
$helper = new ActiveLinkHelper($view);
|
||||||
|
|
||||||
|
$result = $helper->link('goto', '/', [
|
||||||
|
'target' => '/',
|
||||||
|
'activeClass' => 'awesome-active-class',
|
||||||
|
]);
|
||||||
|
$this->assertStringContainsString('awesome-active-class', $result);
|
||||||
|
$this->assertStringNotContainsString('activeClass', $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user