mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
Add tests.
This commit is contained in:
parent
347442c471
commit
35e9fd849d
42
tests/js-construct-basic.phpt
Normal file
42
tests/js-construct-basic.phpt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Test PHP object construction controlled by JavaScript (simple)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$v8 = new V8Js();
|
||||||
|
|
||||||
|
class Greeter {
|
||||||
|
function sayHello($a) {
|
||||||
|
echo "Hello $a\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$v8->greeter = new Greeter();
|
||||||
|
$v8->executeString('
|
||||||
|
function JsGreeter() { };
|
||||||
|
JsGreeter.prototype.sayHello = function(a) {
|
||||||
|
print("Hello " + a + "\n");
|
||||||
|
};
|
||||||
|
|
||||||
|
jsGreeter = new JsGreeter();
|
||||||
|
jsGreeter.sayHello("Paul");
|
||||||
|
|
||||||
|
jsGreeterNg = new jsGreeter.constructor();
|
||||||
|
jsGreeterNg.sayHello("George");
|
||||||
|
|
||||||
|
// ----- now the same using v8Js -----
|
||||||
|
|
||||||
|
PHP.greeter.sayHello("John");
|
||||||
|
|
||||||
|
var ngGreeter = new PHP.greeter.constructor();
|
||||||
|
ngGreeter.sayHello("Ringo");
|
||||||
|
');
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECT--
|
||||||
|
Hello Paul
|
||||||
|
Hello George
|
||||||
|
Hello John
|
||||||
|
Hello Ringo
|
||||||
|
===EOF===
|
59
tests/js-construct-with-ctor.phpt
Normal file
59
tests/js-construct-with-ctor.phpt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Test PHP object construction controlled by JavaScript (with ctor)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$v8 = new V8Js();
|
||||||
|
|
||||||
|
class Greeter {
|
||||||
|
protected $_name = null;
|
||||||
|
|
||||||
|
function __construct($name) {
|
||||||
|
echo "ctor called (php)\n";
|
||||||
|
$this->_name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sayHello() {
|
||||||
|
echo "Hello ".$this->_name."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$v8->greeter = new Greeter("John");
|
||||||
|
|
||||||
|
$v8->executeString('
|
||||||
|
function JsGreeter(name) {
|
||||||
|
print("ctor called (js)\n");
|
||||||
|
this.name = name;
|
||||||
|
};
|
||||||
|
|
||||||
|
JsGreeter.prototype.sayHello = function() {
|
||||||
|
print("Hello " + this.name + "\n");
|
||||||
|
};
|
||||||
|
|
||||||
|
jsGreeter = new JsGreeter("Paul");
|
||||||
|
jsGreeter.sayHello();
|
||||||
|
|
||||||
|
jsGreeterNg = new jsGreeter.constructor("George");
|
||||||
|
jsGreeterNg.sayHello();
|
||||||
|
|
||||||
|
// ----- now the same using v8Js -----
|
||||||
|
|
||||||
|
PHP.greeter.sayHello();
|
||||||
|
|
||||||
|
var ngGreeter = new PHP.greeter.constructor("Ringo");
|
||||||
|
ngGreeter.sayHello();
|
||||||
|
');
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECT--
|
||||||
|
ctor called (php)
|
||||||
|
ctor called (js)
|
||||||
|
Hello Paul
|
||||||
|
ctor called (js)
|
||||||
|
Hello George
|
||||||
|
Hello John
|
||||||
|
ctor called (php)
|
||||||
|
Hello Ringo
|
||||||
|
===EOF===
|
||||||
|
|
Loading…
Reference in New Issue
Block a user