1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Salsify\Tests\Model\Mapper; |
4
|
|
|
|
5
|
|
|
use Dynamic\Salsify\Model\Fetcher; |
6
|
|
|
use Dynamic\Salsify\Model\Mapper; |
7
|
|
|
use \InvalidArgumentException; |
8
|
|
|
use Dynamic\Salsify\Model\Importer; |
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class ImporterTest |
14
|
|
|
* @package Dynamic\Salsify\Tests\Model\Mapper |
15
|
|
|
*/ |
16
|
|
|
class ImporterTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
public function testCanConstruct() { |
23
|
|
|
$importer = new Importer('test'); |
24
|
|
|
$this->assertInstanceOf(Importer::class, $importer); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
public function testGetImporterKey() { |
31
|
|
|
$importer = new Importer('test'); |
32
|
|
|
$this->assertEquals('test', $importer->getImporterKey()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
public function testImportKeyNotString() { |
39
|
|
|
$importer = new Importer('test'); |
40
|
|
|
$this->expectException(InvalidArgumentException::class); |
41
|
|
|
/** @noinspection PhpParamsInspection */ |
42
|
|
|
$importer->setImporterKey(array()); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
public function testImportKeyNotEmpty() { |
49
|
|
|
$importer = new Importer('test'); |
50
|
|
|
$this->expectException(InvalidArgumentException::class); |
51
|
|
|
$importer->setImporterKey(''); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* |
56
|
|
|
*/ |
57
|
|
|
public function testImportKeyContainsInvalidCharacters() { |
58
|
|
|
$importer = new Importer('test'); |
59
|
|
|
$this->expectException(InvalidArgumentException::class); |
60
|
|
|
$importer->setImporterKey('test@'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
public function testCreateServicesFetcher() { |
67
|
|
|
$this->assertFalse(Injector::inst()->has(Fetcher::class . '.test')); |
68
|
|
|
|
69
|
|
|
$importer = new Importer('test'); |
70
|
|
|
$importer->createServices(); |
71
|
|
|
$this->assertTrue(Injector::inst()->has(Fetcher::class . '.test')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
*/ |
77
|
|
|
public function testCreateServicesMapper() { |
78
|
|
|
$this->assertFalse(Injector::inst()->has(Mapper::class . '.test')); |
79
|
|
|
|
80
|
|
|
$importer = new Importer('test'); |
81
|
|
|
$importer->createServices(); |
82
|
|
|
$this->assertTrue(Injector::inst()->has(Mapper::class . '.test')); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|