CurrencyLibTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $this->out('<h2>Currency Table</h2>', true);
  47. $is = $this->CurrencyLib->table();
  48. $this->debug($is);
  49. $this->assertTrue(is_array($is) && !empty($is));
  50. $is = $this->CurrencyLib->table('XYZ');
  51. $this->assertFalse($is);
  52. $this->assertTrue($this->CurrencyLib->cacheFileUsed());
  53. }
  54. /**
  55. * CurrencyLibTest::testReset()
  56. *
  57. * @return void
  58. */
  59. public function testReset() {
  60. $res = $this->CurrencyLib->reset();
  61. $this->assertTrue($res === null || $res === true);
  62. }
  63. }
  64. class TestCurrencyLib extends CurrencyLib {
  65. protected function _loadXml($url) {
  66. if (php_sapi_name() !== 'cli' && !empty($_GET) && !empty($_GET['debug'])) {
  67. debug('Live Data!');
  68. return parent::_loadXml($url);
  69. }
  70. $file = basename($url);
  71. $url = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'xml' . DS . $file;
  72. return parent::_loadXml($url);
  73. }
  74. }