public function ApiSettingsFormTest::testBuildForm in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/ApiSettingsFormTest.php \Drupal\Tests\fb_instant_articles\Functional\ApiSettingsFormTest::testBuildForm()
Test the various stages of form input for the API settings form.
File
- tests/
src/ Functional/ ApiSettingsFormTest.php, line 40
Class
- ApiSettingsFormTest
- Tests the FBIA API settings form.
Namespace
Drupal\Tests\fb_instant_articles\FunctionalCode
public function testBuildForm() {
$this
->drupalGet('/admin/config/services/fb_instant_articles/api_settings');
$this
->assertSession()
->statusCodeEquals(200);
// Initially we should show the App ID and App Secret fields.
$this
->assertSession()
->fieldExists('app_id');
$this
->assertSession()
->fieldExists('app_secret');
// Clicking Next right away should produce an error.
$this
->submitForm([], t('Next'));
$this
->assertSession()
->pageTextContains('You must enter the App ID before proceeding');
// Clicking Next with invalid input should produce an error.
$this
->submitForm([
'app_id' => 'invalid',
], t('Next'));
$this
->assertSession()
->pageTextContains('The App ID that you entered is invalid');
// Set valid values for app_id and app_secret.
$app_id = '1234';
$app_secret = 'secret';
$this
->submitForm([
'app_id' => $app_id,
'app_secret' => $app_secret,
], t('Next'));
$this
->drupalGet('/admin/config/services/fb_instant_articles/api_settings');
$this
->assertSession()
->pageTextContains('Your Facebook App ID is ' . $app_id);
// Clicking "Update Facebook app id." should allow us to change the app_id
// and secret again.
$this
->clickLink('Update Facebook app id');
$this
->assertSession()
->fieldExists('app_id');
$this
->assertSession()
->fieldExists('app_secret');
// Set an access_token and page_id in order to test the summary page.
$page_id = '1234';
\Drupal::configFactory()
->getEditable('fb_instant_articles.settings')
->set('page_id', $page_id)
->set('access_token', 'token')
->save();
$this
->drupalGet('/admin/config/services/fb_instant_articles/api_settings');
$this
->assertSession()
->pageTextContains('Your Facebook App ID is ' . $app_id);
$this
->assertSession()
->pageTextContains('Your Facebook Page ID is ' . $page_id);
}