Skip to content
Snippets Groups Projects
Commit 6fea92d5 authored by Roger Codina's avatar Roger Codina
Browse files

Add test and reduce comment lenght

parent 20a9fc02
No related branches found
No related tags found
1 merge request!83Issue #1615520: Add translatable config_simple_example
......@@ -2,7 +2,7 @@
/**
* @file
* Demonstrates how to create a custom config, config form and config translation.
* Demonstrates how to create a translatable custom configuration form.
*/
/**
......
<?php
namespace Drupal\Tests\form_api_example\Functional;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
/**
* Ensure that the form_api_example forms work properly.
*
* @group config_simple_example
* @group examples
*
* @ingroup form_api_example
*/
class ConfigExampleTest extends ExamplesBrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Our module dependencies.
*
* @var string[]
*/
protected static $modules = [
'language',
'locale',
'config_simple_example',
];
/**
* The installation profile to use with this test.
*
* @var string
*/
protected $profile = 'minimal';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// We need more language than default English.
$language = ConfigurableLanguage::createFromLangcode('es');
$language->save();
}
/**
* Aggregate all the tests.
*
* Since this is a functional test, and we don't expect to need isolation
* between these form tests, we'll aggregate them here for speed's sake. That
* way the testing system doesn't have to rebuild a new Drupal for us for each
* test.
*/
public function testFunctional() {
// Please fail this one first.
$this->doTestMainPage();
$this->doTestConfigSimpleForm();
}
/**
* Test the main page.
*/
public function doTestMainPage() {
$assert = $this->assertSession();
$example_page = Url::fromRoute('config_simple_example.description');
$this->drupalGet($example_page);
$assert->pageTextContains('The Config Simple Example module defines a simple translatable config form.');
$assert->linkExists('Config Simple Form');
}
/**
* Test the config simple form.
*/
public function doTestConfigSimpleForm() {
$assert = $this->assertSession();
$config_page = Url::fromRoute('config_simple_example.settings');
$this->drupalGet($config_page);
$assert->fieldEnabled('edit-message');
$assert->buttonExists('edit-submit');
// Ensure the 'Save configuration' action performs the save.
$this->drupalGet($config_page);
$edit = [
'message' => 'Message in EN',
];
$this->submitForm($edit, 'Save configuration');
$assert->pageTextContains('Message in EN');
// Go to Spanish version.
$es_lang_object = \Drupal::languageManager()->getLanguage('es');
$config_page_es = Url::fromRoute('config_simple_example.settings', [], ['language' => $es_lang_object]);
$this->drupalGet($config_page_es);
$assert->fieldEnabled('edit-message');
$assert->buttonExists('edit-submit');
// Ensure the 'Save configuration' action performs the save.
$this->drupalGet($config_page);
$edit = [
'message' => 'Message in ES',
];
$this->submitForm($edit, 'Save configuration');
$assert->pageTextContains('Message in ES');
// Go back to original English version.
$this->drupalGet($config_page);
$assert->pageTextContains('Message in EN');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment