2017-07-15 14:20:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Manifest\VersionProvider;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
|
|
|
class VersionProviderTest extends SapphireTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var VersionProvider
|
|
|
|
*/
|
|
|
|
protected $provider;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->provider = new VersionProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetModules()
|
|
|
|
{
|
2017-07-16 00:16:21 +02:00
|
|
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
2017-07-15 14:20:37 +02:00
|
|
|
'silverstripe/somepackage' => 'Some Package',
|
|
|
|
'silverstripe/hidden' => '',
|
|
|
|
'silverstripe/another' => 'Another'
|
2017-07-16 00:16:21 +02:00
|
|
|
]);
|
2017-07-15 14:20:37 +02:00
|
|
|
|
|
|
|
$result = $this->provider->getModules();
|
|
|
|
$this->assertArrayHasKey('silverstripe/somepackage', $result);
|
|
|
|
$this->assertSame('Some Package', $result['silverstripe/somepackage']);
|
|
|
|
$this->assertArrayHasKey('silverstripe/another', $result);
|
|
|
|
$this->assertArrayNotHasKey('silverstripe/hidden', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetModuleVersionFromComposer()
|
|
|
|
{
|
2017-07-16 00:16:21 +02:00
|
|
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
2017-07-15 14:20:37 +02:00
|
|
|
'silverstripe/framework' => 'Framework',
|
|
|
|
'silverstripe/siteconfig' => 'SiteConfig'
|
2017-07-16 00:16:21 +02:00
|
|
|
]);
|
2017-07-15 14:20:37 +02:00
|
|
|
|
2017-07-16 00:16:21 +02:00
|
|
|
$result = $this->provider->getModules(['silverstripe/framework']);
|
2017-07-15 14:20:37 +02:00
|
|
|
$this->assertArrayHasKey('silverstripe/framework', $result);
|
|
|
|
$this->assertNotEmpty($result['silverstripe/framework']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetVersion()
|
|
|
|
{
|
2017-07-16 00:16:21 +02:00
|
|
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
2017-07-15 14:20:37 +02:00
|
|
|
'silverstripe/framework' => 'Framework',
|
|
|
|
'silverstripe/siteconfig' => 'SiteConfig'
|
2017-07-16 00:16:21 +02:00
|
|
|
]);
|
2017-07-15 14:20:37 +02:00
|
|
|
|
|
|
|
$result = $this->provider->getVersion();
|
|
|
|
$this->assertContains('SiteConfig: ', $result);
|
|
|
|
$this->assertContains('Framework: ', $result);
|
|
|
|
$this->assertContains(', ', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetModulesFromComposerLock()
|
|
|
|
{
|
|
|
|
$mock = $this->getMockBuilder(VersionProvider::class)
|
2017-07-16 00:16:21 +02:00
|
|
|
->setMethods(['getComposerLock'])
|
2017-07-15 14:20:37 +02:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mock->expects($this->once())
|
|
|
|
->method('getComposerLock')
|
2017-07-16 00:16:21 +02:00
|
|
|
->will($this->returnValue([
|
|
|
|
'packages' => [
|
|
|
|
[
|
2017-07-15 14:20:37 +02:00
|
|
|
'name' => 'silverstripe/somepackage',
|
|
|
|
'version' => '1.2.3'
|
2017-07-16 00:16:21 +02:00
|
|
|
],
|
|
|
|
[
|
2017-07-15 14:20:37 +02:00
|
|
|
'name' => 'silverstripe/another',
|
|
|
|
'version' => '2.3.4'
|
2017-07-16 00:16:21 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]));
|
2017-07-15 14:20:37 +02:00
|
|
|
|
2017-07-16 00:16:21 +02:00
|
|
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
2017-07-15 14:20:37 +02:00
|
|
|
'silverstripe/somepackage' => 'Some Package'
|
2017-07-16 00:16:21 +02:00
|
|
|
]);
|
2017-07-15 14:20:37 +02:00
|
|
|
|
|
|
|
$result = $mock->getVersion();
|
|
|
|
$this->assertContains('Some Package: 1.2.3', $result);
|
|
|
|
}
|
|
|
|
}
|