GenerateFormTest.php in Module Builder 8.3
File
tests/src/Functional/GenerateFormTest.php
View source
<?php
namespace Drupal\Tests\module_builder\Functional;
use Drupal\Tests\BrowserTestBase;
class GenerateFormTest extends BrowserTestBase {
protected $strictConfigSchema = FALSE;
protected $defaultTheme = 'stark';
public static $modules = [
'system',
'user',
'module_builder',
];
protected function setUp() {
parent::setUp();
$this->container
->get('module_installer')
->install([
'test_dummy_module_write_location',
]);
}
public function testMyTest() {
$page = $this
->getSession()
->getPage();
$account = $this
->createUser([
'create modules',
]);
$this
->drupalLogin($account);
$module = $this->container
->get('entity_type.manager')
->getStorage('module_builder_module')
->create([
'id' => 'my_module',
'name' => 'My Module',
'data' => [],
]);
$module
->save();
$this
->drupalGet('admin/config/development/module_builder/manage/my_module/generate');
$page
->pressButton('Write all files');
$site_path = \Drupal::service('site.path');
$this
->assertFileExists($site_path . '/my_module/my_module.info.yml');
$this
->assertSession()
->pageTextMatches('@Written 1 files to folder sites/simpletest/\\d+/my_module@');
$module->data = [
'hooks' => [
'hook_help',
'hook_install',
],
];
$module
->save();
$this
->drupalGet('admin/config/development/module_builder/manage/my_module/generate');
$page
->checkField('filename_list[my_module.module]');
$page
->pressButton('Write selected files');
$this
->assertFileExists($site_path . '/my_module/my_module.module');
$this
->assertFileNotExists($site_path . '/my_module/my_module.install');
$this
->assertSession()
->pageTextMatches('@Written 1 files to folder sites/simpletest/\\d+/my_module@');
file_put_contents($site_path . '/my_module/my_module.info.yml', 'CAKE');
file_put_contents($site_path . '/my_module/my_module.module', 'CAKE');
$page
->pressButton('Write new files');
$this
->assertSession()
->pageTextMatches('@Written 1 files to folder sites/simpletest/\\d+/my_module@');
$this
->assertFileExists($site_path . '/my_module/my_module.install');
$this
->assertEquals('CAKE', file_get_contents($site_path . '/my_module/my_module.info.yml'));
$this
->assertEquals('CAKE', file_get_contents($site_path . '/my_module/my_module.module'));
}
}