ApiSettingsFormTest.php in Facebook Instant Articles 3.x
File
tests/src/Functional/ApiSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\fb_instant_articles\Functional;
use Drupal\Tests\BrowserTestBase;
class ApiSettingsFormTest extends BrowserTestBase {
protected static $modules = [
'node',
'fb_instant_articles',
];
protected $defaultTheme = 'stark';
public function setUp() : void {
parent::setUp();
$this
->drupalLogin($this->rootUser);
}
public function testBuildForm() {
$this
->drupalGet('/admin/config/services/fb_instant_articles/api_settings');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldExists('app_id');
$this
->assertSession()
->fieldExists('app_secret');
$this
->submitForm([], t('Next'));
$this
->assertSession()
->pageTextContains('You must enter the App ID before proceeding');
$this
->submitForm([
'app_id' => 'invalid',
], t('Next'));
$this
->assertSession()
->pageTextContains('The App ID that you entered is invalid');
$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);
$this
->clickLink('Update Facebook app id');
$this
->assertSession()
->fieldExists('app_id');
$this
->assertSession()
->fieldExists('app_secret');
$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);
}
}