-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EWPP-2022: Provide test coverage for the external links service.
- Loading branch information
1 parent
d91735c
commit 66d0da3
Showing
2 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/oe_theme_helper/tests/src/Kernel/ExternalLinksTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\Tests\oe_theme_helper\Kernel; | ||
|
||
use Drupal\Core\Url; | ||
use Drupal\Tests\oe_theme\Kernel\AbstractKernelTestBase; | ||
|
||
/** | ||
* Provides test coverage for the ExternalLinks service. | ||
* | ||
* @group batch1 | ||
*/ | ||
class ExternalLinksTest extends AbstractKernelTestBase { | ||
|
||
/** | ||
* Covers isExternalLink method. | ||
*/ | ||
public function testIsExternalLink(): void { | ||
$external_links = $this->container->get('oe_theme_helper.external_links'); | ||
// Assert internal URL. | ||
$this->assertFalse($external_links->isExternalLink(Url::fromUserInput('/user'))); | ||
// Assert external string path. | ||
$this->assertTrue($external_links->isExternalLink('https://example.com')); | ||
// Assert external string path under EU domain. | ||
$this->assertFalse($external_links->isExternalLink('https://example.europa.eu')); | ||
$this->assertFalse($external_links->isExternalLink('www.ec.europa.eu/info')); | ||
// Assert null and empty value. | ||
$this->assertFalse($external_links->isExternalLink()); | ||
$this->assertFalse($external_links->isExternalLink('')); | ||
// Assert incorrect paths. | ||
$this->assertFalse($external_links->isExternalLink('www. incorrect . com')); | ||
$this->assertFalse($external_links->isExternalLink('www. ec . europa . eu')); | ||
} | ||
|
||
} |