diff --git a/Tests/CasperTest.php b/Tests/CasperTest.php index 12812b7..1ba534e 100644 --- a/Tests/CasperTest.php +++ b/Tests/CasperTest.php @@ -287,6 +287,53 @@ public function testEvaluate() @unlink($filename); } + public function testEvaluateToVar() + { + $evaluateHtml = << + + + + test evaluate + + + link to google + + + +TEXT; + $filename = '/tmp/test-evaluate-var.html'; + + file_put_contents($filename, $evaluateHtml); + + $evaluate_href = <<start($filename) + ->evaluateToVar('href',$evaluate_href) + ->evaluateToVar('num_items',$evaluate_item) + ->run(); + + $vars = $casper->getVars(); + + $this->assertContains('google.com', $vars['href']); + $this->assertEquals(2, $vars['num_items']); + + @unlink($filename); + } + public function testDoubleClick() { $evaluateHtml = <<script .= $fragment; + + return $this; + } + + public function evaluateToVar($var, $function) + { + $fragment = <<script .= $fragment; @@ -585,6 +606,7 @@ public function run() this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status); this.echo('$this->TAG_CURRENT_STATUS_TEXT' + this.currentResponse.statusText); this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies)); + this.echo('$this->TAG_CURRENT_VARS' + JSON.stringify(vars)); }); casper.run(); @@ -680,6 +702,10 @@ private function processOutput() if (0 === strpos($outputLine, $this->TAG_CURRENT_COOKIES)) { $this->cookies = json_decode(str_replace($this->TAG_CURRENT_COOKIES, '', $outputLine), true); } + + if (0 === strpos($outputLine, $this->TAG_CURRENT_VARS)) { + $this->vars = json_decode(str_replace($this->TAG_CURRENT_VARS, '', $outputLine), true); + } } } @@ -739,4 +765,12 @@ public function getCookies() { return $this->cookies; } + + /** + * @return array + */ + public function getVars() + { + return $this->vars; + } }