forked from dready92/PHP-on-Couch
/
couchClientShowTest.php
84 lines (73 loc) · 2.12 KB
/
couchClientShowTest.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// error_reporting(E_STRICT);
error_reporting(E_ALL);
require_once 'PHPUnit/Framework.php';
require_once "lib/couch.php";
require_once "lib/couchClient.php";
require_once "lib/couchDocument.php";
require_once "lib/couchReplicator.php";
class couchClientShowTest extends PHPUnit_Framework_TestCase
{
private $couch_server = "http://localhost:5984/";
public function setUp()
{
$this->client = new couchClient($this->couch_server,"couchclienttest");
try {
$this->client->deleteDatabase();
} catch ( Exception $e) {}
$this->client->createDatabase();
}
public function tearDown()
{
$this->client = null;
}
public function testShow () {
$doc = new couchDocument($this->client);
$doc->_id="_design/test";
$show = array (
"simple" => "function (doc, ctx) {
ro = {body: ''};
if ( ! doc ) {
ro.body = 'no document';
} else {
ro.body = 'document: '+doc._id;
}
ro.body += ' ';
var len = 0;
for ( var k in ctx.query ) {
len++;
}
ro.body += len;
return ro;
}",
"json" => "function (doc, ctx) {
ro = {body: ''};
back = {doc: null};
if ( doc ) {
back.doc = doc._id;
}
var len = 0;
for ( var k in ctx.query ) {
len++;
}
back.query_length = len;
ro.body = JSON.stringify(back);
ro.headers = { \"content-type\": 'application/json' };
return ro;
}"
);
$doc->shows = $show;
$test = $this->client->getShow("test","simple","_design/test");
$this->assertEquals ( $test, "document: _design/test 0" );
$test = $this->client->getShow("test","simple","_design/test",array("param1"=>"value1"));
$this->assertEquals ( $test, "document: _design/test 1" );
$test = $this->client->getShow("test","simple",null);
$this->assertEquals ( $test, "no document 0" );
$test = $this->client->getShow("test","simple",null,array("param1"=>"value1"));
$this->assertEquals ( $test, "no document 1" );
$test = $this->client->getShow("test","json",null);
$this->assertType("object", $test);
$this->assertObjectHasAttribute("doc",$test);
$this->assertObjectHasAttribute("query_length",$test);
}
}