Skip to content

Commit 660df79

Browse files
committed
Add some tests
1 parent 27c2c0f commit 660df79

File tree

5 files changed

+113
-23
lines changed

5 files changed

+113
-23
lines changed

class/Cas.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public static function authenticate($ticket,$service) {
99
$url_validate = $cas_url."serviceValidate?service=".$service."&ticket=".$ticket;
1010
$data = file_get_contents($url_validate);
1111
if(empty($data)) return -1;
12-
1312
$parsed = new xmlToArrayParser($data);
1413
if(isset($parsed->array['cas:serviceResponse']['cas:authenticationSuccess']['cas:user']))
1514
return $parsed->array['cas:serviceResponse']['cas:authenticationSuccess']['cas:user'];

tests/Payutc/Service/KeyRodbTest.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
<?php
22

33

4-
require_once "bootstrap.php";
4+
require_once "ServiceBaseRodbTest.php";
55

6-
use \Payutc\Config;
76

8-
class KeyRodbTest extends ReadOnlyDatabaseTest
7+
class KeyRodbTest extends ServiceBaseRodbTest
98
{
10-
/**
11-
* get db dataset
12-
*/
13-
public function getDataSet()
14-
{
15-
return $this->computeDataset(array(
16-
'users.yml'
17-
));
18-
}
19-
20-
/**
21-
* @requires PHP 5.4
22-
*/
23-
public function testGetCasUrl()
24-
{
25-
$r = httpSend('KEY', 'getCasUrl');
26-
$this->assertEquals(200, $r->code);
27-
$this->assertEquals(Config::get('cas_url'), $r->body);
28-
}
9+
2910
}
3011

3112

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
require_once "ServiceBaseRodbTest.php";
4+
5+
class Poss3RodbTest extends ServiceBaseRodbTest
6+
{
7+
public function getFixtures()
8+
{
9+
return array_merge(parent::getFixtures(), array(
10+
'products.yml',
11+
));
12+
}
13+
14+
public function testGetBuyerInfo()
15+
{
16+
$cookie = '';
17+
$r = null;
18+
$this->loginCas($cookie, $r, 'trecouvr@POSS3', 'POSS3');
19+
$this->loginApp($cookie, $r, 'app1');
20+
}
21+
}
22+
23+
24+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
require_once "bootstrap.php";
4+
5+
use \Payutc\Config;
6+
7+
8+
abstract class ServiceBaseRodbTest extends ReadOnlyDatabaseTest
9+
{
10+
/**
11+
* get db dataset
12+
*/
13+
public function getDataSet()
14+
{
15+
return $this->computeDataset($this->getFixtures());
16+
}
17+
18+
public function getFixtures()
19+
{
20+
return array(
21+
'users.yml',
22+
'fundations.yml',
23+
'applications.yml'
24+
);
25+
}
26+
27+
public function loginCas(&$cookie='', &$r=null, $ticket='trecouvr@SERVICE', $service='SERVICE')
28+
{
29+
$r = httpSend('POSS3', 'loginCas', $cookie, array(
30+
'ticket' => $ticket,
31+
'service' => $service,
32+
));
33+
return $r;
34+
}
35+
36+
public function loginApp(&$cookie='', &$r, $key='app1')
37+
{
38+
$cookie = '';
39+
$r = httpSend('POSS3', 'loginApp', $cookie, array(
40+
'key' => $key,
41+
));
42+
return $r;
43+
}
44+
45+
/**
46+
* @requires PHP 5.4
47+
*/
48+
public function testGetCasUrl()
49+
{
50+
$r = httpSend('POSS3', 'getCasUrl');
51+
$this->assertEquals(200, $r->code);
52+
$this->assertEquals(Config::get('cas_url'), $r->body);
53+
}
54+
55+
/**
56+
* @require PHP 5.4
57+
*/
58+
public function testLoginCas()
59+
{
60+
$cookie = '';
61+
$r = null;
62+
$this->loginCas($cookie, $r, 'trecouvr@SERVICE', 'SERVICE');
63+
$this->assertEquals(200, $r->code);
64+
}
65+
66+
/**
67+
* @requires PHP 5.4
68+
*/
69+
public function testLoginApp()
70+
{
71+
$cookie = '';
72+
$r = null;
73+
$this->loginApp($cookie, $r, 'app1');
74+
$this->assertEquals(200, $r->code);
75+
}
76+
}
77+

tests/seed/applications.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
t_application_app:
2+
-
3+
app_id: 1
4+
app_url:
5+
app_key: app1
6+
app_name: app1
7+
app_desc:
8+
app_creator: trecouvr
9+

0 commit comments

Comments
 (0)