diff options
author | Hugues Peccatte <hugues.peccatte@gmail.com> | 2019-11-03 23:08:13 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2020-01-27 22:52:01 +0300 |
commit | 57442680fa1fe083603db1533b2f30a7b54dc70e (patch) | |
tree | 5e4bb55df0f530e2cbd73526f81b37b5fc4a6ef1 /test/classes/Utils | |
parent | 5dcb477e0f37cedfd98a5ab5202c0aab7da0b25d (diff) |
Fix #15555 - Add IP2Long input transformation
Signed-off-by: Hugues Peccatte <hugues.peccatte@gmail.com>
Diffstat (limited to 'test/classes/Utils')
-rw-r--r-- | test/classes/Utils/FormatConverterTest.php | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/test/classes/Utils/FormatConverterTest.php b/test/classes/Utils/FormatConverterTest.php new file mode 100644 index 0000000000..bafab36ab0 --- /dev/null +++ b/test/classes/Utils/FormatConverterTest.php @@ -0,0 +1,158 @@ +<?php +/** + * tests for PhpMyAdmin\Utils\FormatConverter class + * + * @package PhpMyAdmin-test + */ +declare(strict_types=1); + +namespace PhpMyAdmin\Tests\Utils; + +use PhpMyAdmin\Tests\PmaTestCase; +use PhpMyAdmin\Utils\FormatConverter; + +/** + * @package PhpMyAdmin\Tests\Utils + */ +class FormatConverterTest extends PmaTestCase +{ + /** + * Test for binaryToIp + * + * @param string $expected Expected result given an input + * @param string $input Input to convert + * + * @return void + * + * @dataProvider providerBinaryToIp + */ + public function testBinaryToIp(string $expected, string $input): void + { + $result = FormatConverter::binaryToIp($input); + $this->assertEquals($expected, $result); + } + + /** + * Data provider for binaroToIp + * + * @return array + */ + public function providerBinaryToIp(): array + { + return [ + [ + '10.11.12.13', + '0x0a0b0c0d', + ], + [ + 'my ip', + 'my ip', + ], + ]; + } + + /** + * Test for ipToBinary + * + * @param string $expected Expected result given an input + * @param string $input Input to convert + * + * @return void + * + * @dataProvider providerIpToBinary + */ + public function testIpToBinary(string $expected, string $input): void + { + $result = FormatConverter::ipToBinary($input); + $this->assertEquals($expected, $result); + } + + /** + * Data provider for ipToBinary + * + * @return array + */ + public function providerIpToBinary(): array + { + return [ + [ + '0x0a0b0c0d', + '10.11.12.13', + ], + [ + 'my ip', + 'my ip', + ], + ]; + } + + /** + * Test for ipToLong + * + * @param string $expected Expected result given an input + * @param string $input Input to convert + * + * @return void + * + * @dataProvider providerIpToLong + */ + public function testIpToLong(string $expected, string $input): void + { + $result = FormatConverter::ipToLong($input); + $this->assertEquals($expected, $result); + } + + /** + * Data provider for ipToLong + * + * @return array + */ + public function providerIpToLong(): array + { + return [ + [ + '168496141', + '10.11.12.13', + ], + [ + 'my ip', + 'my ip', + ], + ]; + } + + /** + * Test for longToIp + * + * @param string $expected Expected result given an input + * @param string $input Input to convert + * + * @return void + * + * @dataProvider providerLongToIp + */ + public function testLongToIp(string $expected, string $input): void + { + $result = FormatConverter::longToIp($input); + $this->assertEquals($expected, $result); + } + + /** + * Data provider for longToIp + * + * @return array + */ + public function providerLongToIp(): array + { + return [ + [ + '10.11.12.13', + '168496141', + ], + [ + 'my ip', + 'my ip', + ], + ]; + } +} |