source: Dev/branches/rest-dojo-ui/server/tonic/tests/filesystemcollection.php @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 4.2 KB
Line 
1<?php
2
3require_once('../lib/tonic.php');
4require_once('../examples/filesystem/filesystem.php');
5require_once('../examples/filesystem/filesystemcollection.php');
6
7/**
8 * @namespace Tonic\Tests
9 */
10class FilesystemCollectionTester extends UnitTestCase {
11   
12    var $testPath;
13   
14    function __construct() {
15        $this->testPath = sys_get_temp_dir();
16    }
17   
18    function setUp() {
19        @mkdir($this->testPath.DIRECTORY_SEPARATOR.'collection');
20        file_put_contents($this->testPath.DIRECTORY_SEPARATOR.'collectionIndex', '<ul>{{resources}}</ul>');
21        file_put_contents($this->testPath.DIRECTORY_SEPARATOR.'collection'.DIRECTORY_SEPARATOR.'1', 'one');
22        file_put_contents($this->testPath.DIRECTORY_SEPARATOR.'collection'.DIRECTORY_SEPARATOR.'2', 'two');
23    }
24   
25    function tearDown() {
26        unlink($this->testPath.DIRECTORY_SEPARATOR.'collectionIndex');
27        unlink($this->testPath.DIRECTORY_SEPARATOR.'collection'.DIRECTORY_SEPARATOR.'1');
28        unlink($this->testPath.DIRECTORY_SEPARATOR.'collection'.DIRECTORY_SEPARATOR.'2');
29        @unlink($this->testPath.DIRECTORY_SEPARATOR.'collection'.DIRECTORY_SEPARATOR.'3');
30        rmdir($this->testPath.DIRECTORY_SEPARATOR.'collection');
31    }
32   
33    function testCollection() {
34       
35        $config = array(
36            'uri' => '/filesystemcollection/collectionIndex'
37        );
38       
39        $request = new Request($config);
40        $resource = $request->loadResource();
41        $response = $resource->exec($request);
42       
43        $this->assertEqual($response->code, 200);
44        $this->assertEqual($response->body, '<ul><li><a href="/filesystemcollection/collection/1">1</a></li><li><a href="/filesystemcollection/collection/2">2</a></li></ul>');
45       
46    }
47   
48    function testReadCollectionItem() {
49       
50        $config = array(
51            'uri' => '/filesystemcollection/collection/1'
52        );
53       
54        $request = new Request($config);
55        $resource = $request->loadResource();
56        $response = $resource->exec($request);
57       
58        $this->assertEqual($response->code, 200);
59        $this->assertEqual($response->body, 'one');
60       
61    }
62   
63    function testCreateCollectionItem() {
64       
65        $config = array(
66            'uri' => '/filesystemcollection/collectionIndex',
67            'method' => 'POST'
68        );
69       
70        $request = new Request($config);
71        $resource = $request->loadResource();
72        $response = $resource->exec($request);
73       
74        $this->assertEqual($response->code, 411);
75       
76        $config = array(
77            'uri' => '/filesystemcollection/collectionIndex',
78            'method' => 'POST',
79            'data' => 'three'
80        );
81       
82        $request = new Request($config);
83        $resource = $request->loadResource();
84        $response = $resource->exec($request);
85       
86        $this->assertEqual($response->code, 201);
87        $this->assertEqual($response->headers['Location'], '/filesystemcollection/collection/3');
88       
89        $config = array(
90            'uri' => '/filesystemcollection/collectionIndex'
91        );
92       
93        $request = new Request($config);
94        $resource = $request->loadResource();
95        $response = $resource->exec($request);
96       
97        $this->assertEqual($response->code, 200);
98        $this->assertEqual($response->body, '<ul><li><a href="/filesystemcollection/collection/1">1</a></li><li><a href="/filesystemcollection/collection/2">2</a></li><li><a href="/filesystemcollection/collection/3">3</a></li></ul>');
99       
100    }
101   
102}
103
104
105/* Test resource definitions */
106
107/**
108 * @namespace Tonic\Tests
109 * @uri /filesystemcollection/collection/.*
110 */
111class TestFileSystemCollectionItem extends FilesystemResource {
112   
113    function __construct() {
114       
115        $this->path = sys_get_temp_dir();
116        $this->uriStub = '/filesystemcollection';
117       
118    }
119   
120}
121
122/**
123 * @namespace Tonic\Tests
124 * @uri /filesystemcollection/collectionIndex
125 */
126class TestFileSystemCollection extends FilesystemCollection {
127   
128    function __construct() {
129       
130        $this->path = sys_get_temp_dir();
131        $this->uriStub = '/filesystemcollection';
132        $this->collection = sys_get_temp_dir().'/collection';
133       
134    }
135   
136}
137
Note: See TracBrowser for help on using the repository browser.