update 1.0.8.0

Commits for version update
This commit is contained in:
Manish Verma
2016-10-17 12:02:27 +05:30
parent dec927987b
commit 76e85db070
9674 changed files with 495757 additions and 58922 deletions

View File

@@ -0,0 +1,100 @@
<?php
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class ChineseXlsReaderTest extends TestCase {
/**
* Test csv file
* @var [type]
*/
protected $xls;
/**
* Loaded csv file
* @var [type]
*/
protected $loadedXls;
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Disable to ascii
Config::set('excel.import.to_ascii', false);
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
// Load csv file
$this->loadChineseXls();
}
/**
* Test loading a csv file
* @return [type] [description]
*/
public function testloadChineseXls()
{
$this->assertEquals($this->reader, $this->loadedXls);
$this->assertInstanceOf('PHPExcel', $this->reader->getExcel());
}
/**
* Test get
* @return [type] [description]
*/
public function testGet()
{
$got = $this->loadedXls->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(2, $got);
}
/**
* Test toArray
* @return [type] [description]
*/
public function testToArray()
{
$array = $this->loadedXls->toArray();
$this->assertEquals(array(
array(
'商品編號' => 'L01A01SY047',
'商品名稱' => 'LED T8燈管',
'實際數量' => 1,
),
array(
'商品編號' => 'L01A01SY046',
'商品名稱' => 'LED T8燈管',
'實際數量' => 1,
)
), $array);
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function loadChineseXls()
{
// Set test csv file
$this->xls = __DIR__ . '/files/' . 'chinese.xls';
// Loaded csv
$this->loadedXls = $this->reader->load($this->xls);
}
}

View File

@@ -0,0 +1,51 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class CsvReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.csv';
public function testSeparator()
{
$this->assertEquals('_', $this->loadedFile->getSeparator());
}
public function testSetSeparator()
{
$set = $this->loadedFile->setSeparator('-');
$this->assertEquals('-', $set->getSeparator());
}
public function testSetDelimiter()
{
$this->loadedFile->setDelimiter(';');
$this->reload();
$this->assertEquals(';', $this->loadedFile->getDelimiter());
}
public function testSetEnclosure()
{
$this->loadedFile->setEnclosure('d');
$this->reload();
$this->assertEquals('d', $this->loadedFile->getEnclosure());
}
}

View File

@@ -0,0 +1,106 @@
<?php
class CustomValuBinderTest extends TestCase {
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
$this->reader->noHeading(true);
// Set value binder
$binder = new StubValueBinder();
$this->reader->setValueBinder($binder);
// Load csv file
$this->loadFile();
}
/**
* Tear down
*/
public function tearDown()
{
// Necessary to reset the value binder back to default so that future test classes are unaffected.
$this->reader->resetValueBinder();
}
public function testDefaultGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(5, $got);
}
public function testNumeric()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[0][0]));
$this->assertEquals('00123', $got[0][0]);
}
public function testRealNull()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_null($got[1][0]));
$this->assertEquals('', $got[1][0]);
}
public function testStringNull()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[2][0]));
$this->assertEquals('null', $got[2][0]);
}
public function testEquation()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[3][0]));
$this->assertEquals('=1+2', $got[3][0]);
}
public function testBoolean()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[4][0]));
$this->assertEquals('true', $got[4][0]);
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function loadFile()
{
// Set test csv file
$file = __DIR__ . '/files/' . 'customBinder.csv';
// Loaded csv
$this->loadedFile = $this->reader->load($file);
}
}
class StubValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
public function bindValue(PHPExcel_Cell $cell, $value = null)
{
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
return true;
}
}

View File

