/usr/share/php/kohana3.2/system/tests/kohana/ValidTest.php is in libkohana3.2-core-php 3.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 | <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
/**
* Tests the Valid class
*
* @group kohana
* @group kohana.core
* @group kohana.core.valid
*
* @package Kohana
* @category Tests
* @author Kohana Team
* @author BRMatt <matthew@sigswitch.com>
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_ValidTest extends Unittest_TestCase
{
/**
* Provides test data for test_alpha()
* @return array
*/
public function provider_alpha()
{
return array(
array('asdavafaiwnoabwiubafpowf', TRUE),
array('!aidhfawiodb', FALSE),
array('51535oniubawdawd78', FALSE),
array('!"£$(G$W£(HFW£F(HQ)"n', FALSE),
// UTF-8 tests
array('あいうえお', TRUE, TRUE),
array('¥', FALSE, TRUE),
// Empty test
array('', FALSE, FALSE),
array(NULL, FALSE, FALSE),
array(FALSE, FALSE, FALSE),
);
}
/**
* Tests Valid::alpha()
*
* Checks whether a string consists of alphabetical characters only.
*
* @test
* @dataProvider provider_alpha
* @param string $string
* @param boolean $expected
*/
public function test_alpha($string, $expected, $utf8 = FALSE)
{
$this->assertSame(
$expected,
Valid::alpha($string, $utf8)
);
}
/*
* Provides test data for test_alpha_numeric
*/
public function provide_alpha_numeric()
{
return array(
array('abcd1234', TRUE),
array('abcd', TRUE),
array('1234', TRUE),
array('abc123&^/-', FALSE),
// UTF-8 tests
array('あいうえお', TRUE, TRUE),
array('零一二三四五', TRUE, TRUE),
array('あい四五£^£^', FALSE, TRUE),
// Empty test
array('', FALSE, FALSE),
array(NULL, FALSE, FALSE),
array(FALSE, FALSE, FALSE),
);
}
/**
* Tests Valid::alpha_numeric()
*
* Checks whether a string consists of alphabetical characters and numbers only.
*
* @test
* @dataProvider provide_alpha_numeric
* @param string $input The string to test
* @param boolean $expected Is $input valid
*/
public function test_alpha_numeric($input, $expected, $utf8 = FALSE)
{
$this->assertSame(
$expected,
Valid::alpha_numeric($input, $utf8)
);
}
/**
* Provides test data for test_alpha_dash
*/
public function provider_alpha_dash()
{
return array(
array('abcdef', TRUE),
array('12345', TRUE),
array('abcd1234', TRUE),
array('abcd1234-', TRUE),
array('abc123&^/-', FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::alpha_dash()
*
* Checks whether a string consists of alphabetical characters, numbers, underscores and dashes only.
*
* @test
* @dataProvider provider_alpha_dash
* @param string $input The string to test
* @param boolean $contains_utf8 Does the string contain utf8 specific characters
* @param boolean $expected Is $input valid?
*/
public function test_alpha_dash($input, $expected, $contains_utf8 = FALSE)
{
if ( ! $contains_utf8)
{
$this->assertSame(
$expected,
Valid::alpha_dash($input)
);
}
$this->assertSame(
$expected,
Valid::alpha_dash($input, TRUE)
);
}
/**
* DataProvider for the valid::date() test
*/
public function provider_date()
{
return array(
array('now',TRUE),
array('10 September 2010',TRUE),
array('+1 day',TRUE),
array('+1 week',TRUE),
array('+1 week 2 days 4 hours 2 seconds',TRUE),
array('next Thursday',TRUE),
array('last Monday',TRUE),
array('blarg',FALSE),
array('in the year 2000',FALSE),
array('324824',FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::date()
*
* @test
* @dataProvider provider_date
* @param string $date The date to validate
* @param integer $expected
*/
public function test_date($date, $expected)
{
$this->assertSame(
$expected,
Valid::date($date, $expected)
);
}
/**
* DataProvider for the valid::decimal() test
*/
public function provider_decimal()
{
return array(
// Empty test
array('', 2, NULL, FALSE),
array(NULL, 2, NULL, FALSE),
array(FALSE, 2, NULL, FALSE),
array('45.1664', 3, NULL, FALSE),
array('45.1664', 4, NULL, TRUE),
array('45.1664', 4, 2, TRUE),
array('-45.1664', 4, NULL, TRUE),
array('+45.1664', 4, NULL, TRUE),
array('-45.1664', 3, NULL, FALSE),
);
}
/**
* Tests Valid::decimal()
*
* @test
* @dataProvider provider_decimal
* @param string $decimal The decimal to validate
* @param integer $places The number of places to check to
* @param integer $digits The number of digits preceding the point to check
* @param boolean $expected Whether $decimal conforms to $places AND $digits
*/
public function test_decimal($decimal, $places, $digits, $expected)
{
$this->assertSame(
$expected,
Valid::decimal($decimal, $places, $digits),
'Decimal: "'.$decimal.'" to '.$places.' places and '.$digits.' digits (preceeding period)'
);
}
/**
* Provides test data for test_digit
* @return array
*/
public function provider_digit()
{
return array(
array('12345', TRUE),
array('10.5', FALSE),
array('abcde', FALSE),
array('abcd1234', FALSE),
array('-5', FALSE),
array(-5, FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::digit()
*
* @test
* @dataProvider provider_digit
* @param mixed $input Input to validate
* @param boolean $expected Is $input valid
*/
public function test_digit($input, $expected, $contains_utf8 = FALSE)
{
if ( ! $contains_utf8)
{
$this->assertSame(
$expected,
Valid::digit($input)
);
}
$this->assertSame(
$expected,
Valid::digit($input, TRUE)
);
}
/**
* DataProvider for the valid::color() test
*/
public function provider_color()
{
return array(
array('#000000', TRUE),
array('#GGGGGG', FALSE),
array('#AbCdEf', TRUE),
array('#000', TRUE),
array('#abc', TRUE),
array('#DEF', TRUE),
array('000000', TRUE),
array('GGGGGG', FALSE),
array('AbCdEf', TRUE),
array('000', TRUE),
array('DEF', TRUE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::color()
*
* @test
* @dataProvider provider_color
* @param string $color The color to test
* @param boolean $expected Is $color valid
*/
public function test_color($color, $expected)
{
$this->assertSame(
$expected,
Valid::color($color)
);
}
/**
* Provides test data for test_credit_card()
*/
public function provider_credit_card()
{
return array(
array('4222222222222', 'visa', TRUE),
array('4012888888881881', 'visa', TRUE),
array('4012888888881881', NULL, TRUE),
array('4012888888881881', array('mastercard', 'visa'), TRUE),
array('4012888888881881', array('discover', 'mastercard'), FALSE),
array('4012888888881881', 'mastercard', FALSE),
array('5105105105105100', 'mastercard', TRUE),
array('6011111111111117', 'discover', TRUE),
array('6011111111111117', 'visa', FALSE),
// Empty test
array('', NULL, FALSE),
array(NULL, NULL, FALSE),
array(FALSE, NULL, FALSE),
);
}
/**
* Tests Valid::credit_card()
*
* @test
* @covers Valid::credit_card
* @dataProvider provider_credit_card()
* @param string $number Credit card number
* @param string $type Credit card type
* @param boolean $expected
*/
public function test_credit_card($number, $type, $expected)
{
$this->assertSame(
$expected,
Valid::credit_card($number, $type)
);
}
/**
* Provides test data for test_credit_card()
*/
public function provider_luhn()
{
return array(
array('4222222222222', TRUE),
array('4012888888881881', TRUE),
array('5105105105105100', TRUE),
array('6011111111111117', TRUE),
array('60111111111111.7', FALSE),
array('6011111111111117X', FALSE),
array('6011111111111117 ', FALSE),
array('WORD ', FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::luhn()
*
* @test
* @covers Valid::luhn
* @dataProvider provider_luhn()
* @param string $number Credit card number
* @param boolean $expected
*/
public function test_luhn($number, $expected)
{
$this->assertSame(
$expected,
Valid::luhn($number)
);
}
/**
* Provides test data for test_email()
*
* @return array
*/
public function provider_email()
{
return array(
array('foo', TRUE, FALSE),
array('foo', FALSE, FALSE),
array('foo@bar', TRUE, TRUE),
// RFC is less strict than the normal regex, presumably to allow
// admin@localhost, therefore we IGNORE IT!!!
array('foo@bar', FALSE, FALSE),
array('foo@bar.com', FALSE, TRUE),
array('foo@barcom:80', FALSE, FALSE),
array('foo@bar.sub.com', FALSE, TRUE),
array('foo+asd@bar.sub.com', FALSE, TRUE),
array('foo.asd@bar.sub.com', FALSE, TRUE),
// RFC says 254 length max #4011
array(Text::random(NULL, 200).'@'.Text::random(NULL, 50).'.com', FALSE, FALSE),
// Empty test
array('', TRUE, FALSE),
array(NULL, TRUE, FALSE),
array(FALSE, TRUE, FALSE),
);
}
/**
* Tests Valid::email()
*
* Check an email address for correct format.
*
* @test
* @dataProvider provider_email
* @param string $email Address to check
* @param boolean $strict Use strict settings
* @param boolean $correct Is $email address valid?
*/
public function test_email($email, $strict, $correct)
{
$this->assertSame(
$correct,
Valid::email($email, $strict)
);
}
/**
* Returns test data for test_email_domain()
*
* @return array
*/
public function provider_email_domain()
{
return array(
array('google.com', TRUE),
// Don't anybody dare register this...
array('DAWOMAWIDAIWNDAIWNHDAWIHDAIWHDAIWOHDAIOHDAIWHD.com', FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::email_domain()
*
* Validate the domain of an email address by checking if the domain has a
* valid MX record.
*
* Test skips on windows
*
* @test
* @dataProvider provider_email_domain
* @param string $email Email domain to check
* @param boolean $correct Is it correct?
*/
public function test_email_domain($email, $correct)
{
if ( ! $this->hasInternet())
{
$this->markTestSkipped('An internet connection is required for this test');
}
if ( ! Kohana::$is_windows OR version_compare(PHP_VERSION, '5.3.0', '>='))
{
$this->assertSame(
$correct,
Valid::email_domain($email)
);
}
else
{
$this->markTestSkipped('checkdnsrr() was not added on windows until PHP 5.3');
}
}
/**
* Provides data for test_exact_length()
*
* @return array
*/
public function provider_exact_length()
{
return array(
array('somestring', 10, TRUE),
array('somestring', 11, FALSE),
array('anotherstring', 13, TRUE),
// Empty test
array('', 10, FALSE),
array(NULL, 10, FALSE),
array(FALSE, 10, FALSE),
// Test array of allowed lengths
array('somestring', array(1, 3, 5, 7, 9, 10), TRUE),
array('somestring', array(1, 3, 5, 7, 9), FALSE),
);
}
/**
*
* Tests Valid::exact_length()
*
* Checks that a field is exactly the right length.
*
* @test
* @dataProvider provider_exact_length
* @param string $string The string to length check
* @param integer $length The length of the string
* @param boolean $correct Is $length the actual length of the string?
* @return bool
*/
public function test_exact_length($string, $length, $correct)
{
return $this->assertSame(
$correct,
Valid::exact_length($string, $length),
'Reported string length is not correct'
);
}
/**
* Provides data for test_equals()
*
* @return array
*/
public function provider_equals()
{
return array(
array('foo', 'foo', TRUE),
array('1', '1', TRUE),
array(1, '1', FALSE),
array('011', 011, FALSE),
// Empty test
array('', 123, FALSE),
array(NULL, 123, FALSE),
array(FALSE, 123, FALSE),
);
}
/**
* Tests Valid::equals()
*
* @test
* @dataProvider provider_equals
* @param string $string value to check
* @param integer $required required value
* @param boolean $correct is $string the same as $required?
* @return boolean
*/
public function test_equals($string, $required, $correct)
{
return $this->assertSame(
$correct,
Valid::equals($string, $required),
'Values are not equal'
);
}
/**
* DataProvider for the valid::ip() test
* @return array
*/
public function provider_ip()
{
return array(
array('75.125.175.50', FALSE, TRUE),
// PHP 5.3.6 fixed a bug that allowed 127.0.0.1 as a public ip: http://bugs.php.net/53150
array('127.0.0.1', FALSE, version_compare(PHP_VERSION, '5.3.6', '<')),
array('256.257.258.259', FALSE, FALSE),
array('255.255.255.255', FALSE, FALSE),
array('192.168.0.1', FALSE, FALSE),
array('192.168.0.1', TRUE, TRUE),
// Empty test
array('', TRUE, FALSE),
array(NULL, TRUE, FALSE),
array(FALSE, TRUE, FALSE),
);
}
/**
* Tests Valid::ip()
*
* @test
* @dataProvider provider_ip
* @param string $input_ip
* @param boolean $allow_private
* @param boolean $expected_result
*/
public function test_ip($input_ip, $allow_private, $expected_result)
{
$this->assertEquals(
$expected_result,
Valid::ip($input_ip, $allow_private)
);
}
/**
* Returns test data for test_max_length()
*
* @return array
*/
public function provider_max_length()
{
return array(
// Border line
array('some', 4, TRUE),
// Exceeds
array('KOHANARULLLES', 2, FALSE),
// Under
array('CakeSucks', 10, TRUE),
// Empty test
array('', -10, FALSE),
array(NULL, -10, FALSE),
array(FALSE, -10, FALSE),
);
}
/**
* Tests Valid::max_length()
*
* Checks that a field is short enough.
*
* @test
* @dataProvider provider_max_length
* @param string $string String to test
* @param integer $maxlength Max length for this string
* @param boolean $correct Is $string <= $maxlength
*/
public function test_max_length($string, $maxlength, $correct)
{
$this->assertSame(
$correct,
Valid::max_length($string, $maxlength)
);
}
/**
* Returns test data for test_min_length()
*
* @return array
*/
public function provider_min_length()
{
return array(
array('This is obviously long enough', 10, TRUE),
array('This is not', 101, FALSE),
array('This is on the borderline', 25, TRUE),
// Empty test
array('', 10, FALSE),
array(NULL, 10, FALSE),
array(FALSE, 10, FALSE),
);
}
/**
* Tests Valid::min_length()
*
* Checks that a field is long enough.
*
* @test
* @dataProvider provider_min_length
* @param string $string String to compare
* @param integer $minlength The minimum allowed length
* @param boolean $correct Is $string 's length >= $minlength
*/
public function test_min_length($string, $minlength, $correct)
{
$this->assertSame(
$correct,
Valid::min_length($string, $minlength)
);
}
/**
* Returns test data for test_not_empty()
*
* @return array
*/
public function provider_not_empty()
{
// Create a blank arrayObject
$ao = new ArrayObject;
// arrayObject with value
$ao1 = new ArrayObject;
$ao1['test'] = 'value';
return array(
array(array(), FALSE),
array(NULL, FALSE),
array('', FALSE),
array($ao, FALSE),
array($ao1, TRUE),
array(array(NULL), TRUE),
array(0, TRUE),
array('0', TRUE),
array('Something', TRUE),
);
}
/**
* Tests Valid::not_empty()
*
* Checks if a field is not empty.
*
* @test
* @dataProvider provider_not_empty
* @param mixed $value Value to check
* @param boolean $empty Is the value really empty?
*/
public function test_not_empty($value, $empty)
{
return $this->assertSame(
$empty,
Valid::not_empty($value)
);
}
/**
* DataProvider for the Valid::numeric() test
*/
public function provider_numeric()
{
return array(
array(12345, TRUE),
array(123.45, TRUE),
array('12345', TRUE),
array('10.5', TRUE),
array('-10.5', TRUE),
array('10.5a', FALSE),
// @issue 3240
array(.4, TRUE),
array(-.4, TRUE),
array(4., TRUE),
array(-4., TRUE),
array('.5', TRUE),
array('-.5', TRUE),
array('5.', TRUE),
array('-5.', TRUE),
array('.', FALSE),
array('1.2.3', FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
}
/**
* Tests Valid::numeric()
*
* @test
* @dataProvider provider_numeric
* @param string $input Input to test
* @param boolean $expected Whether or not $input is numeric
*/
public function test_numeric($input, $expected)
{
$this->assertSame(
$expected,
Valid::numeric($input)
);
}
/**
* Provides test data for test_phone()
* @return array
*/
public function provider_phone()
{
return array(
array('0163634840', NULL, TRUE),
array('+27173634840', NULL, TRUE),
array('123578', NULL, FALSE),
// Some uk numbers
array('01234456778', NULL, TRUE),
array('+0441234456778', NULL, FALSE),
// Google UK case you're interested
array('+44 20-7031-3000', array(12), TRUE),
// BT Corporate
array('020 7356 5000', NULL, TRUE),
// Empty test
array('', NULL, FALSE),
array(NULL, NULL, FALSE),
array(FALSE, NULL, FALSE),
);
}
/**
* Tests Valid::phone()
*
* @test
* @dataProvider provider_phone
* @param string $phone Phone number to test
* @param boolean $expected Is $phone valid
*/
public function test_phone($phone, $lengths, $expected)
{
$this->assertSame(
$expected,
Valid::phone($phone, $lengths)
);
}
/**
* DataProvider for the valid::regex() test
*/
public function provider_regex()
{
return array(
array('hello world', '/[a-zA-Z\s]++/', TRUE),
array('123456789', '/[0-9]++/', TRUE),
array('£$%£%', '/[abc]/', FALSE),
array('Good evening', '/hello/', FALSE),
// Empty test
array('', '/hello/', FALSE),
array(NULL, '/hello/', FALSE),
array(FALSE, '/hello/', FALSE),
);
}
/**
* Tests Valid::range()
*
* Tests if a number is within a range.
*
* @test
* @dataProvider provider_regex
* @param string Value to test against
* @param string Valid pcre regular expression
* @param bool Does the value match the expression?
*/
public function test_regex($value, $regex, $expected)
{
$this->AssertSame(
$expected,
Valid::regex($value, $regex)
);
}
/**
* DataProvider for the valid::range() test
*/
public function provider_range()
{
return array(
array(1, 0, 2, TRUE),
array(-1, -5, 0, TRUE),
array(-1, 0, 1, FALSE),
array(1, 0, 0, FALSE),
array(2147483647, 0, 200000000000000, TRUE),
array(-2147483647, -2147483655, 2147483645, TRUE),
// Empty test
array('', 5, 10, FALSE),
array(NULL, 5, 10, FALSE),
array(FALSE, 5, 10, FALSE),
);
}
/**
* Tests Valid::range()
*
* Tests if a number is within a range.
*
* @test
* @dataProvider provider_range
* @param integer $number Number to test
* @param integer $min Lower bound
* @param integer $max Upper bound
* @param boolean $expected Is Number within the bounds of $min && $max
*/
public function test_range($number, $min, $max, $expected)
{
$this->AssertSame(
$expected,
Valid::range($number, $min, $max)
);
}
/**
* Provides test data for test_url()
*
* @return array
*/
public function provider_url()
{
$data = array(
array('http://google.com', TRUE),
array('http://google.com/', TRUE),
array('http://google.com/?q=abc', TRUE),
array('http://google.com/#hash', TRUE),
array('http://localhost', TRUE),
array('http://hello-world.pl', TRUE),
array('http://hello--world.pl', TRUE),
array('http://h.e.l.l.0.pl', TRUE),
array('http://server.tld/get/info', TRUE),
array('http://127.0.0.1', TRUE),
array('http://127.0.0.1:80', TRUE),
array('http://user@127.0.0.1', TRUE),
array('http://user:pass@127.0.0.1', TRUE),
array('ftp://my.server.com', TRUE),
array('rss+xml://rss.example.com', TRUE),
array('http://google.2com', FALSE),
array('http://google.com?q=abc', FALSE),
array('http://google.com#hash', FALSE),
array('http://hello-.pl', FALSE),
array('http://hel.-lo.world.pl', FALSE),
array('http://ww£.google.com', FALSE),
array('http://127.0.0.1234', FALSE),
array('http://127.0.0.1.1', FALSE),
array('http://user:@127.0.0.1', FALSE),
array("http://finalnewline.com\n", FALSE),
// Empty test
array('', FALSE),
array(NULL, FALSE),
array(FALSE, FALSE),
);
$data[] = array('http://'.str_repeat('123456789.', 25).'com/', TRUE); // 253 chars
$data[] = array('http://'.str_repeat('123456789.', 25).'info/', FALSE); // 254 chars
return $data;
}
/**
* Tests Valid::url()
*
* @test
* @dataProvider provider_url
* @param string $url The url to test
* @param boolean $expected Is it valid?
*/
public function test_url($url, $expected)
{
$this->assertSame(
$expected,
Valid::url($url)
);
}
/**
* DataProvider for the valid::matches() test
*/
public function provider_matches()
{
return array(
array(array('a' => 'hello', 'b' => 'hello'), 'a', 'b', TRUE),
array(array('a' => 'hello', 'b' => 'hello '), 'a', 'b', FALSE),
array(array('a' => '1', 'b' => 1), 'a', 'b', FALSE),
// Empty test
array(array('a' => '', 'b' => 'hello'), 'a', 'b', FALSE),
array(array('a' => NULL, 'b' => 'hello'), 'a', 'b', FALSE),
array(array('a' => FALSE, 'b' => 'hello'), 'a', 'b', FALSE),
);
}
/**
* Tests Valid::matches()
*
* Tests if a field matches another from an array of data
*
* @test
* @dataProvider provider_matches
* @param array $data Array of fields
* @param integer $field First field name
* @param integer $match Field name that must match $field in $data
* @param boolean $expected Do the two fields match?
*/
public function test_matches($data, $field, $match, $expected)
{
$this->AssertSame(
$expected,
Valid::matches($data, $field, $match)
);
}
}
|