File: oauth_standard.phpt

package info (click to toggle)
php-oauth 2.0.2%2B1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 816 kB
  • ctags: 950
  • sloc: ansic: 7,197; xml: 841; php: 536; makefile: 1
file content (134 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (2)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--TEST--
OAuth Standard functions
--FILE--
<?php

function oauth_dump($v)
{
	if (is_null($v)) {
		echo "NULL\n";
		return;
	}
	if ($v instanceof OAuth) {
		printf("OAuth[debug=%d,sslChecks=%d,debugInfo=%s]\n", $v->debug, $v->sslChecks, $v->debugInfo);
		return;
	}
	echo "NOT_OAUTH\n";
}

echo "-- empty params --\n";
try {
	$x = new OAuth;
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- one param --\n";
try {
	$x = new OAuth('');
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- empty consumer key and secret --\n";
try {
	$x = new OAuth('', '');
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- empty consumer secret --\n";
try {
	$x = new OAuth('1234', '');
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- normal constructor --\n";
$x = new OAuth('1234', '5678');
oauth_dump($x);

echo "-- enable debug --\n";
$x->enableDebug();
oauth_dump($x);

echo "-- disable debug --\n";
$x->disableDebug();
oauth_dump($x);

try {
	echo "-- set version without parameters --\n";
	var_dump($x->setVersion());
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}
try {
	echo "-- set version with boolean --\n";
	var_dump($x->setVersion(true));
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

try {
	echo "-- set version with empty string --\n";
	var_dump($x->setVersion(''));
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- set version to 1 --\n";
var_dump($x->setVersion('1'));

try {
	echo "-- set auth type to invalid type 99 --\n";
	var_dump($x->setAuthType(99));
} catch (Exception $e) {
	echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}

echo "-- generate a signature --\n";
var_dump(is_string($x->generateSignature('GET', 'http://www.friendface.com/foo', array('param' => 'value'))));

echo "-- set a timeout (100 ms) --\n";
var_dump($x->setTimeout(100));

echo "-- set an invalid timeout --\n";
try {
$x->setTimeout(-1);
} catch (Exception $E) {
echo "EXCEPTION {$E->getCode()}: {$E->getMessage()}\n";
}
?>
--EXPECTF--
-- empty params --
EXCEPTION -1: The consumer key cannot be empty
-- one param --
EXCEPTION -1: The consumer key cannot be empty
-- empty consumer key and secret --
EXCEPTION -1: The consumer key cannot be empty
-- empty consumer secret --
EXCEPTION -1: The consumer secret cannot be empty
-- normal constructor --
OAuth[debug=0,sslChecks=3,debugInfo=]
-- enable debug --
OAuth[debug=1,sslChecks=3,debugInfo=]
-- disable debug --
OAuth[debug=0,sslChecks=3,debugInfo=]
-- set version without parameters --

Warning: OAuth::setVersion() expects exactly 1 parameter, 0 given %s
NULL
-- set version with boolean --
bool(true)
-- set version with empty string --
EXCEPTION 503: Invalid version
-- set version to 1 --
bool(true)
-- set auth type to invalid type 99 --
EXCEPTION 503: Invalid auth type
-- generate a signature --
bool(true)
-- set a timeout (100 ms) --
bool(true)
-- set an invalid timeout --
EXCEPTION 503: Invalid timeout