View source
<?php
namespace Drupal\Tests\agreement\Functional;
use Drupal\agreement\Entity\Agreement;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\user\Traits\UserCreationTrait;
class AgreementMultilingualTest extends AgreementTestBase {
use UserCreationTrait;
protected static $modules = [
'node',
'user',
'language',
'locale',
'config_translation',
'filter',
'views',
'agreement',
];
protected $spanishSpeaker;
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('es')
->save();
$this->spanishSpeaker = $this
->createUnprivilegedUser();
$this->spanishSpeaker
->set('preferred_langcode', 'es');
$this->spanishSpeaker
->save();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'access content',
'administer content types',
'administer filters',
'administer languages',
'access user profiles',
'bypass agreement',
'translate configuration',
]);
$this
->drupalLogin($this->adminUser);
$languageEdit = [
'language_interface[enabled][language-url]' => '1',
'language_interface[enabled][language-user]' => '1',
];
$this
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm($languageEdit, t('Save settings'));
$configEdit = [
'translation[config_names][agreement.agreement.default][settings][title]' => 'Nuestro acuerdo',
'translation[config_names][agreement.agreement.default][settings][checkbox]' => 'Estoy de acuerdo.',
'translation[config_names][agreement.agreement.default][settings][submit]' => 'Enviar',
'translation[config_names][agreement.agreement.default][settings][success]' => 'Gracias por aceptar nuestro acuerdo.',
'translation[config_names][agreement.agreement.default][settings][revoked]' => 'Ha revocado con éxito su aceptación de nuestro acuerdo.',
'translation[config_names][agreement.agreement.default][settings][failure]' => 'Debes aceptar nuestro acuerdo para continuar.',
'translation[config_names][agreement.agreement.default][agreement]' => 'Este es el texto del acuerdo.',
];
$this
->drupalGet('admin/config/people/agreement/manage/default/translate/es/add');
$this
->submitForm($configEdit, t('Save translation'));
$this
->drupalLogout();
}
public function testMultilingualAgreement() {
$this
->drupalLogin($this->spanishSpeaker);
$this
->assertStringEndsWith($this->agreement
->get('path'), $this
->getUrl(), 'URL is agreement page.');
$this
->assertSession()
->titleEquals('Nuestro acuerdo | Drupal');
$this
->assertSession()
->pageTextContains('Nuestro acuerdo');
$this
->assertSession()
->checkboxNotChecked('Estoy de acuerdo.');
$this
->assertSession()
->buttonExists('Enviar');
$this
->assertSession()
->pageTextContainsOnce('Este es el texto del acuerdo.');
$this
->assertNotAgreed($this->agreement);
$this
->assertAgreed($this->agreement);
}
public function assertAgreed(Agreement $agreement) {
$this
->drupalGet($agreement
->get('path'));
$this
->submitForm([
'agree' => 1,
], 'Enviar');
$this
->assertSession()
->pageTextContains('Gracias por aceptar nuestro acuerdo.');
$this
->assertNotAgreementPage($agreement);
}
public function assertNotAgreed(Agreement $agreement) {
$this
->drupalGet($agreement
->get('path'));
$this
->submitForm([], 'Enviar');
$this
->assertSession()
->pageTextContains('Debes aceptar nuestro acuerdo para continuar.');
}
}