BasePhantomJSDriver.php in Zircon Profile 8
File
vendor/jcalderonzumba/mink-phantomjs-driver/src/BasePhantomJSDriver.php
View source
<?php
namespace Zumba\Mink\Driver;
use Behat\Mink\Driver\CoreDriver;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Session;
use Zumba\GastonJS\Browser\Browser;
class BasePhantomJSDriver extends CoreDriver {
protected $session;
protected $browser;
protected $phantomHost;
protected $templateLoader;
protected $templateEnv;
public function __construct($phantomHost, $templateCache = null) {
$this->phantomHost = $phantomHost;
$this->browser = new Browser($phantomHost);
$this->templateLoader = new \Twig_Loader_Filesystem(realpath(__DIR__ . '/Resources/Script'));
$this->templateEnv = new \Twig_Environment($this->templateLoader, array(
'cache' => $this
->templateCacheSetup($templateCache),
'strict_variables' => true,
));
}
protected function templateCacheSetup($templateCache) {
$cacheDir = $templateCache;
if ($templateCache === null) {
$cacheDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "jcalderonzumba" . DIRECTORY_SEPARATOR . "phantomjs";
if (!file_exists($cacheDir)) {
mkdir($cacheDir, 0777, true);
}
}
if (!file_exists($cacheDir)) {
throw new DriverException("Template cache {$cacheDir} directory does not exist");
}
return $cacheDir;
}
protected function findElement($xpath, $max = 1) {
$elements = $this->browser
->find("xpath", $xpath);
if (!isset($elements["page_id"]) || !isset($elements["ids"]) || count($elements["ids"]) !== $max) {
throw new DriverException("Failed to get elements with given {$xpath}");
}
return $elements;
}
public function setSession(Session $session) {
$this->session = $session;
}
public function getBrowser() {
return $this->browser;
}
public function getTemplateEnv() {
return $this->templateEnv;
}
public function javascriptTemplateRender($templateName, $viewData) {
$templateEngine = $this
->getTemplateEnv();
return $templateEngine
->render($templateName, $viewData);
}
}