|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the limit0/assets package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Limit Zero, LLC <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Limit0\Assets\Tests\StorageEngine; |
|
13
|
|
|
|
|
14
|
|
|
use Limit0\Assets\AssetFactory; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Provides common tests for all storage engines |
|
18
|
|
|
* |
|
19
|
|
|
* @author Josh Worden <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractStorageEngineTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var \Limit0\Assets\StorageEngineInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected static $engine; |
|
27
|
|
|
|
|
28
|
|
|
public function testEngineSetUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertInstanceOf('Limit0\Assets\StorageEngineInterface', self::$engine, 'Storage engine was not set up before test.'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testEngineStorage() |
|
34
|
|
|
{ |
|
35
|
|
|
$result = self::$engine->store( |
|
36
|
|
|
$this->getTestAsset(), |
|
37
|
|
|
$this->getTestPath(), |
|
38
|
|
|
$this->getTestFilename() |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue($result, 'StorageEngine did not return a good value.'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testEngineRetrieval() |
|
45
|
|
|
{ |
|
46
|
|
|
$asset = self::$engine->retrieve($this->getTestIdentifier()); |
|
47
|
|
|
$this->assertInstanceOf('Limit0\Assets\Asset', $asset); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testFileContents() |
|
51
|
|
|
{ |
|
52
|
|
|
$asset = self::$engine->retrieve($this->getTestIdentifier()); |
|
53
|
|
|
$this->assertSame(file_get_contents($this->getTestAsset()), file_get_contents($asset), 'StorageEngine did not store file contents properly.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testEngineRemoval() |
|
57
|
|
|
{ |
|
58
|
|
|
$result = self::$engine->remove($this->getTestIdentifier()); |
|
59
|
|
|
$this->assertTrue($result, 'StorageEngine did not return a good value.'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function getTestAsset() |
|
63
|
|
|
{ |
|
64
|
|
|
$path = sprintf('%s/asset-management.test', sys_get_temp_dir()); |
|
65
|
|
|
file_put_contents($path, 'Lorem ipsum dolor sit amet.'); |
|
66
|
|
|
return AssetFactory::createFromPath($path); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function getTestPath() |
|
70
|
|
|
{ |
|
71
|
|
|
return 'test/directory/structure'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function getTestFilename() |
|
75
|
|
|
{ |
|
76
|
|
|
return 'asset-management.test'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function getTestIdentifier() |
|
80
|
|
|
{ |
|
81
|
|
|
return sprintf('%s/%s', $this->getTestPath(), $this->getTestFilename()); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|