@@ -0,0 +1,111 @@
<?php
require_once('traits/ImportTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class MultipleSheetsXlsReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/multiple.xls';
/**
* Test get
* @return [type] [description]
*/
public function testGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
}
/**
* Test get
* @return [type] [description]
*/
public function testGetAndGetFirstSheetName()
{
$got = $this->loadedFile->get();
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
// 5 rows
$this->assertCount(5, $sheet);
}
public function testSelectSheet()
{
$this->reader->setSelectedSheets('Sheet2');
$this->reload();
$sheet = $this->loadedFile->get();
$this->assertEquals('Sheet2', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectSheetByIndex()
{
$this->reader->setSelectedSheetIndices(array(1));
$this->reload();
$sheet = $this->loadedFile->get();
$this->assertEquals('Sheet2', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectMultipleSheets()
{
$this->reader->setSelectedSheets(array('Sheet1', 'Sheet2'));
$this->reload();
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectMultipleSheetsByIndex()
{
$this->reader->setSelectedSheetIndices(array(0,1));
$this->reload();
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
}

View File

@@ -0,0 +1,33 @@
<?php
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class ReaderTest extends TestCase {
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
}
/**
* Test the excel injection
* @return [type] [description]
*/
public function testExcelInjection()
{
$this->assertEquals($this->excel, $this->reader->getExcel());
}
}

View File

@@ -0,0 +1,23 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class XlsReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.xls';
}

View File

@@ -0,0 +1,23 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class XlsxReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.xlsx';
}

View File

@@ -0,0 +1,74 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
class ZerosHandlingReaderTest extends TestCase {
/**
* Traits
*/
use ImportTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/zeros.xls';
/**
* @var bool
*/
protected $noHeadings = false;
public function testDefaultGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(6, $got);
}
//
//public function testStringsAppendedPrependedWithZeros()
//{
// $got = $this->loadedFile->toArray();
//
// $this->assertContains('TEST000', $got[3]);
// $this->assertContains('000TEST', $got[4]);
//}
//
//
//public function testStringZeros()
//{
// $got = $this->loadedFile->toArray();
//
// $this->assertContains('000', $got[0]);
//}
public function testMoney()
{
$got = $this->loadedFile->toArray();
$this->assertContains((double) 0, $got[1]);
}
public function testEmptyCellHandling()
{
$got = $this->loadedFile->toArray();
$this->assertContains(null, $got[2]);
}
public function testNormalZeros()
{
$got = $this->loadedFile->toArray();
$this->assertContains((double) 0, $got[5]);
}
}

Binary file not shown.

View File

@@ -0,0 +1,5 @@
00123
null
=1+2
true
1 00123
2 null
3 =1+2
4 true

Binary file not shown.

View File

@@ -0,0 +1,6 @@
heading one,heading two,heading three
test,test,test
test,test,test
test,test,test
test,test,test
test,test,test
1 heading one heading two heading three
2 test test test
3 test test test
4 test test test
5 test test test
6 test test test

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,77 @@
<?php
trait ImportTrait {
/**
* Test csv file
* @var [type]
*/
protected $file;
/**
* Loaded csv file
* @var [type]
*/
protected $loadedFile;
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Set default heading
Config::set('excel.import.heading', 'slugged');
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
// Disable heading usage
if(isset($this->noHeadings) && $this->noHeadings)
$this->reader->noHeading(true);
// Load csv file
$this->loadFile();
}
/**
* Test loading a csv file
* @return [type] [description]
*/
public function testLoadFile()
{
$this->assertEquals($this->reader, $this->loadedFile);
$this->assertInstanceOf('PHPExcel', $this->reader->getExcel());
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function loadFile()
{
// Set test csv file
$this->file = __DIR__ . '/..' . DIRECTORY_SEPARATOR . $this->fileName;
// Loaded csv
$this->loadedFile = $this->reader->load($this->file);
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function reload()
{
// Set test csv file
$this->file = __DIR__ . '/..' . DIRECTORY_SEPARATOR . $this->fileName;
// Loaded csv
return $this->reader->load($this->file);
}
}

View File

@@ -0,0 +1,262 @@
<?php
trait SingleImportTestingTrait {
public function testGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(5, $got);
}
public function testGetWithColumns()
{
$columns = array('heading_one', 'heading_two');
$got = $this->loadedFile->get($columns);
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(5, $got);
}
public function testAll()
{
$all = $this->loadedFile->all();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $all);
$this->assertCount(5, $all);
}
public function testFirst()
{
$first = $this->loadedFile->first();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\CellCollection', $first);
// 3 columns
$this->assertCount(3, $first);
}
public function testFirstWithColumns()
{
$columns = array('heading_one', 'heading_two');
$first = $this->loadedFile->first($columns);
$this->assertInstanceOf('Maatwebsite\Excel\Collections\CellCollection', $first);
$this->assertCount(count($columns), $first);
}
public function testEach()
{
$me = $this;
$this->loadedFile->each(function($cells) use($me) {
$me->assertInstanceOf('Maatwebsite\Excel\Collections\CellCollection', $cells);
});
}
public function testToArray()
{
$array = $this->loadedFile->toArray();
$this->assertEquals(array(
array(
'heading_one' => 'test',
'heading_two' => 'test',
'heading_three' => 'test',
),
array(
'heading_one' => 'test',
'heading_two' => 'test',
'heading_three' => 'test',
),
array(
'heading_one' => 'test',
'heading_two' => 'test',
'heading_three' => 'test',
),
array(
'heading_one' => 'test',
'heading_two' => 'test',
'heading_three' => 'test',
),
array(
'heading_one' => 'test',
'heading_two' => 'test',
'heading_three' => 'test',
)
), $array);
}
public function testImportedHeadingsSlugged()
{
$first = $this->loadedFile->first()->toArray();
$keys = array_keys($first);
$this->assertEquals(array(
'heading_one',
'heading_two',
'heading_three'
), $keys);
}
public function testImportedHeadingsHashed()
{
Config::set('excel.import.heading', 'hashed');
$loaded = $this->reload();
$first = $loaded->first()->toArray();
$keys = array_keys($first);
$this->assertEquals(array(
md5('heading one'),
md5('heading two'),
md5('heading three')
), $keys);
}
public function testImportedHeadingsNumeric()
{
Config::set('excel.import.heading', 'numeric');
$loaded = $this->reload();
$first = $loaded->first()->toArray();
$keys = array_keys($first);
$this->assertEquals(array(
0,
1,
2
), $keys);
}
public function testImportedHeadingsOriginal()
{
Config::set('excel.import.heading', 'original');
$loaded = $this->reload();
$first = $loaded->first()->toArray();
$keys = array_keys($first);
$this->assertEquals(array(
'heading one',
'heading two',
'heading three'
), $keys);
}
public function testRemember()
{
$remembered = $this->loadedFile->remember(10);
$this->assertEquals($this->reader, $remembered);
$this->assertEquals(10, $remembered->cacheMinutes);
$this->assertTrue($remembered->remembered);
}
public function testByConfig()
{
$config = $this->loadedFile->byConfig('excel.import.sheets');
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $config);
}
public function testByConfigCallback()
{
$me = $this;
$config = $this->loadedFile->byConfig('excel.import.sheets', function($config) use($me)
{
$me->assertInstanceOf('Maatwebsite\Excel\Readers\ConfigReader', $config);
});
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $config);
}
public function testTake()
{
$taken = $this->loadedFile->take(2);
$this->assertEquals(2, $taken->getLimit());
$this->assertCount(2, $taken->get());
}
public function testSkip()
{
$taken = $this->loadedFile->skip(1);
$this->assertEquals(1, $taken->getSkip());
$this->assertCount(4, $taken->get());
}
public function testLimit()
{
$taken = $this->loadedFile->limit(2, 1);
$this->assertEquals(2, $taken->getLimit());
$this->assertEquals(1, $taken->getSkip());
$this->assertCount(2, $taken->get());
}
public function testSelect()
{
$columns = array('heading_one', 'heading_two');
$taken = $this->loadedFile->select($columns);
$this->assertEquals($columns, $taken->columns);
}
public function testSetDateFormat()
{
$set = $this->loadedFile->setDateFormat('Y-m-d');
$this->assertEquals('Y-m-d', $set->getDateFormat());
}
public function testFormatDates()
{
$set = $this->loadedFile->formatDates(true, 'Y-m-d');
$this->assertTrue($set->needsDateFormatting());
$this->assertEquals('Y-m-d', $set->getDateFormat());
}
public function testSetDateColumns()
{
$set = $this->loadedFile->setDateColumns('created_at', 'deleted_at');
$this->assertTrue($set->needsDateFormatting());
$this->assertEquals(array('created_at', 'deleted_at'), $set->getDateColumns());
}
public function testCalculate()
{
$set = $this->loadedFile->calculate();
$this->assertTrue($set->needsCalculation());
}
public function testIgnoreEmpty()
{
$set = $this->loadedFile->ignoreEmpty();
$this->assertTrue($set->needsIgnoreEmpty());
}
}