菜谱项目

AddressTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Faker\Test\Provider\uk_UA;
  3. use Faker\Generator;
  4. use Faker\Provider\uk_UA\Address;
  5. class AddressTest extends \PHPUnit_Framework_TestCase
  6. {
  7. /**
  8. * @var Generator
  9. */
  10. private $faker;
  11. public function setUp()
  12. {
  13. $faker = new Generator();
  14. $faker->addProvider(new Address($faker));
  15. $this->faker = $faker;
  16. }
  17. public function testPostCodeIsValid()
  18. {
  19. $main = '[0-9]{5}';
  20. $pattern = "/^($main)|($main-[0-9]{3})+$/";
  21. $postcode = $this->faker->postcode;
  22. $this->assertRegExp($pattern, $postcode, 'Post code ' . $postcode . ' is wrong!');
  23. }
  24. public function testEmptySuffixes()
  25. {
  26. $this->assertEmpty($this->faker->citySuffix, 'City suffix should be empty!');
  27. $this->assertEmpty($this->faker->streetSuffix, 'Street suffix should be empty!');
  28. }
  29. public function testStreetCyrOnly()
  30. {
  31. $pattern = "/[0-9А-ЩЯІЇЄЮа-щяіїєюьIVXCM][0-9А-ЩЯІЇЄЮа-щяіїєюь \'-.]*[А-Яа-я.]/u";
  32. $streetName = $this->faker->streetName;
  33. $this->assertSame(
  34. preg_match($pattern, $streetName),
  35. 1,
  36. 'Street name ' . $streetName . ' is wrong!'
  37. );
  38. }
  39. public function testCityNameCyrOnly()
  40. {
  41. $pattern = "/[А-ЩЯІЇЄЮа-щяіїєюь][0-9А-ЩЯІЇЄЮа-щяіїєюь \'-]*[А-Яа-я]/u";
  42. $city = $this->faker->city;
  43. $this->assertSame(
  44. preg_match($pattern, $city),
  45. 1,
  46. 'City name ' . $city . ' is wrong!'
  47. );
  48. }
  49. public function testRegionNameCyrOnly()
  50. {
  51. $pattern = "/[А-ЩЯІЇЄЮ][А-ЩЯІЇЄЮа-щяіїєюь]*а$/u";
  52. $regionName = $this->faker->region;
  53. $this->assertSame(
  54. preg_match($pattern, $regionName),
  55. 1,
  56. 'Region name ' . $regionName . ' is wrong!'
  57. );
  58. }
  59. public function testCountryCyrOnly()
  60. {
  61. $pattern = "/[А-ЩЯІЇЄЮа-щяіїєюьIVXCM][А-ЩЯІЇЄЮа-щяіїєюь \'-]*[А-Яа-я.]/u";
  62. $country = $this->faker->country;
  63. $this->assertSame(
  64. preg_match($pattern, $country),
  65. 1,
  66. 'Country name ' . $country . ' is wrong!'
  67. );
  68. }
  69. }