areaTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 areaTest 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 testCity()
  25. {
  26. $area = new area\upgrade();
  27. $area->city();
  28. }
  29. public function testConutry()
  30. {
  31. $area = new area\upgrade();
  32. $area->country();
  33. }
  34. public function testExport()
  35. {
  36. $area = new area\area_check();
  37. $result = $area->export();
  38. $x = json_encode($result,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  39. wcache('area_2.0', array('data' => serialize($result)), 'mb_area');
  40. }
  41. public function testUpdate()
  42. {
  43. area_helper::uplast_country();
  44. }
  45. public function testValidate()
  46. {
  47. $validator = new area\area_validator('area');
  48. $result = $validator->from_areaid(145);
  49. $result_name = $validator->from_name('上海','上海市','松江区');
  50. }
  51. public function testNosub()
  52. {
  53. $validator = new area\area_validator('area');
  54. $cities = $validator->nosub_city();
  55. $output = [];
  56. $input = [];
  57. foreach ($cities as $city)
  58. {
  59. $area_id = $city['area_id'];
  60. $items = $validator->city($city['area_id']);
  61. $prov = $items['province'];
  62. $input[$area_id] = ['其它区'];
  63. $str_out = "area_id={$area_id} prov_name = {$prov['area_name']} , city_name ={$city['area_name']}";
  64. $output[] = $str_out;
  65. }
  66. $in_json = json_encode($input,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  67. $out_json = json_encode($output,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  68. }
  69. public function testAddCountry()
  70. {
  71. $path = BASE_DATA_PATH . '/area/input';
  72. $content = file_get_contents($path);
  73. $items = json_decode($content);
  74. $mod_area = Model('area');
  75. foreach ($items as $parent_id => $names)
  76. {
  77. foreach ($names as $name) {
  78. $ret = $mod_area->insert(array('area_name' => $name,'area_deep' => 3,'area_parent_id' => $parent_id));
  79. Log::record("insert aread_id = {$ret},area_name={$name}");
  80. }
  81. }
  82. }
  83. public function testFixAreadid()
  84. {
  85. area_helper::fix_areaid();
  86. }
  87. public function testFixAreadinfo()
  88. {
  89. area_helper::fix_areainfo();
  90. }
  91. public function testReplace()
  92. {
  93. $phrase = "You should eat fruits, vegetables, and fiber every day.";
  94. $healthy = array("fruits", "vegetables", "fiber");
  95. $yummy = array("pizza", "beer", "ice cream");
  96. $newphrase = str_replace($healthy, $yummy, $phrase);
  97. $str = "上海 上海市 徐汇区 ";
  98. $x = str_replace(array(" "),array("\t"),$str);
  99. }
  100. }