View source
<?php
namespace Drupal\Tests\fb_instant_articles\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
class ViewModeToggleTest extends BrowserTestBase {
protected static $modules = [
'fb_instant_articles',
'node',
'field_ui',
];
protected $permissions = [
'access administration pages',
'administer content types',
'administer display modes',
'administer node display',
'administer site configuration',
'administer fb_instant_articles',
];
protected $adminUser;
protected $testField;
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->createContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->testField = mb_strtolower($this
->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $this->testField,
'entity_type' => 'node',
'type' => 'string',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'article',
]);
$field
->save();
}
public function testFbiaViewModeToggle() {
$this->adminUser = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($this->adminUser);
$view_modes_url = Url::fromRoute('entity.entity_view_mode.collection')
->toString();
$this
->drupalGet($view_modes_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Facebook Instant Articles');
$article_url = Url::fromRoute('entity.node_type.edit_form', [
'node_type' => 'article',
])
->toString();
$this
->drupalGet($article_url);
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'fb_instant_articles_enabled' => '1',
];
$this
->submitForm($edit, t('Save content type'));
$article_display_url = Url::fromRoute('entity.entity_view_display.node.default', [
'node_type' => 'article',
])
->toString();
$this
->drupalGet($article_display_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxChecked('edit-display-modes-custom-fb-instant-articles');
$article_display_url = Url::fromRoute('entity.entity_view_display.node.view_mode', [
'node_type' => 'article',
'view_mode_name' => 'fb_instant_articles',
])
->toString();
$this
->drupalGet($article_display_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Header');
$this
->assertSession()
->pageTextContains('Body');
$this
->assertSession()
->pageTextContains('Footer');
$this
->assertSession()
->pageTextContains('No fields are displayed in this region.');
$edit = [
'fields[' . $this->testField . '][region]' => 'content',
];
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->fieldValueEquals('fields[' . $this->testField . '][region]', 'content');
$article_url = Url::fromRoute('entity.node_type.edit_form', [
'node_type' => 'article',
])
->toString();
$this
->drupalGet($article_url);
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'fb_instant_articles_enabled' => '0',
];
$this
->submitForm($edit, t('Save content type'));
$article_display_url = Url::fromRoute('entity.entity_view_display.node.default', [
'node_type' => 'article',
])
->toString();
$this
->drupalGet($article_display_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->checkboxNotChecked('edit-display-modes-custom-fb-instant-articles');
}
}