xref: /PHP-8.1/ext/filter/tests/055.phpt (revision 74859783)
1--TEST--
2filter_var() and FILTER_VALIDATE_MAC
3--EXTENSIONS--
4filter
5--FILE--
6<?php
7$values = Array(
8    array("01-23-45-67-89-ab", 0),
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", 0),
13    array("01-23-45-67-89-aB", 0),
14    array("01:23:45:67:89:ab", 0),
15    array("01:23:45:67:89:AB", 0),
16    array("01:23:45:67:89:aB", 0),
17    array("01:23:45-67:89:aB", 0),
18    array("xx:23:45:67:89:aB", 0),
19    array("0123.4567.89ab", 0),
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