forked from neolf/googl-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.php
62 lines (51 loc) · 1.85 KB
/
tests.php
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
<?php
/**
* This file is part of googl-php
*
* https://github.com/sebi/googl-php
*
* googl-php is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function assert_equals($is, $should) {
if($is != $should) {
exit(1);
} else {
println('Passed!');
}
}
function assert_url($is) {
if(!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $is)) {
exit(1);
} else {
println('Passed!');
}
}
function println($text) {
echo $text . "\n";
}
require 'Googl.class.php';
#
# IMPORTANT: Please add your API key to make the tests work
#
$googl = new Googl('YOUR_API_KEY');
println('#1 - Assert that shortening http://www.google.ch results in an URL');
assert_url($googl->shorten('http://www.google.ch'));
println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/');
assert_equals($googl->expand('http://goo.gl/KSggQ'), 'http://www.google.com/');
println('#3 - Assert that shortening https://www.facebook.com results in an URL');
assert_url($googl->shorten('https://www.facebook.com'));
println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/');
assert_equals($googl->expand('http://goo.gl/wCWWd'), 'http://www.php.net/');
# If this point is reached, all tests have passed
println('All tests have successfully passed!');