X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fjcalderonzumba%2Fmink-phantomjs-driver%2Fsrc%2FBasePhantomJSDriver.php;fp=vendor%2Fjcalderonzumba%2Fmink-phantomjs-driver%2Fsrc%2FBasePhantomJSDriver.php;h=88a3073a9d6681e9d5e3969ce75811c829f5c984;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/jcalderonzumba/mink-phantomjs-driver/src/BasePhantomJSDriver.php b/vendor/jcalderonzumba/mink-phantomjs-driver/src/BasePhantomJSDriver.php new file mode 100644 index 000000000..88a3073a9 --- /dev/null +++ b/vendor/jcalderonzumba/mink-phantomjs-driver/src/BasePhantomJSDriver.php @@ -0,0 +1,98 @@ +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)); + } + + /** + * Sets up the cache template location for the scripts we are going to create with the driver + * @param $templateCache + * @return string + * @throws DriverException + */ + 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; + } + + /** + * Helper to find a node element given an xpath + * @param string $xpath + * @param int $max + * @returns int + * @throws DriverException + */ + 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; + } + + /** + * @return Browser + */ + public function getBrowser() { + return $this->browser; + } + + /** + * @return \Twig_Environment + */ + public function getTemplateEnv() { + return $this->templateEnv; + } + + /** + * Returns a javascript script via twig template engine + * @param $templateName + * @param $viewData + * @return string + */ + public function javascriptTemplateRender($templateName, $viewData) { + /** @var $templateEngine \Twig_Environment */ + $templateEngine = $this->getTemplateEnv(); + return $templateEngine->render($templateName, $viewData); + } + +}