/branches/alake/plugins/geo_kit/test/default_tests.php

https://github.com/akelos/v1 · PHP · 118 lines · 57 code · 10 blank · 51 comment · 0 complexity · aca23f2c56b35f604b6020db86975b29 MD5 · raw file

  1. <?php
  2. error_reporting(E_ALL);
  3. defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
  4. defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);
  5. defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION') ? null :
  6. define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false);
  7. defined('AK_BASE_DIR') ? null :
  8. define('AK_BASE_DIR',realpath(dirname(__FILE__).str_repeat(DS.'..',5)));
  9. defined('GEOKIT_PLUGIN_DIR') ? null :
  10. define('GEOKIT_PLUGIN_DIR',
  11. AK_BASE_DIR.DS.'app'.DS.'vendor'.DS.'plugins'.DS.'geo_kit');
  12. defined('AK_APP_DIR') ? null :
  13. define('AK_APP_DIR', GEOKIT_PLUGIN_DIR.DS.'test'.DS.'fixtures'.DS.'app');
  14. require_once(AK_BASE_DIR.DS.'test'.DS.'fixtures'.DS.'config'.DS.'config.php');
  15. # This file may not exist. It exists if you had to create one for your
  16. # plugin, as I had to for geo_kit
  17. require_once(GEOKIT_PLUGIN_DIR.DS.'config'.DS.'config.php');
  18. # These are the plugin scripts
  19. $lib_dir = GEOKIT_PLUGIN_DIR.DS.'lib'.DS.'geo_kit'.DS;
  20. require_once($lib_dir.'defaults.php');
  21. #require_once($lib_dir.'mappable.php');
  22. #require_once($lib_dir.'acts_as_mappable.php');
  23. #require_once($lib_dir.'array_funcs.php');
  24. #require_once($lib_dir.'ip_geocode_lookup.php');
  25. #require_once($lib_dir.'geocoders.php');
  26. class DefaultTestCase extends AkUnitTest
  27. {
  28. /*
  29. function test_setup()
  30. {
  31. # Create tables
  32. $this->installAndIncludeModels('Company');
  33. $this->installAndIncludeModels('CustomLocation');
  34. $this->installAndIncludeModels('Location');
  35. $this->installAndIncludeModels('Store');
  36. $this->populateTables(array('companies','custom_locations','locations'));
  37. $Installer =& new AkInstaller();
  38. } // function test_setup
  39. # This function is a modification of a function of the same name in
  40. # AK_UNIT_TEST. The changes accomplish two things:
  41. # This function looks for the YAML files within the
  42. # GEOKIT_PLUGIN_DIR instead of app_home/test/fixtures/data,
  43. # where non-plugin testing is done.
  44. # It looks for files with the extension "yml" as well as "yaml".
  45. # The reason for this is that Rails uses the extension "yml".
  46. function populateTables()
  47. {
  48. $args = func_get_args();
  49. $tables = !empty($args) ? (is_array($args[0]) ? $args[0] :
  50. (count($args) > 1 ? $args : Ak::toArray($args))) : array();
  51. foreach ($tables as $table){
  52. $data_dir = GEOKIT_PLUGIN_DIR.DS.'test'.DS.'fixtures'.DS.'data';
  53. $file = $data_dir.DS.$table.'.yaml';
  54. if(!file_exists($file)){
  55. $file = $data_dir.DS.$table.'.yml';
  56. if(!file_exists($file)) {
  57. continue;
  58. }
  59. }
  60. $class_name = AkInflector::classify($table);
  61. if($this->instantiateModel($class_name)) {
  62. $items = Ak::convert('yaml','array',file_get_contents($file));
  63. foreach ($items as $item) {
  64. $this->{$class_name}->create($item);
  65. }
  66. }
  67. }
  68. } // function populateTables()
  69. */
  70. function test_get_defaults()
  71. {
  72. $default = new GeoKitDefaults;
  73. $units = $default->get('units');
  74. $formula = $default->get('formula');
  75. $this->assertEqual($units, 'miles');
  76. $this->assertEqual($formula,'sphere');
  77. }
  78. function test_set_defaults()
  79. {
  80. $default = new GeoKitDefaults;
  81. $this->assertFalse($default->set('sphere'));
  82. $this->assertTrue($default->set(array()));
  83. $this->assertFalse($default->set(array('unit' => 'mile')));
  84. $this->assertFalse($default->set(array('units' => 'mile')));
  85. $this->assertTrue($default->set(array('units' => 'kms')));
  86. $units = $default->get('units');
  87. $this->assertEqual($units, 'kms');
  88. $this->assertFalse($default->set(array('formulae' => 'sphere')));
  89. $this->assertFalse($default->set(array('formula' => 'round')));
  90. $this->assertTrue($default->set(array('formula' => 'flat')));
  91. $formula = $default->get('formula');
  92. $this->assertEqual($formula, 'flat');
  93. $this->assertFalse($default->set(
  94. array('formulae' => 'sphere','units' => 'km')));
  95. $this->assertFalse($default->set(
  96. array('formula' => 'round','units' => 'miles')));
  97. $this->assertTrue($default->set(
  98. array('formula' => 'sphere','units' => 'miles')));
  99. $formula = $default->get('formula');
  100. $this->assertEqual($formula, 'sphere');
  101. $units = $default->get('units');
  102. $this->assertEqual($units, 'miles');
  103. }
  104. } // class DefaultTestCase
  105. $use_sessions = true;
  106. ak_test('DefaultTestCase', $use_sessions);
  107. ?>