CurrencyLibTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. App::uses('CurrencyLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class CurrencyLibTest extends MyCakeTestCase {
  5. public function setUp() {
  6. parent::setUp();
  7. $this->CurrencyLib = new TestCurrencyLib();
  8. }
  9. /**
  10. * CurrencyLibTest::testStartReset()
  11. *
  12. * @return void
  13. */
  14. public function testStartReset() {
  15. $this->CurrencyLib->reset();
  16. }
  17. /**
  18. * CurrencyLibTest::testConvert()
  19. *
  20. * @return void
  21. */
  22. public function testConvert() {
  23. $this->out('<h2>30 EUR in USD</h2>', true);
  24. $is = $this->CurrencyLib->convert(30, 'EUR', 'USD');
  25. $this->debug($is);
  26. $this->assertTrue($is > 30 && $is < 60);
  27. $this->assertFalse($this->CurrencyLib->cacheFileUsed());
  28. }
  29. /**
  30. * CurrencyLibTest::testIsAvailable()
  31. *
  32. * @return void
  33. */
  34. public function testIsAvailable() {
  35. $is = $this->CurrencyLib->isAvailable('EUR');
  36. $this->assertTrue($is);
  37. $is = $this->CurrencyLib->isAvailable('XYZ');
  38. $this->assertFalse($is);
  39. }
  40. /**
  41. * CurrencyLibTest::testTable()
  42. *
  43. * @return void
  44. */
  45. public function testTable() {
  46. $is = $this->CurrencyLib->table();
  47. $this->assertTrue(is_array($is) && !empty($is));
  48. $is = $this->CurrencyLib->table('XYZ');
  49. $this->assertFalse($is);
  50. $this->assertTrue($this->CurrencyLib->cacheFileUsed());
  51. }
  52. public function testHistory() {
  53. $is = $this->CurrencyLib->history();
  54. $this->assertTrue(is_array($is) && !empty($is));
  55. }
  56. /**
  57. * CurrencyLibTest::testReset()
  58. *
  59. * @return void
  60. */
  61. public function testReset() {
  62. $res = $this->CurrencyLib->reset();
  63. $this->assertTrue($res === null || $res === true);
  64. }
  65. }
  66. class TestCurrencyLib extends CurrencyLib {
  67. protected function _loadXml($url) {
  68. if (php_sapi_name() !== 'cli' && !empty($_GET) && !empty($_GET['debug'])) {
  69. debug('Live Data!');
  70. return parent::_loadXml($url);
  71. }
  72. $file = basename($url);
  73. $url = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'xml' . DS . $file;
  74. return parent::_loadXml($url);
  75. }
  76. }