X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fmink-extension%2Fsrc%2FBehat%2FMinkExtension%2FContext%2FRawMinkContext.php;fp=vendor%2Fbehat%2Fmink-extension%2Fsrc%2FBehat%2FMinkExtension%2FContext%2FRawMinkContext.php;h=d07610ec45ad4d083993d6817a91c8cf9a731573;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php b/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php new file mode 100644 index 000000000..d07610ec4 --- /dev/null +++ b/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php @@ -0,0 +1,165 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\MinkExtension\Context; + +use Behat\Mink\Mink; +use Behat\Mink\WebAssert; +use Behat\Mink\Session; + +/** + * Raw Mink context for Behat BDD tool. + * Provides raw Mink integration (without step definitions) and web assertions. + * + * @author Konstantin Kudryashov + */ +class RawMinkContext implements MinkAwareContext +{ + private $mink; + private $minkParameters; + + /** + * Sets Mink instance. + * + * @param Mink $mink Mink session manager + */ + public function setMink(Mink $mink) + { + $this->mink = $mink; + } + + /** + * Returns Mink instance. + * + * @return Mink + */ + public function getMink() + { + if (null === $this->mink) { + throw new \RuntimeException( + 'Mink instance has not been set on Mink context class. ' . + 'Have you enabled the Mink Extension?' + ); + } + + return $this->mink; + } + + /** + * Returns the parameters provided for Mink. + * + * @return array + */ + public function getMinkParameters() + { + return $this->minkParameters; + } + + /** + * Sets parameters provided for Mink. + * + * @param array $parameters + */ + public function setMinkParameters(array $parameters) + { + $this->minkParameters = $parameters; + } + + /** + * Returns specific mink parameter. + * + * @param string $name + * + * @return mixed + */ + public function getMinkParameter($name) + { + return isset($this->minkParameters[$name]) ? $this->minkParameters[$name] : null; + } + + /** + * Applies the given parameter to the Mink configuration. Consider that all parameters get reset for each + * feature context. + * + * @param string $name The key of the parameter + * @param string $value The value of the parameter + */ + public function setMinkParameter($name, $value) + { + $this->minkParameters[$name] = $value; + } + + /** + * Returns Mink session. + * + * @param string|null $name name of the session OR active session will be used + * + * @return Session + */ + public function getSession($name = null) + { + return $this->getMink()->getSession($name); + } + + /** + * Returns Mink session assertion tool. + * + * @param string|null $name name of the session OR active session will be used + * + * @return WebAssert + */ + public function assertSession($name = null) + { + return $this->getMink()->assertSession($name); + } + + /** + * Visits provided relative path using provided or default session. + * + * @param string $path + * @param string|null $sessionName + */ + public function visitPath($path, $sessionName = null) + { + $this->getSession($sessionName)->visit($this->locatePath($path)); + } + + /** + * 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()); + } +}