1
|
|
|
<?php |
2
|
|
|
namespace Mathielen\ImportEngine\Storage\Format\Discovery; |
3
|
|
|
|
4
|
|
|
use Mathielen\ImportEngine\Storage\Format\CompressedFormat; |
5
|
|
|
use Mathielen\ImportEngine\Storage\Format\CsvFormat; |
6
|
|
|
use Mathielen\ImportEngine\Storage\Format\ExcelFormat; |
7
|
|
|
use Mathielen\ImportEngine\Storage\Format\XmlFormat; |
8
|
|
|
use Mathielen\ImportEngine\ValueObject\StorageSelection; |
9
|
|
|
|
10
|
|
|
class FileExtensionDiscoverStrategyTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private $discoverStrategy; |
14
|
|
|
|
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->discoverStrategy = new FileExtensionDiscoverStrategy( |
18
|
|
|
array() |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @dataProvider getDefaultExtensions |
24
|
|
|
*/ |
25
|
|
|
public function testDefaultExtensions($ext, $expectedFormat) |
26
|
|
|
{ |
27
|
|
|
$actualFormat = $this->discoverStrategy->getFormat($ext); |
28
|
|
|
|
29
|
|
|
$this->assertEquals($expectedFormat, $actualFormat); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getDefaultExtensions() |
33
|
|
|
{ |
34
|
|
|
return array( |
35
|
|
|
//array('application/zip text/[email protected]', new CompressedFormat('subfile.csv', 'zip', new CsvFormat())), |
36
|
|
|
array(new StorageSelection(null, 'file.zip'), new CompressedFormat()), |
37
|
|
|
array(new StorageSelection(null, 'file.csv'), new CsvFormat()), |
38
|
|
|
array(new StorageSelection(null, 'file.txt'), new CsvFormat()), |
39
|
|
|
array(new StorageSelection(null, 'file.xls'), new ExcelFormat()), |
40
|
|
|
array(new StorageSelection(null, 'file.xlsx'), new ExcelFormat()), |
41
|
|
|
array(new StorageSelection(null, 'file.xml'), new XmlFormat()), |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @expectedException \Mathielen\ImportEngine\Exception\InvalidConfigurationException |
47
|
|
|
*/ |
48
|
|
|
public function testInvalidExt() |
49
|
|
|
{ |
50
|
|
|
$this->discoverStrategy->getFormat(new StorageSelection(null, 'uri')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testExtFormatFactories() |
54
|
|
|
{ |
55
|
|
|
$formatFactory = $this->createMock('Mathielen\ImportEngine\Storage\Format\Factory\FormatFactoryInterface'); |
56
|
|
|
$formatFactory |
57
|
|
|
->expects($this->once()) |
58
|
|
|
->method('factor') |
59
|
|
|
->with('uri/uri.ext') |
60
|
|
|
->will($this->returnValue('myFormat')); |
61
|
|
|
$this->discoverStrategy->addFormatFactory('ext', $formatFactory); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('myFormat', $this->discoverStrategy->getFormat(new StorageSelection(null, 'uri/uri.ext'))); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|