TestArea.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/3/16
  6. * Time: 下午11:55
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/helper/area/area_upgrade.php');
  11. require_once(BASE_ROOT_PATH . '/helper/area/area_check.php');
  12. require_once(BASE_ROOT_PATH . '/helper/area/area_validator.php');
  13. require_once(BASE_ROOT_PATH . '/helper/area_helper.php');
  14. class TestArea extends PHPUnit_Framework_TestCase
  15. {
  16. public static function setUpBeforeClass() {
  17. Base::run_util();
  18. }
  19. public function testProvince()
  20. {
  21. $area = new area\upgrade();
  22. $area->province();
  23. }
  24. public function testSafeurl()
  25. {
  26. $text = "韩国馆-个人洗护";
  27. $base64 = base64_encode($text);
  28. $title = util::base64url_encode($text);
  29. $xxx = urlencode($title);
  30. $xxy = urlencode($base64);
  31. $titlex = util::base64url_decode($title);
  32. $url = "http://p.lrlz.com/mshop/special?special_id=121&title={$title}";
  33. $url = urlencode($url);
  34. $url = urldecode($url);
  35. $urlx = "http://p.lrlz.com/mshop/special?special_id=121&title={$base64}";
  36. $urlx= urlencode($urlx);
  37. $urlx = urldecode($urlx);
  38. }
  39. public function testUrl()
  40. {
  41. $x = 'http%3A%2F%2Fp.lrlz.com%2Fmshop%2Fspecial%3Fspecial_id%3D450%26is_special%3Dtrue%26title%3D5ZGY5bel5YaF6LStdG9w5qacIDYyOA%2C%2C%26from%3Dsinglemessage%26isappinstalled%3D0';
  42. $y = urldecode($x);
  43. }
  44. public function testCity()
  45. {
  46. $area = new area\upgrade();
  47. $area->city();
  48. }
  49. public function testConutry()
  50. {
  51. $area = new area\upgrade();
  52. $area->country();
  53. }
  54. public function testExport()
  55. {
  56. $area = new area\area_check();
  57. $result = $area->export();
  58. $x = json_encode($result,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  59. wcache('area_2.0', array('data' => serialize($result)), 'mb_area');
  60. }
  61. public function testUpdate()
  62. {
  63. area_helper::uplast_country();
  64. }
  65. public function testValidate()
  66. {
  67. $validator = new area\area_validator('area');
  68. $result = $validator->from_areaid(145);
  69. $result_name = $validator->from_name('上海','上海市','松江区');
  70. }
  71. public function testNosub()
  72. {
  73. $validator = new area\area_validator('area');
  74. $cities = $validator->nosub_city();
  75. $output = [];
  76. $input = [];
  77. foreach ($cities as $city)
  78. {
  79. $area_id = $city['area_id'];
  80. $items = $validator->city($city['area_id']);
  81. $prov = $items['province'];
  82. $input[$area_id] = ['其它区'];
  83. $str_out = "area_id={$area_id} prov_name = {$prov['area_name']} , city_name ={$city['area_name']}";
  84. $output[] = $str_out;
  85. }
  86. $in_json = json_encode($input,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  87. $out_json = json_encode($output,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  88. }
  89. public function testAddCountry()
  90. {
  91. $path = BASE_DATA_PATH . '/area/input';
  92. $content = file_get_contents($path);
  93. $items = json_decode($content);
  94. $mod_area = Model('area');
  95. foreach ($items as $parent_id => $names)
  96. {
  97. foreach ($names as $name) {
  98. $ret = $mod_area->insert(array('area_name' => $name,'area_deep' => 3,'area_parent_id' => $parent_id));
  99. Log::record("insert aread_id = {$ret},area_name={$name}");
  100. }
  101. }
  102. }
  103. public function testFixAreadid()
  104. {
  105. area_helper::fix_areaid();
  106. }
  107. public function testFixAreadinfo()
  108. {
  109. area_helper::fix_areainfo();
  110. }
  111. public function testReplace()
  112. {
  113. $phrase = "You should eat fruits, vegetables, and fiber every day.";
  114. $healthy = array("fruits", "vegetables", "fiber");
  115. $yummy = array("pizza", "beer", "ice cream");
  116. $newphrase = str_replace($healthy, $yummy, $phrase);
  117. $str = "上海 上海市 徐汇区 ";
  118. $x = str_replace(array(" "),array("\t"),$str);
  119. }
  120. }