From 35e9fd849de570f9a79523b0c89863a8220b8b0d Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 22 Jun 2013 13:35:29 +0200 Subject: [PATCH] Add tests. --- tests/js-construct-basic.phpt | 42 ++++++++++++++++++++++ tests/js-construct-with-ctor.phpt | 59 +++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tests/js-construct-basic.phpt create mode 100644 tests/js-construct-with-ctor.phpt diff --git a/tests/js-construct-basic.phpt b/tests/js-construct-basic.phpt new file mode 100644 index 0000000..7ecb451 --- /dev/null +++ b/tests/js-construct-basic.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test V8::executeString() : Test PHP object construction controlled by JavaScript (simple) +--SKIPIF-- + +--FILE-- +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=== diff --git a/tests/js-construct-with-ctor.phpt b/tests/js-construct-with-ctor.phpt new file mode 100644 index 0000000..72b5fbc --- /dev/null +++ b/tests/js-construct-with-ctor.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test V8::executeString() : Test PHP object construction controlled by JavaScript (with ctor) +--SKIPIF-- + +--FILE-- +_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=== +