ExcelFileTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. include_once 'classes/TestImport.php';
  3. include_once 'classes/TestImportHandler.php';
  4. include_once 'classes/TestFile.php';
  5. include_once 'classes/TestFileHandler.php';
  6. class ExcelFileTest extends TestCase {
  7. public function testInit()
  8. {
  9. $importer = app('TestImport');
  10. $this->assertInstanceOf('Maatwebsite\Excel\Files\ExcelFile', $importer);
  11. }
  12. public function testGetFile()
  13. {
  14. $importer = app('TestImport');
  15. $file = $importer->getFile();
  16. $exploded = explode('/',$file);
  17. $filename = end($exploded);
  18. $this->assertEquals('test.csv', $filename);
  19. }
  20. public function testGetFilters()
  21. {
  22. $importer = app('TestImport');
  23. $this->assertContains('chunk', $importer->getFilters());
  24. $this->assertContains('chunk', $importer->getFileInstance()->filters['enabled']);
  25. }
  26. public function testLoadFile()
  27. {
  28. $importer = app('TestImport');
  29. $importer->loadFile();
  30. $this->assertInstanceOf('Maatwebsite\Excel\Readers\LaravelExcelReader', $importer->getFileInstance());
  31. }
  32. public function testGetResultsDirectly()
  33. {
  34. $importer = app('TestImport');
  35. $results = $importer->get();
  36. $this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
  37. $this->assertCount(5, $results);
  38. }
  39. public function testImportHandler()
  40. {
  41. $importer = app('TestImport');
  42. $results = $importer->handleImport();
  43. $this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
  44. $this->assertCount(5, $results);
  45. $importer = app('TestFile');
  46. $results = $importer->handleImport();
  47. $this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
  48. $this->assertCount(5, $results);
  49. }
  50. }