areaTest.php 3.2 KB

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