ExcelReaderLibTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  3. App::uses('ExcelReaderLib', 'Tools.Lib');
  4. /**
  5. * testing basic functions
  6. * 2011-05-09 ms
  7. */
  8. class ExcelReaderLibTest extends MyCakeTestCase {
  9. public $ExcelReader;
  10. public function setUp() {
  11. parent::setUp();
  12. $this->ExcelReader = new ExcelReaderLib();
  13. }
  14. /**
  15. * Read binary data directly
  16. */
  17. public function readFromBlob() {
  18. $path = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'xls' . DS;
  19. $file = $path . 'excel_2000.xls';
  20. $content = file_get_contents($file);
  21. $this->ExcelReader->readFromBlob($content);
  22. $sheets = $this->ExcelReader->sheets();
  23. $this->assertSame(3, $sheets);
  24. $array = $this->ExcelReader->dumpToArray();
  25. $expected = array(
  26. array('A', 'B', 'C'),
  27. array('titleA', 'titleB', 'titleC'),
  28. );
  29. $this->assertSame($expected, $array);
  30. }
  31. /**
  32. * Currently the ExcelReader only works with Excel97/2000/XP etc
  33. * Not with any versions prio to that
  34. */
  35. public function testRead() {
  36. $path = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'xls' . DS;
  37. $file = $path . 'excel_2000.xls';
  38. $this->ExcelReader->read($file);
  39. $sheets = $this->ExcelReader->sheets();
  40. $this->assertSame(3, $sheets);
  41. $array = $this->ExcelReader->dumpToArray();
  42. $expected = array(
  43. array('A', 'B', 'C'),
  44. array('titleA', 'titleB', 'titleC'),
  45. );
  46. $this->assertSame($expected, $array);
  47. $array = $this->ExcelReader->dumpToArray(1);
  48. debug($array);
  49. $expected = array(
  50. array('A1', '0'),
  51. array('A2', '1'),
  52. array('A3', '2'),
  53. array('A4', '3'),
  54. );
  55. $this->assertSame($expected, $array);
  56. $array = $this->ExcelReader->dumpToArray(2);
  57. $expected = array(
  58. );
  59. $this->assertSame($expected, $array);
  60. $file = $path . 'excel_1995.xls';
  61. //TODO
  62. }
  63. }