|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CWP\Core\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use CWP\Core\Extension\CWPVersionExtension; |
|
6
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
7
|
|
|
use SilverStripe\Admin\LeftAndMain; |
|
8
|
|
|
use SilverStripe\Core\Manifest\VersionProvider; |
|
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
10
|
|
|
|
|
11
|
|
|
class CWPVersionExtensionTest extends SapphireTest |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var VersionProvider|PHPUnit_Framework_MockObject_MockObject |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $versionProvider; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var LeftAndMain|PHPUnit_Framework_MockObject_MockObject |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $leftAndMain; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
|
|
27
|
|
|
$this->versionProvider = $this->createMock(VersionProvider::class); |
|
28
|
|
|
$this->leftAndMain = $this->createMock(LeftAndMain::class); |
|
29
|
|
|
|
|
30
|
|
|
$this->leftAndMain |
|
31
|
|
|
->expects($this->atLeastOnce()) |
|
32
|
|
|
->method('getVersionProvider') |
|
33
|
|
|
->willReturn($this->versionProvider); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $modules |
|
38
|
|
|
* @param string $expected |
|
39
|
|
|
* @dataProvider getVersionProvider |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testGetVersion($modules, $expected) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->versionProvider->expects($this->once()) |
|
44
|
|
|
->method('getModuleVersionFromComposer') |
|
45
|
|
|
->willReturn($modules); |
|
46
|
|
|
|
|
47
|
|
|
$extension = new CWPVersionExtension(); |
|
48
|
|
|
$extension->setOwner($this->leftAndMain); |
|
49
|
|
|
|
|
50
|
|
|
$result = $extension->getCWPVersionNumber(); |
|
51
|
|
|
$this->assertSame($expected, $result); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getVersionProvider() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
'dev version' => [['cwp/cwp-core' => '2.3.x-dev'], '2.3'], |
|
61
|
|
|
'stable version' => [['cwp/cwp-core' => '2.2.0'], '2.2'], |
|
62
|
|
|
'not found' => [[], ''], |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|