Test2::Tools::URL - Compare a URL in your Test2 test
version 0.06
use Test2::V0; use Test2::Tools::URL; is( "http://example.com/path1/path2?query=1#fragment", url { url_scheme => 'http'; url_host => 'example.com'; url_component path => '/path1/path2'; url_component query => { query => 1 }; url_component fragment => 'fragment'; }, 'url is as expected', );
This set of Test2 tools helps writing tests against URLs, represented as either strings, or as objects that stringify to URLs (such as URI or Mojo::URL).
The idea is that you may be writing tests against URLs, but you may only care about one or two components, and you may not want to worry about decoding the URL or breaking the components up. The URL may be nested deeply. This tool is intended to help!
my $check = url {}
Checks that the given string or object is a valid URL.
url { url_base $url; };
Use the given base URL for relative paths. If specified outside of a URL, then it will apply to all url checks.
url { url_component $component, $check; }
Check that the given URL component matches.
Note: scheme is normalized to lower case for this test.
Note: hostname is not normalized to lower case for this test. To test the normalized hostname use url_host below.
url_host
May be either a string, list or array!
[version 0.06]
Note: for ftp URLs only.
ftp
Note: for data URLs only.
data
url { url_scheme $check; }
Check that the given URL scheme matches $check. Note that the scheme is normalized to lower case for this test, so it is identical to using url_component 'scheme', $check.
$check
url_component 'scheme', $check
url { url_host $check; }
Check that the given URL host matches $check. Note that the host is normalized to lower case for this test, unlike the url_component 'host', $check test described above.
url_component 'host', $check
url { url_secure(); }
Check that the given URL is using a secure protocol like https or wss.
https
wss
url { url_insecure(); }
Check that the given URL is using an insecure protocol like http or ftp.
http
url { url_mail_to $check; }
Checks that the email address in the given mailto URL matches the check. For non-mailto URLs this check will fail.
mailto
Test2::Suite
Author: Graham Ollis <plicease@cpan.org>
Contributors:
Paul Durden (alabamapaul, PDURDEN)
This software is copyright (c) 2017-2021 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test2::Tools::URL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test2::Tools::URL
CPAN shell
perl -MCPAN -e shell install Test2::Tools::URL
For more information on module installation, please visit the detailed CPAN module installation guide.