File: xslt_set_object.phpt

package info (click to toggle)
php4 6%3A4.4.4-8%2Betch1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 34,976 kB
  • ctags: 39,148
  • sloc: ansic: 340,486; php: 34,786; cpp: 10,150; sh: 9,010; lex: 2,180; yacc: 1,712; xml: 1,335; makefile: 559; awk: 466; java: 455; perl: 154
file content (89 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--TEST--
xslt_set_object function
--SKIPIF--
<?php
include("skipif.inc");
if(!function_exists('xslt_set_object')) {
	die("skip function xslt_set_object() not available");
}
?>
--INI--
magic_quotes_runtime=0
--FILE--
<?php
error_reporting(E_ALL);
class XSLTTester
{
	var $_success = false;
	var $_success2 = false;

	function XSLTTester()
	{}
	
	// this function will register this object as the
	// callback object.
	function test1($xmlfile,$xslfile)
	{
		$xh = xslt_create();
		xslt_set_object($xh,$this);
		$handlers = array('get_all'=> 'handle_getall');
		xslt_set_scheme_handlers($xh,$handlers);
		$res = xslt_process($xh,$xmlfile,$xslfile);
		xslt_free($xh);
		return 1;
	}

	// this function will pass this object as in set_scheme_handler
	function test2($xmlfile,$xslfile)
	{
		$xh = xslt_create();
		$handlers = array('get_all'=> array(&$this,'handle_getall2'));
		xslt_set_scheme_handlers($xh,$handlers);
		$res = xslt_process($xh,$xmlfile,$xslfile);
		xslt_free($xh);
		return 1;
	}
	function handle_getall($xh,$scheme,$rest)
	{
		$this->_success = true;
		$rest = substr($rest,2);
		return implode('', file('ext/xslt/tests/'.$rest));
	}
	function handle_getall2($xh,$scheme,$rest)
	{
		$this->_success2 = true;
		$rest = substr($rest,2);
		return implode('', file('ext/xslt/tests/'.$rest));
	}
	function testSucceeded()
	{
		return $this->_success;
	}
	function test2Succeeded()
	{
		return $this->_success2;
	}
}

$xmlfile = 'ext/xslt/tests/test.xml';
$xslfile = 'ext/xslt/tests/xslt_set_object.xsl';

$testobj = new XSLTTester();
$testobj->test1($xmlfile,$xslfile);

$testobj->test2($xmlfile,$xslfile);

if ($testobj->testSucceeded())
	print "OK\n";
else
	print "FAILED\n";

if ($testobj->test2Succeeded())
	print "OK\n";
else
	print "FAILED\n";
	
?>
--EXPECT--
OK
OK