clearCache(); } public function getProvider() { $provider = Injector::inst()->get(VersionProvider::class); return $provider; } public function testGetModules() { Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/mypackage' => 'My Package', 'silverstripe/somepackage' => 'Some Package', 'silverstripe/another' => 'Another', 'cwp/cwp-something' => 'CWP something', ]); $result = $this->getProvider()->getModules(); $this->assertArrayHasKey('silverstripe/mypackage', $result); $this->assertArrayHasKey('silverstripe/somepackage', $result); $this->assertArrayHasKey('silverstripe/another', $result); $this->assertArrayHasKey('cwp/cwp-something', $result); } public function testGetModulesEmpty() { Config::modify()->set(VersionProvider::class, 'modules', []); $this->assertEquals( ['silverstripe/framework' => 'Framework'], $this->getProvider()->getModules() ); } public function testGetModulesNone() { Config::modify()->remove(VersionProvider::class, 'modules'); $this->assertEquals( ['silverstripe/framework' => 'Framework'], $this->getProvider()->getModules() ); } public function testGetModuleVersionFromComposer() { Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/siteconfig' => 'SiteConfig', 'silverstripe/framework' => 'Framework', ]); $result = $this->getProvider()->getModules(['silverstripe/framework']); $this->assertArrayHasKey('silverstripe/framework', $result); $this->assertNotEmpty($result['silverstripe/framework']); } public function testGetVersion() { Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/siteconfig' => 'SiteConfig', 'silverstripe/framework' => 'Framework' ]); $result = $this->getProvider()->getVersion(); $this->assertStringNotContainsString('SiteConfig: ', $result); $this->assertStringContainsString('Framework: ', $result); $this->assertStringNotContainsString(', ', $result); } public function testGetModuleVersion() { $provider = $this->getProvider(); Config::modify()->set(VersionProvider::class, 'modules', [ 'silverstripe/framework' => 'Framework', ]); $moduleVersion = $provider->getModuleVersion('silverstripe/framework'); $parser = new VersionParser(); $this->assertIsString($parser->normalize($moduleVersion), "Expected a valid semver but got $moduleVersion"); $result = $provider->getVersion(); $this->assertStringNotContainsString('Framework: 1.2.3', $result); } private function clearCache() { $cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider'); $cache->clear(); } }