FeatureContext.php in Pantheon Advanced Page Cache 7
File
tests/behat/features/bootstrap/FeatureContext.php
View source
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Drupal\DrupalExtension\Context\MinkContext;
use Drupal\DrupalExtension\Context\RawDrupalContext;
class FeatureContext extends RawDrupalContext implements Context, SnippetAcceptingContext {
public function __construct(array $parameters = []) {
}
private $minkContext;
public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope
->getEnvironment();
$this->minkContext = $environment
->getContext('Drupal\\DrupalExtension\\Context\\MinkContext');
}
public function thereAreArticleNodesWithAHugeNumberOfTaxonomyTermsEach($number_of_nodes) {
$i = 0;
while ($i < $number_of_nodes) {
$this
->WhenIGenerateAnArticleWithLotsOfTerms();
$i++;
}
}
public function WhenIGenerateAnArticleWithLotsOfTerms() {
$random_node_title = "Random Node Title: " . rand();
$this->minkContext
->visit('node/add/article');
$this->minkContext
->fillField('Title', $random_node_title);
$this->minkContext
->fillField('Tags', $this
->generateRandomTaxonomyString());
$this->minkContext
->pressButton('Save');
$this->minkContext
->assertTextVisible($random_node_title);
}
private function generateRandomTaxonomyString() {
$all_letters = explode(' ', 'a b c d e f g h i j k l m n o p q r s t u v w x y z');
$i = 0;
$random_three_letter_combos = array();
while ($i < 250) {
$random_three_letter_combos[] = $all_letters[rand(0, 25)] . $all_letters[rand(0, 25)] . $all_letters[rand(0, 25)];
$i++;
}
return implode(",", $random_three_letter_combos);
}
}