OSDN Git Service

Import current code.
[osdn-codes/wiki-parser.git] / test / StorageTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework/TestCase.php';
4
5 class StorageTest extends PHPUnit_Framework_TestCase {
6         protected $storage_path;
7         protected $s;
8
9         protected function setUp(){
10                 $this->storage_path = dirname(__FILE__) . "filestore-test";
11                 $this->s = new sfjp\Wiki\Storage\File(array('storage.file.datadir' => $this->storage_path));
12         }
13
14         protected function tearDown() {
15                 $this->cleanup();
16         }
17
18         protected function cleanup() {
19                 if (!is_dir($this->storage_path))
20                         return;
21                 $dh = opendir($this->storage_path);
22                 if (!$dh) return;
23                 while ($ent = readdir($dh)) {
24                         if ($ent == '.' || $ent == '..')
25                                 continue;
26                         unlink("{$this->storage_path}/{$ent}");
27                 }
28                 closedir($dh);
29                 rmdir($this->storage_path);
30         }
31
32         public function testNew() {
33                 self::assertTrue(isset($this->s));
34         }
35
36
37         public function testGetSet() {
38                 $text = "hoge\nfuga\r\nyeah!";
39                 $this->s->set('page1', $text);
40                 self::assertEquals($text, $this->s->get('page1'));
41         }
42
43         public function testList() {
44                 $this->cleanup();
45                 $this->s->set('foo', 'foo 1');
46                 $this->s->set('Bar', 'bar 2');
47                 self::assertTrue(in_array('foo', $this->s->get_list()));
48                 self::assertTrue(in_array('Bar', $this->s->get_list()));
49                 self::assertTrue(!in_array('boo', $this->s->get_list()));
50         }
51
52         public function testRemove() {
53                 $this->s->set('hoge', '1');
54                 self::assertTrue(in_array('hoge', $this->s->get_list()));
55                 $this->s->remove('hoge');
56                 self::assertTrue(!in_array('hoge', $this->s->get_list()));
57         }
58 }