Functional


1. Setup

2. UI Tests

2.1 Text

// Checks for text "Test fetcher" is on current page.
$this->assertSession()->pageTextContains('Test fetcher');

// Checks for text "Test fetcher" is NOT on current page.
$this->assertSession()->pageTextNotContains('Test fetcher');

// Checks for regular expression pattern match.
$this->assertSession()->pageTextMatches('/[0-9]{10}/');

// 
$this->assertSession()->pageTextNotMatches('/[0-9]{5}/');

2.2 HTML

// Check HTML content.
$this->assertSession()->responseContains();

2.2 Field

// Check for a field by id or name or label
$this->assertSession()->fieldExists('aggregator_allowed_html_tags')

2.3 Button

// Check for a button by id or name or label
$this->assertSession()->buttonExists('Submit')

2.4 Summary

  /**
   * Tests the settings form to ensure the correct default values are used.
   */
  public function testSettingsPage() {
    // Visit a page
    $this->drupalGet('admin/config');

    // Click a link on a page.
    $this->clickLink('Aggregator');
    $this->clickLink('Settings');

    // Check for text.
    $this->assertSession()->pageTextContains('Test fetcher');
    $this->assertSession()->pageTextContains('Test parser');
    $this->assertSession()->pageTextContains('Test processor');

    // Check for a field by id or name or label
    $this->assertSession()->fieldExists('aggregator_allowed_html_tags')

    // Check for a button by id or name or label
    $this->assertSession()->buttonExists('Submit')
  }

3. Behavior Tests

3.1 Validation

   // Try to submit with invalid value.
    $edit = [
      'total_count' => 'invalid string',
    ];
    $this->drupalPostForm('admin/config/services/aggregator/settings', $edit, t('Save configuration'));

    // Check for error message.
    $this->assertSession()->pageTextContains('Total count should be an integer.');

3.2 Submit

    // Set new values and enable test plugins.
    $edit = [
      'aggregator_allowed_html_tags' => '<a>',
      'aggregator_summary_items' => 10,
      'aggregator_clear' => 3600,
      'aggregator_teaser_length' => 200,
      'aggregator_fetcher' => 'aggregator_test_fetcher',
      'aggregator_parser' => 'aggregator_test_parser',
      'aggregator_processors[aggregator_test_processor]' => 'aggregator_test_processor',
    ];
    $this->drupalPostForm('admin/config/services/aggregator/settings', $edit, 'Save configuration');
    $this->assertText('The configuration options have been saved.');

Note:

  1. It is a good idea to make sure new values are saved after submit by asserting like in display section above.

4. Reference

  1. AggregatorAdminTest
  2. ResponsiveImageAdminUITest

results matching ""

    No results matching ""