function toggleCoupons(FeatureContext $world, TableNode $table) { $hash = $table->getHash(); foreach ($hash as $row) { if (isset($row['enabled'])) { $switcher = $world->find('xpath', '//a[text()="' . $row['name'] . '"]/ancestor::tr//span[contains(@class, "input-checkbox-switcher")]'); $class = $switcher->getAttribute('class'); if (strpos($class, $row['enabled']) === false) { $switcher->find('css', '.widget')->click(); } } } $world->pressButton("Save changes"); }
/** * @static * @BeforeSuite */ public static function bootstrapSilex() { if (!self::$app) { self::$app = (require __DIR__ . '/../../app/bootstrap.php'); } return self::$app; }
/** * Start up the web server * * @BeforeSuite */ public static function setUp(SuiteEvent $event) { // Fetch config $params = $event->getContextParameters(); $url = parse_url($params['url']); $port = !empty($url['port']) ? $url['port'] : 80; if (self::canConnectToHttpd($url['host'], $port)) { throw new RuntimeException('Something is already running on ' . $params['url'] . '. Aborting tests.'); } // Try to start the web server self::$pid = self::startBuiltInHttpd($url['host'], $port, $params['documentRoot'], $params['router']); if (!self::$pid) { throw new RuntimeException('Could not start the web server'); } $start = microtime(true); $connected = false; // Try to connect until the time spent exceeds the timeout specified in the configuration while (microtime(true) - $start <= (int) $params['timeout']) { if (self::canConnectToHttpd($url['host'], $port)) { $connected = true; break; } } if (!$connected) { self::killProcess(self::$pid); throw new RuntimeException(sprintf('Could not connect to the web server within the given timeframe (%d second(s))', $params['timeout'])); } self::$testSessionId = uniqid('behat-coverage-', true); }
/** * Start up the web server * * @BeforeSuite */ public static function setUp(SuiteEvent $event) { $params = $event->getContextParameters(); $url = parse_url($params['url']); self::$webServerPort = !empty($url['port']) ? $url['port'] : 80; self::$phantomServerPort = $params['phantom_port']; self::$webServerProcess = self::setUpWebServer($event); self::$phantomServerProcess = self::setUpPhantomServer($event); }
/** * @Given /^I am in a directory called "([^"]*)"$/ */ public function inDir($dir) { if (null === self::$cliDir) { self::$cliDir = getcwd(); } $this->dir = $dir; $dir = $this->tmp . '/' . $dir; $this->fs->mkdir($dir); chdir($dir); }
/** * Initialize context * Every scenario gets it's own context object. * * @param array $parameters context parameters (set them up through behat.yml) */ public function __construct(array $parameters) { self::$_parameters = $parameters; self::$vhosts = ["/test-behat"]; ini_set('display_errors', true); ini_set('xdebug.var_display_max_depth', 100); ini_set('xdebug.var_display_max_children', 100); ini_set('xdebug.var_display_max_data', 100); error_reporting(E_ALL); }
public function saveHtml(Behat\Behat\Hook\Scope\AfterStepScope $scope) { if (!$scope->getTestResult()->isPassed()) { $session = $this->featureContext->getSession(); $page = $session->getPage(); $fileName = str_replace(array(' ', ','), '-', $scope->getFeature()->getTitle()); if (!file_exists($this->html_dump_path)) { mkdir($this->html_dump_path); } $date = date('Y-m-d H:i:s'); $url = $session->getCurrentUrl(); $html = $page->getContent(); $html = "<!-- HTML dump from behat \nDate: {$date} \nUrl: {$url} -->\n " . $html; $htmlCapturePath = $this->html_dump_path . '/' . $fileName . '.html'; file_put_contents($htmlCapturePath, $html); $message = "\nHTML saved to: " . $this->html_dump_path . "/" . $fileName . ".html"; $message .= "\nHTML available at: " . $this->html_dump_url . "/" . $fileName . ".html"; echo $message; } }
/** * Initializes context. * Every scenario gets its own context object. */ public function __construct() { $this->doctrineHelper = new DoctrineHelper(); self::$entityManager = $this->doctrineHelper->entityManager; $classes = $this->doctrineHelper->entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool = new SchemaTool($this->doctrineHelper->entityManager); $schemaTool->dropSchema($classes); $schemaTool->createSchema($classes); $appBuilderFactory = new Conpago\AppBuilderFactory(); $appBuilder = $appBuilderFactory->createAppBuilder("Web", "."); $appBuilder->registerAdditionalModule(new TestModule()); $appBuilder->buildApp(); $this->container = $appBuilder->getContainer(); $this->passwordHasher = $this->container->resolve('Conpago\\Helpers\\Contract\\IPasswordHasher'); $this->presenter = $this->container->resolve('Conpago\\Presentation\\Contract\\IJsonPresenter'); }
/** * @When /^I create an account$/ */ public function iCreateAnAccount() { try { //go to the registration page, we use http://demo.magentocommerce.com/ as the homepage $this->visit('/customer/account/create/'); //we generate a random mailinator email that starts with FIRST_NAME self::$email = uniqid(self::FIRST_NAME) . '@mailinator.com'; //complete the registration form $this->fillField('firstname', self::FIRST_NAME); $this->fillField('lastname', self::LAST_NAME); $this->fillField('email', self::$email); $this->fillField('password', self::PASSWORD); $this->fillField('confirmation', self::PASSWORD); $this->pressButton('Register'); //for testing only echo "Email address used for registration: " . self::$email . "\n"; } catch (Exception $e) { //we will fail this step if we have any exceptions throw new Exception("Something went wrong: " . $e->getMessage()); } }
public function iLoginAs($user) { if (isset($this->users[$user])) { $this->featureContext->visit("user"); $name = $this->featureContext->getSession()->getPage()->findField("name"); $name->setValue($user); $pass = $this->featureContext->getSession()->getPage()->findField("pass"); $pass->setValue($this->users[$user]); $login = $this->featureContext->getSession()->getPage()->find("css", "#edit-submit"); $login->click(); $escapedValue = $this->featureContext->getSession()->getSelectorsHandler()->xpathLiteral($user); $text = $this->featureContext->getSession()->getPage()->find('named', array('content', $escapedValue)); if (isset($text) && $text != NULL) { return true; } else { throw new Exception("Can't login as the user " . $user . " with password: '******'. Check its credentials are ok in the \$users array"); } } else { throw new Exception("Can't find the user " . $user . " in the test user array. Edit the Logger.php class and add its credentials :)."); } }
/** * @AfterStep * * Take screenshot when step fails. * Works only with Selenium2Driver. * * @param \Behat\Behat\Hook\Scope\AfterStepScope $scope */ public function takeScreenshotAfterFailedStep(Behat\Behat\Hook\Scope\AfterStepScope $scope) { if (!is_dir('temp')) { mkdir('temp'); } if (self::$clean === false) { $files = glob('temp/BEHAT*.png'); array_map('unlink', $files); self::$clean = true; } if ($scope->getTestResult()->getResultCode() === Behat\Testwork\Tester\Result\TestResult::FAILED) { $driver = $this->getSession()->getDriver(); if ($driver instanceof Behat\Mink\Driver\Selenium2Driver) { $browser = $this->getMinkParameters()['browser_name']; $feature = iconv('UTF-8', 'ASCII//TRANSLIT', $scope->getFeature()->getTitle()); $line = $scope->getStep()->getLine(); $description = iconv('UTF-8', 'ASCII//TRANSLIT', $scope->getStep()->getText()); $description = preg_replace('/[^\\s\\w]/', '', $description); $image = sprintf('%s.%s.%s.%s.png', $browser, $feature, $line, $description); file_put_contents('temp/BEHAT.' . $image, $driver->getScreenshot()); } } }
/** * Initializes context. * Every scenario gets it's own context object. * * @param array $parameters context parameters (set them up through behat.yml) */ public function __construct(array $parameters) { $config = new \Doctrine\DBAL\Configuration(); self::$db = \Doctrine\DBAL\DriverManager::getConnection(array('dbname' => $parameters['database']['dbname'], 'user' => $parameters['database']['username'], 'password' => $parameters['database']['password'], 'host' => $parameters['database']['host'], 'driver' => $parameters['database']['driver'])); $datasource = new \Phabric\Datasource\Doctrine(self::$db, $parameters['Phabric']['entities']); $this->phabric = new Phabric($datasource); $this->phabric->createEntitiesFromConfig($parameters['Phabric']['entities']); $this->phabric->addDataTransformation('UKTOMYSQLDATE', function ($date) { $date = \DateTime::createFromFormat('d/m/Y H:i', $date); return $date->format('Y-m-d H:i:s'); }); $this->phabric->addDataTransformation('ATTENDEELOOKUP', function ($attendeeName, $bus) { $ent = $bus->getEntity('attendee'); $id = $ent->getNamedItemId($attendeeName); return $id; }); $this->phabric->addDataTransformation('SESSIONLOOKUP', function ($sessionName, $bus) { $ent = $bus->getEntity('session'); $id = $ent->getNamedItemId($sessionName); return $id; }); $this->phabric->addDataTransformation('UPDOWNTOINT', function ($action) { $action = strtoupper($action); switch ($action) { case 'UP': return +1; break; case 'DOWN': return -1; case 'NO VOTE': return 0; } }); $this->phabric->addDataTransformation('SNAKECASE', function ($name) { return str_replace(' ', '_', strtolower($name)); }); }
/** * @BeforeSuite */ public static function prepare(SuiteEvent $event) { self::cache_wp_files(); self::$suite_cache_dir = sys_get_temp_dir() . '/' . uniqid("wp-cli-test-suite-cache-", TRUE); mkdir(self::$suite_cache_dir); }
/** * @BeforeSuite */ public static function bootstrapApp() { self::$app = (require __DIR__ . '/../../bootstrap.php'); }
/** * @beforeSuite */ public static function prepareDIC() { self::$container = (require __DIR__ . '/DIC/definitions.php'); }
public static function create_cache_dir() { self::$suite_cache_dir = sys_get_temp_dir() . '/' . uniqid("wp-cli-test-suite-cache-", TRUE); mkdir(self::$suite_cache_dir); return self::$suite_cache_dir; }
/** * Initializes context. */ public function __construct() { parent::__construct(); }
function runStep(&$browser, $step) { FeatureContext::step($browser, $step); }
/** * @BeforeSuite */ public static function startServer() { self::$pid = (int) `php --server=localhost:8000 --docroot="public" >> var/php-cli-server.log 2>&1 & echo \$!`; sleep(1); }
/** @Given /^I am on "([^"]*)"$/ */ public function iAmOnSite($url) { self::$webDriver = RemoteWebDriver::create("http://*****:*****@hub.browserstack.com/wd/hub", array("platform" => "WINDOWS", "browserName" => "firefox", "browserstack.local" => getenv('WP_ENV') === 'development')); self::$webDriver->get($_SERVER['WP_HOME'] . $url); }
/** * Cleans test folders in the temporary directory. * * @BeforeSuite */ public static function storeIncludePath() { self::$includePath = get_include_path(); }
/** * @BeforeSuite */ public static function initUrls(\Behat\Behat\Event\SuiteEvent $event) { $params = $event->getContextParameters(); if (isset($params['client_url'])) { $url = $params['client_url']; self::$clientUrl = strpos($url, 'http://') === 0 ? $params['client_url'] : $params['base_url'] . $params['client_url']; } if (isset($params['admin_url'])) { $url = $params['admin_url']; self::$adminUrl = strpos($url, 'http://') === 0 ? $url : $params['base_url'] . $url; } }
/** * Sets Kernel instance. * * @param HttpKernelInterface $kernel HttpKernel instance */ public function setKernel(HttpKernelInterface $kernel) { $this->kernel = $kernel; self::$statickernel = $kernel; }
<?php use Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\TableNode, WP_CLI\Process; $steps->Given('/^an empty directory$/', function ($world) { $world->create_run_dir(); }); $steps->Given('/^an empty cache/', function ($world) { $world->variables['SUITE_CACHE_DIR'] = FeatureContext::create_cache_dir(); }); $steps->Given('/^an? ([^\\s]+) file:$/', function ($world, $path, PyStringNode $content) { $content = (string) $content . "\n"; $full_path = $world->variables['RUN_DIR'] . "/{$path}"; Process::create(\WP_CLI\utils\esc_cmd('mkdir -p %s', dirname($full_path)))->run_check(); file_put_contents($full_path, $content); }); $steps->Given('/^WP files$/', function ($world) { $world->download_wp(); }); $steps->Given('/^wp-config\\.php$/', function ($world) { $world->create_config(); }); $steps->Given('/^a database$/', function ($world) { $world->create_db(); }); $steps->Given('/^a WP install$/', function ($world) { $world->install_wp(); }); $steps->Given("/^a WP install in '([^\\s]+)'\$/", function ($world, $subdir) { $world->install_wp($subdir); }); $steps->Given('/^a WP multisite (subdirectory|subdomain)?\\s?install$/', function ($world, $type = 'subdirectory') {
private static function getConfigDb($parameters) { if (!self::$conf_loaded) { include $parameters['config_file']; self::$conn = new Connection($conf); } return self::$conn; }
/** * @BeforeSuite */ public static function iniializeZendFramework() { if (self::$zendApp === null) { $config = (require __DIR__ . '/../../config/application.config.php'); self::$zendApp = Application::init($config); } }