ChineseXlsReaderTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. use Mockery as m;
  3. use Maatwebsite\Excel\Readers\LaravelExcelReader;
  4. use Maatwebsite\Excel\Classes;
  5. class ChineseXlsReaderTest extends TestCase {
  6. /**
  7. * Test csv file
  8. * @var [type]
  9. */
  10. protected $xls;
  11. /**
  12. * Loaded csv file
  13. * @var [type]
  14. */
  15. protected $loadedXls;
  16. /**
  17. * Setup
  18. */
  19. public function setUp()
  20. {
  21. parent::setUp();
  22. // Disable to ascii
  23. Config::set('excel.import.to_ascii', false);
  24. // Set excel class
  25. $this->excel = App::make('phpexcel');
  26. // Set writer class
  27. $this->reader = App::make('excel.reader');
  28. $this->reader->injectExcel($this->excel);
  29. // Load csv file
  30. $this->loadChineseXls();
  31. }
  32. /**
  33. * Test loading a csv file
  34. * @return [type] [description]
  35. */
  36. public function testloadChineseXls()
  37. {
  38. $this->assertEquals($this->reader, $this->loadedXls);
  39. $this->assertInstanceOf('PHPExcel', $this->reader->getExcel());
  40. }
  41. /**
  42. * Test get
  43. * @return [type] [description]
  44. */
  45. public function testGet()
  46. {
  47. $got = $this->loadedXls->get();
  48. $this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
  49. $this->assertCount(2, $got);
  50. }
  51. /**
  52. * Test toArray
  53. * @return [type] [description]
  54. */
  55. public function testToArray()
  56. {
  57. $array = $this->loadedXls->toArray();
  58. $this->assertEquals(array(
  59. array(
  60. '商品編號' => 'L01A01SY047',
  61. '商品名稱' => 'LED T8燈管',
  62. '實際數量' => 1,
  63. ),
  64. array(
  65. '商品編號' => 'L01A01SY046',
  66. '商品名稱' => 'LED T8燈管',
  67. '實際數量' => 1,
  68. )
  69. ), $array);
  70. }
  71. /**
  72. * Load a csv file
  73. * @return [type] [description]
  74. */
  75. protected function loadChineseXls()
  76. {
  77. // Set test csv file
  78. $this->xls = __DIR__ . '/files/' . 'chinese.xls';
  79. // Loaded csv
  80. $this->loadedXls = $this->reader->load($this->xls);
  81. }
  82. }