From 7968dbc28688deacdf6ed1be2dd917d21bb2cce5 Mon Sep 17 00:00:00 2001 From: Konstantin Kudryashov Date: Wed, 24 Oct 2012 17:57:39 +0300 Subject: [PATCH] Move generic functions to RawMinkContext [1/2] --- .../MinkExtension/Context/RawMinkContext.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Behat/MinkExtension/Context/RawMinkContext.php b/src/Behat/MinkExtension/Context/RawMinkContext.php index 7605f50..3056a1b 100644 --- a/src/Behat/MinkExtension/Context/RawMinkContext.php +++ b/src/Behat/MinkExtension/Context/RawMinkContext.php @@ -91,4 +91,36 @@ class RawMinkContext extends BehatContext implements MinkAwareInterface { return $this->getMink()->assertSession($name); } + + /** + * Locates url, based on provided path. + * Override to provide custom routing mechanism. + * + * @param string $path + * + * @return string + */ + public function locatePath($path) + { + $startUrl = rtrim($this->getMinkParameter('base_url'), '/') . '/'; + + return 0 !== strpos($path, 'http') ? $startUrl . ltrim($path, '/') : $path; + } + + /** + * Save a screenshot of the current window to the file system. + * + * @param string $filename Desired filename, defaults to + * __.png + * @param string $filepath Desired filepath, defaults to + * upload_tmp_dir, falls back to sys_get_temp_dir() + */ + public function saveScreenshot($filename = null, $filepath = null) + { + // Under Cygwin, uniqid with more_entropy must be set to true. + // No effect in other environments. + $filename = $filename ?: sprintf('%s_%s_%s.%s', $this->getMinkParameter('browser_name'), date('c'), uniqid('', true), 'png'); + $filepath = $filepath ? $filepath : ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); + file_put_contents($filepath . '/' . $filename, $this->getSession()->getScreenshot()); + } }