mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7175 from robbieaverill/pulls/4.0/version-provider
FIX Version provider uses non LSB config getters, move LeftAndMain config to admin module
This commit is contained in:
commit
4f095ea61d
@ -12,9 +12,6 @@ SilverStripe\Control\HTTP:
|
|||||||
must-revalidate: "true"
|
must-revalidate: "true"
|
||||||
no-transform: "true"
|
no-transform: "true"
|
||||||
vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept"
|
vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept"
|
||||||
LeftAndMain:
|
|
||||||
dependencies:
|
|
||||||
versionProvider: %$VersionProvider
|
|
||||||
SilverStripe\Core\Manifest\VersionProvider:
|
SilverStripe\Core\Manifest\VersionProvider:
|
||||||
modules:
|
modules:
|
||||||
silverstripe/framework: Framework
|
silverstripe/framework: Framework
|
||||||
|
@ -33,11 +33,11 @@ class VersionProvider
|
|||||||
{
|
{
|
||||||
$modules = $this->getModules();
|
$modules = $this->getModules();
|
||||||
$lockModules = $this->getModuleVersionFromComposer(array_keys($modules));
|
$lockModules = $this->getModuleVersionFromComposer(array_keys($modules));
|
||||||
$output = array();
|
$output = [];
|
||||||
foreach ($modules as $module => $title) {
|
foreach ($modules as $module => $title) {
|
||||||
$version = isset($lockModules[$module])
|
$version = isset($lockModules[$module])
|
||||||
? $lockModules[$module]
|
? $lockModules[$module]
|
||||||
: _t('SilverStripe\Core\Manifest\VersionProvider.VERSIONUNKNOWN', 'Unknown');
|
: _t(__CLASS__.'.VERSIONUNKNOWN', 'Unknown');
|
||||||
$output[] = $title . ': ' . $version;
|
$output[] = $title . ': ' . $version;
|
||||||
}
|
}
|
||||||
return implode(', ', $output);
|
return implode(', ', $output);
|
||||||
@ -51,8 +51,8 @@ class VersionProvider
|
|||||||
*/
|
*/
|
||||||
public function getModules()
|
public function getModules()
|
||||||
{
|
{
|
||||||
$modules = Config::inst()->get(static::class, 'modules');
|
$modules = Config::inst()->get(self::class, 'modules');
|
||||||
return $modules ? array_filter($modules) : array();
|
return $modules ? array_filter($modules) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,9 +61,9 @@ class VersionProvider
|
|||||||
* @param array $modules
|
* @param array $modules
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getModuleVersionFromComposer($modules = array())
|
public function getModuleVersionFromComposer($modules = [])
|
||||||
{
|
{
|
||||||
$versions = array();
|
$versions = [];
|
||||||
$lockData = $this->getComposerLock();
|
$lockData = $this->getComposerLock();
|
||||||
if ($lockData && !empty($lockData['packages'])) {
|
if ($lockData && !empty($lockData['packages'])) {
|
||||||
foreach ($lockData['packages'] as $package) {
|
foreach ($lockData['packages'] as $package) {
|
||||||
@ -85,10 +85,10 @@ class VersionProvider
|
|||||||
{
|
{
|
||||||
$composerLockPath = BASE_PATH . '/composer.lock';
|
$composerLockPath = BASE_PATH . '/composer.lock';
|
||||||
if (!file_exists($composerLockPath)) {
|
if (!file_exists($composerLockPath)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$lockData = array();
|
$lockData = [];
|
||||||
$jsonData = file_get_contents($composerLockPath);
|
$jsonData = file_get_contents($composerLockPath);
|
||||||
|
|
||||||
if ($cache) {
|
if ($cache) {
|
||||||
|
@ -21,11 +21,11 @@ class VersionProviderTest extends SapphireTest
|
|||||||
|
|
||||||
public function testGetModules()
|
public function testGetModules()
|
||||||
{
|
{
|
||||||
Config::modify()->set(VersionProvider::class, 'modules', array(
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||||
'silverstripe/somepackage' => 'Some Package',
|
'silverstripe/somepackage' => 'Some Package',
|
||||||
'silverstripe/hidden' => '',
|
'silverstripe/hidden' => '',
|
||||||
'silverstripe/another' => 'Another'
|
'silverstripe/another' => 'Another'
|
||||||
));
|
]);
|
||||||
|
|
||||||
$result = $this->provider->getModules();
|
$result = $this->provider->getModules();
|
||||||
$this->assertArrayHasKey('silverstripe/somepackage', $result);
|
$this->assertArrayHasKey('silverstripe/somepackage', $result);
|
||||||
@ -36,22 +36,22 @@ class VersionProviderTest extends SapphireTest
|
|||||||
|
|
||||||
public function testGetModuleVersionFromComposer()
|
public function testGetModuleVersionFromComposer()
|
||||||
{
|
{
|
||||||
Config::modify()->set(VersionProvider::class, 'modules', array(
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||||
'silverstripe/framework' => 'Framework',
|
'silverstripe/framework' => 'Framework',
|
||||||
'silverstripe/siteconfig' => 'SiteConfig'
|
'silverstripe/siteconfig' => 'SiteConfig'
|
||||||
));
|
]);
|
||||||
|
|
||||||
$result = $this->provider->getModules(array('silverstripe/framework'));
|
$result = $this->provider->getModules(['silverstripe/framework']);
|
||||||
$this->assertArrayHasKey('silverstripe/framework', $result);
|
$this->assertArrayHasKey('silverstripe/framework', $result);
|
||||||
$this->assertNotEmpty($result['silverstripe/framework']);
|
$this->assertNotEmpty($result['silverstripe/framework']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetVersion()
|
public function testGetVersion()
|
||||||
{
|
{
|
||||||
Config::modify()->set(VersionProvider::class, 'modules', array(
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||||
'silverstripe/framework' => 'Framework',
|
'silverstripe/framework' => 'Framework',
|
||||||
'silverstripe/siteconfig' => 'SiteConfig'
|
'silverstripe/siteconfig' => 'SiteConfig'
|
||||||
));
|
]);
|
||||||
|
|
||||||
$result = $this->provider->getVersion();
|
$result = $this->provider->getVersion();
|
||||||
$this->assertContains('SiteConfig: ', $result);
|
$this->assertContains('SiteConfig: ', $result);
|
||||||
@ -61,30 +61,28 @@ class VersionProviderTest extends SapphireTest
|
|||||||
|
|
||||||
public function testGetModulesFromComposerLock()
|
public function testGetModulesFromComposerLock()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Unable to get this passing');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(VersionProvider::class)
|
$mock = $this->getMockBuilder(VersionProvider::class)
|
||||||
->setMethods(array('getComposerLock'))
|
->setMethods(['getComposerLock'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('getComposerLock')
|
->method('getComposerLock')
|
||||||
->will($this->returnValue(array(
|
->will($this->returnValue([
|
||||||
'packages' => array(
|
'packages' => [
|
||||||
array(
|
[
|
||||||
'name' => 'silverstripe/somepackage',
|
'name' => 'silverstripe/somepackage',
|
||||||
'version' => '1.2.3'
|
'version' => '1.2.3'
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'name' => 'silverstripe/another',
|
'name' => 'silverstripe/another',
|
||||||
'version' => '2.3.4'
|
'version' => '2.3.4'
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
)));
|
]));
|
||||||
|
|
||||||
Config::modify()->set(VersionProvider::class, 'modules', array(
|
Config::modify()->set(VersionProvider::class, 'modules', [
|
||||||
'silverstripe/somepackage' => 'Some Package'
|
'silverstripe/somepackage' => 'Some Package'
|
||||||
));
|
]);
|
||||||
|
|
||||||
$result = $mock->getVersion();
|
$result = $mock->getVersion();
|
||||||
$this->assertContains('Some Package: 1.2.3', $result);
|
$this->assertContains('Some Package: 1.2.3', $result);
|
||||||
|
Loading…
Reference in New Issue
Block a user