1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* apparat-object |
5
|
|
|
* |
6
|
|
|
* @category Apparat |
7
|
|
|
* @package Apparat\Kernel |
8
|
|
|
* @subpackage Apparat\Kernel\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Apparat\Object\Tests; |
38
|
|
|
|
39
|
|
|
use Apparat\Object\Domain\Factory\AuthorFactory; |
40
|
|
|
use Apparat\Object\Domain\Model\Author\ApparatAuthor; |
41
|
|
|
use Apparat\Object\Domain\Model\Author\GenericAuthor; |
42
|
|
|
use Apparat\Object\Domain\Model\Author\InvalidAuthor; |
43
|
|
|
use Apparat\Object\Domain\Model\Path\ApparatInvalidArgumentException; |
44
|
|
|
use Apparat\Object\Domain\Model\Path\RepositoryPath; |
45
|
|
|
use Apparat\Object\Domain\Repository\Repository; |
46
|
|
|
use Apparat\Object\Infrastructure\Repository\FileAdapterStrategy; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Author tests |
50
|
|
|
* |
51
|
|
|
* @package Apparat\Kernel |
52
|
|
|
* @subpackage Apparat\Object\Tests |
53
|
|
|
*/ |
54
|
|
|
class AuthorTest extends AbstractTest |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Test repository |
58
|
|
|
* |
59
|
|
|
* @var Repository |
60
|
|
|
*/ |
61
|
|
|
protected static $repository = null; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Generic author string |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
const GENERIC_AUTHOR = 'John Doe <[email protected]> (http://doe.com)'; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Setup |
72
|
|
|
*/ |
73
|
|
|
public static function setUpBeforeClass() |
74
|
|
|
{ |
75
|
|
|
\Apparat\Object\Ports\Repository::register( |
76
|
|
|
getenv('REPOSITORY_URL'), [ |
77
|
|
|
'type' => FileAdapterStrategy::TYPE, |
78
|
|
|
'root' => __DIR__ . DIRECTORY_SEPARATOR . 'Fixture', |
79
|
|
|
] |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
self::$repository = \Apparat\Object\Ports\Repository::instance(getenv('REPOSITORY_URL')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Load an article and test an invalid author |
87
|
|
|
* |
88
|
|
|
* @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException |
89
|
|
|
* @expectedExceptionCode 1451425516 |
90
|
|
|
*/ |
91
|
|
|
public function testLoadArticleObjectInvalidAuthor() |
92
|
|
|
{ |
93
|
|
|
$articleObjectPath = new RepositoryPath(self::$repository, '/2016/02/16/4.article/4'); |
94
|
|
|
self::$repository->loadObject($articleObjectPath); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Test an invalid author format |
99
|
|
|
* |
100
|
|
|
* @expectedException \Apparat\Object\Domain\Model\Author\InvalidArgumentException |
101
|
|
|
* @expectedExceptionCode 1451426440 |
102
|
|
|
*/ |
103
|
|
|
public function testInvalidAuthorFormat() |
104
|
|
|
{ |
105
|
|
|
AuthorFactory::createFromString(''); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Test apparat author unserialization |
110
|
|
|
*/ |
111
|
|
|
public function testApparatAuthorUnserialization() { |
112
|
|
|
$this->assertInstanceOf(ApparatAuthor::class, ApparatAuthor::unserialize('/repo/2016/01/08/2.contact/2')); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Test the serialization of a generic author |
117
|
|
|
*/ |
118
|
|
|
public function testGenericAuthorSerialization() { |
119
|
|
|
$genericAuthor = GenericAuthor::unserialize(self::GENERIC_AUTHOR); |
120
|
|
|
$this->assertEquals(self::GENERIC_AUTHOR, $genericAuthor->serialize()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Test invalid author |
125
|
|
|
*/ |
126
|
|
|
public function testInvalidAuthor() { |
127
|
|
|
/** @var InvalidAuthor $invalidAuthor */ |
128
|
|
|
$invalidAuthor = AuthorFactory::createFromString('ftp://apparat.tools/2015/10/01/36704.event/36704-1'); |
129
|
|
|
$this->assertInstanceOf(InvalidAuthor::class, $invalidAuthor); |
130
|
|
|
$exception = $invalidAuthor->getException(); |
131
|
|
|
$this->assertInstanceOf(ApparatInvalidArgumentException::class, $exception); |
132
|
|
|
$this->assertEquals(ApparatInvalidArgumentException::INVALID_ABSOLUTE_APPARAT_URL, $exception->getCode()); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Test invalid author unserialization |
137
|
|
|
*/ |
138
|
|
|
public function testInvalidAuthorUnserialization() { |
139
|
|
|
/** @var InvalidAuthor $invalidAuthor */ |
140
|
|
|
$invalidAuthor = InvalidAuthor::unserialize('ftp://apparat.tools/2015/10/01/36704.event/36704-1'); |
141
|
|
|
$this->assertInstanceOf(InvalidAuthor::class, $invalidAuthor); |
142
|
|
|
$this->assertEquals(null, $invalidAuthor->getException()); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|