namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\UrlHelper;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
/**
* @group Utility
*
* @coversDefaultClass \Drupal\Component\Utility\UrlHelper
*/
-class UrlHelperTest extends UnitTestCase {
+class UrlHelperTest extends TestCase {
/**
* Provides test data for testBuildQuery().
'fragment' => 'footer',
],
],
+ 'absolute fragment, no query' => [
+ 'http://www.example.com/my/path#footer',
+ [
+ 'path' => 'http://www.example.com/my/path',
+ 'query' => [],
+ 'fragment' => 'footer',
+ ],
+ ],
[
'http://',
[
'fragment' => 'footer',
],
],
+ 'relative fragment, no query' => [
+ '/my/path#footer',
+ [
+ 'path' => '/my/path',
+ 'query' => [],
+ 'fragment' => 'footer',
+ ],
+ ],
];
}
* @covers ::filterBadProtocol
*
* @param string $uri
- * Protocol URI.
+ * Protocol URI.
* @param string $expected
- * Expected escaped value.
+ * Expected escaped value.
* @param array $protocols
- * Protocols to allow.
+ * Protocols to allow.
*/
public function testFilterBadProtocol($uri, $expected, $protocols) {
UrlHelper::setAllowedProtocols($protocols);
* @covers ::stripDangerousProtocols
*
* @param string $uri
- * Protocol URI.
+ * Protocol URI.
* @param string $expected
- * Expected escaped value.
+ * Expected escaped value.
* @param array $protocols
- * Protocols to allow.
+ * Protocols to allow.
*/
public function testStripDangerousProtocols($uri, $expected, $protocols) {
UrlHelper::setAllowedProtocols($protocols);
['http://example.com/foo', 'http://example.com/bar', FALSE],
['http://example.com', 'http://example.com/bar', FALSE],
['http://example.com/bar', 'http://example.com/bar/', FALSE],
+ // Ensure \ is normalised to / since some browsers do that.
+ ['http://www.example.ca\@example.com', 'http://example.com', FALSE],
+ // Some browsers ignore or strip leading control characters.
+ ["\x00//www.example.ca", 'http://example.com', FALSE],
];
}
* @dataProvider providerTestExternalIsLocalInvalid
*/
public function testExternalIsLocalInvalid($url, $base_url) {
- $this->setExpectedException(\InvalidArgumentException::class);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\InvalidArgumentException::class);
+ }
+ else {
+ $this->setExpectedException(\InvalidArgumentException::class);
+ }
UrlHelper::externalIsLocal($url, $base_url);
}