xref: /PHP-8.0/ext/filter/tests/055.phpt (revision cc35cfd2)
1--TEST--
2filter_var() and FILTER_VALIDATE_MAC
3--SKIPIF--
4<?php if (!extension_loaded("filter")) die("skip"); ?>
5--FILE--
6<?php
7$values = Array(
8    array("01-23-45-67-89-ab", null),
9    array("01-23-45-67-89-ab", array("options" => array("separator" => "-"))),
10    array("01-23-45-67-89-ab", array("options" => array("separator" => "."))),
11    array("01-23-45-67-89-ab", array("options" => array("separator" => ":"))),
12    array("01-23-45-67-89-AB", null),
13    array("01-23-45-67-89-aB", null),
14    array("01:23:45:67:89:ab", null),
15    array("01:23:45:67:89:AB", null),
16    array("01:23:45:67:89:aB", null),
17    array("01:23:45-67:89:aB", null),
18    array("xx:23:45:67:89:aB", null),
19    array("0123.4567.89ab", null),
20    array("01-23-45-67-89-ab", array("options" => array("separator" => "--"))),
21    array("01-23-45-67-89-ab", array("options" => array("separator" => ""))),
22);
23foreach ($values as $value) {
24    try {
25        var_dump(filter_var($value[0], FILTER_VALIDATE_MAC, $value[1]));
26    } catch (ValueError $exception) {
27        echo $exception->getMessage() . "\n";
28    }
29}
30
31echo "Done\n";
32?>
33--EXPECT--
34string(17) "01-23-45-67-89-ab"
35string(17) "01-23-45-67-89-ab"
36bool(false)
37bool(false)
38string(17) "01-23-45-67-89-AB"
39string(17) "01-23-45-67-89-aB"
40string(17) "01:23:45:67:89:ab"
41string(17) "01:23:45:67:89:AB"
42string(17) "01:23:45:67:89:aB"
43bool(false)
44bool(false)
45string(14) "0123.4567.89ab"
46filter_var(): "separator" option must be one character long
47filter_var(): "separator" option must be one character long
48Done
49