fix: harden url mapping validation
This commit is contained in:
@@ -21,12 +21,29 @@ class UrlMappingCollectionTest extends TestCase {
|
||||
new UrlMapping( '', 'https://staging.example.test' );
|
||||
}
|
||||
|
||||
public function test_it_returns_mappings_in_order(): void {
|
||||
$first = new UrlMapping( 'https://example.test', 'https://staging.example.test' );
|
||||
$second = new UrlMapping( 'https://cdn.example.test', 'https://cdn.staging.example.test' );
|
||||
$collection = new UrlMappingCollection( array( $first, $second ) );
|
||||
public function test_it_rejects_mapping_urls_without_scheme_and_host(): void {
|
||||
$this->expectException( \InvalidArgumentException::class );
|
||||
$this->expectExceptionMessage( 'Source and destination URLs must include a scheme and host.' );
|
||||
|
||||
self::assertSame( array( $first, $second ), $collection->all() );
|
||||
new UrlMapping( 'https://', 'https://staging.example.test' );
|
||||
}
|
||||
|
||||
public function test_it_preserves_query_and_fragment_trailing_slashes(): void {
|
||||
$mapping = new UrlMapping(
|
||||
'https://example.test/?redirect=/',
|
||||
'https://staging.example.test/#/'
|
||||
);
|
||||
|
||||
self::assertSame( 'https://example.test?redirect=/', $mapping->sourceUrl() );
|
||||
self::assertSame( 'https://staging.example.test#/', $mapping->destinationUrl() );
|
||||
}
|
||||
|
||||
public function test_it_returns_mappings_by_longest_source_url_first(): void {
|
||||
$short = new UrlMapping( 'https://example.test', 'https://staging.example.test' );
|
||||
$long = new UrlMapping( 'https://example.test/uploads', 'https://staging.example.test/uploads' );
|
||||
$collection = new UrlMappingCollection( array( $short, $long ) );
|
||||
|
||||
self::assertSame( array( $long, $short ), $collection->all() );
|
||||
}
|
||||
|
||||
public function test_it_rejects_non_mapping_items(): void {
|
||||
|
||||
Reference in New Issue
Block a user