Skip to content

Commit

Permalink
fix drupal 10.2 testing conditions
Browse files Browse the repository at this point in the history
WengerK committed Feb 21, 2024
1 parent 6640428 commit e275cbe
Showing 2 changed files with 48 additions and 12 deletions.
17 changes: 15 additions & 2 deletions tests/src/Functional/HelpPageTest.php
Original file line number Diff line number Diff line change
@@ -36,8 +36,21 @@ class HelpPageTest extends BrowserTestBase {
protected function setUp(): void {
parent::setUp();

// Since Drupal 10.2 accessing help page require a new permission.
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
$permissions = [
'access administration pages',
'access help pages',
];
}
else {
$permissions = [
'access administration pages',
];
}

// Create a user for tests.
$admin_user = $this->drupalCreateUser(['access administration pages']);
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
}

@@ -48,7 +61,7 @@ protected function setUp(): void {
* displayed.
*/
public function testHelp(): void {
$this->drupalGet('admin/help/template_whisperer');
$this->drupalGet('/admin/help/template_whisperer');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The module uses is own field and his own entity to generate more suggestions for your selected nodes.');
$this->assertSession()->linkExists('suggestion');
43 changes: 33 additions & 10 deletions tests/src/Functional/UiFieldTest.php
Original file line number Diff line number Diff line change
@@ -105,23 +105,46 @@ public function testAddField() {
$this->clickLink('Add field');
}

$this->fillField('Add a new field', 'template_whisperer');
// Add the Template Whisperer field.
// Since Drupal 10.2 the field type has been changed from select to radio.
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
$this->assertSession()->elementExists('css', "[name='new_storage_type'][value='template_whisperer']");
$this->getSession()->getPage()->selectFieldOption('new_storage_type', 'template_whisperer');
}
else {
$this->fillField('Add a new field', 'template_whisperer');
}

$this->fillField('Label', 'Template Whisperer');
$this->fillField('Machine-readable name', 'template_whisperer');
$this->pressButton('Save and continue');

// Since Drupal 10.2 the submit button text changed.
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
$this->pressButton('Continue');
}
else {
$this->pressButton('Save and continue');
}
$this->assertSession()->statusCodeEquals(200);

// Check the cardinality.
$this->assertSession()->pageTextContains("These settings apply to the Template Whisperer field everywhere it is used.");
$this->pressButton('Save field settings');
$this->assertSession()->statusCodeEquals(200);

// Finalize the field.
$this->assertSession()->pageTextContains('Updated field Template Whisperer field settings.');
$this->pressButton('Save settings');
$this->assertSession()->statusCodeEquals(200);

$this->assertSession()->pageTextContains('Saved Template Whisperer configuration.');
// Since Drupal 10.2 the storage page has been removed.
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
$this->pressButton('Save settings');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Saved Template Whisperer configuration.');
}
else {
$this->pressButton('Save field settings');
$this->assertSession()->statusCodeEquals(200);
// Finalize the field configuration.
$this->assertSession()->pageTextContains('Updated field Template Whisperer field settings.');
$this->pressButton('Save settings');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Saved Template Whisperer configuration.');
}
}

/**

0 comments on commit e275cbe

Please sign in to comment.