View source
<?php
namespace Drupal\Tests\composer_manager\Unit;
use Drupal\composer_manager\ExtensionDiscovery;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
class ExtensionDiscoveryTest extends UnitTestCase {
protected $discovery;
public function setUp() {
parent::setUp();
$structure = [
'modules' => [
'test1' => $this
->generateModule('test1'),
],
'profiles' => [
'commons' => [
'commons.info.yml' => 'type: profile',
'commons.profile' => '<?php',
'modules' => [
'test2' => $this
->generateModule('test2'),
],
],
],
'sites' => [
'all' => [
'modules' => [
'test3' => $this
->generateModule('test3'),
],
],
'default' => [
'modules' => [
'test4' => $this
->generateModule('test4'),
],
],
'test.site.com' => [
'profiles' => [
'commerce_kickstart' => [
'commerce_kickstart.info.yml' => 'type: profile',
'commerce_kickstart.profile' => '<?php',
'modules' => [
'test5' => $this
->generateModule('test5'),
],
],
],
'modules' => [
'test6' => $this
->generateModule('test6'),
],
],
],
];
vfsStream::setup('drupal', null, $structure);
$this->discovery = new ExtensionDiscovery('vfs://drupal');
}
public function tearDown() {
$this->discovery
->resetCache();
}
public function testScan() {
$expected_profiles = [
'commons',
'commerce_kickstart',
];
$profiles = $this->discovery
->scan('profile');
$this
->assertEquals($expected_profiles, array_keys($profiles));
$expected_extensions = [
'test5',
'test2',
'test3',
'test1',
'test4',
'test6',
];
$profile_directories = array_map(function ($profile) {
return $profile
->getPath();
}, $profiles);
$this->discovery
->setProfileDirectories($profile_directories);
$extensions = $this->discovery
->scan('module');
$this
->assertEquals($expected_extensions, array_keys($extensions));
}
protected function generateModule($name) {
return [
$name . '.module' => '<?php',
$name . '.info.yml' => 'type: module',
];
}
}