FbInstantArticlesFeatureContext.php in Facebook Instant Articles 3.x
File
tests/src/Behat/features/bootstrap/FbInstantArticlesFeatureContext.php
View source
<?php
use Behat\Gherkin\Node\TableNode;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
class FbInstantArticlesFeatureContext extends RawDrupalContext {
public static function prepare(BeforeSuiteScope $scope) {
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler
->moduleExists('fb_instant_articles_views')) {
\Drupal::service('module_installer')
->install([
'fb_instant_articles_views',
]);
}
if ($moduleHandler
->moduleExists('inline_form_errors')) {
\Drupal::service('module_installer')
->uninstall([
'inline_form_errors',
]);
}
\Drupal::configFactory()
->getEditable('fb_instant_articles.settings')
->delete();
}
public function iDisableHtmlRequiredValidationOnTheField($field) {
$id = $this
->getSession()
->getPage()
->findField($field)
->getAttribute('id');
$this
->getSession()
->evaluateScript("jQuery('#{$id}').removeAttr('required');");
}
public function iDisableHtmlRequiredValidationOnTheFields(TableNode $fields) {
foreach ($fields
->getHash() as $key => $value) {
$field = trim($value['field']);
$this
->iDisableHtmlRequiredValidationOnTheField($field);
}
}
public function iOpenTheFacebookInstantArticlesSettingsForm() {
$this
->visitPath('admin/config/services/fb_instant_articles');
}
}