| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// Bitcache unit tests (repository operations)
|
| 6 |
|
| 7 |
class BitcacheRepositoryTestCase extends DrupalWebTestCase {
|
| 8 |
public function getInfo() {
|
| 9 |
return array(
|
| 10 |
'name' => t('Repositories'),
|
| 11 |
'description' => t('Creates, renames and deletes a Bitcache repository.'),
|
| 12 |
'group' => t('Bitcache'),
|
| 13 |
);
|
| 14 |
}
|
| 15 |
|
| 16 |
public function setup() {
|
| 17 |
$this->repository = 'simpletest';
|
| 18 |
//parent::setup('bitcache');
|
| 19 |
}
|
| 20 |
|
| 21 |
function test_create_repository() {
|
| 22 |
$this->assertTrue(is_null($this->settings()), t('Repository does not exist'));
|
| 23 |
$this->assertFalse(is_dir($this->path()), t('Directory does not exist'));
|
| 24 |
|
| 25 |
bitcache_create_repository($this->repository, array('title' => 'Simpletest', 'description' => ''));
|
| 26 |
$this->assertFalse(is_null($this->settings()), t('Repository was created'));
|
| 27 |
$this->assertTrue(is_dir($this->path()), t('Directory was created'));
|
| 28 |
}
|
| 29 |
|
| 30 |
function test_rename_repository() {
|
| 31 |
bitcache_rename_repository($this->repository, $this->repository . '_renamed', array('location' => TRUE));
|
| 32 |
$this->assertFalse(is_null($this->settings($this->repository . '_renamed')), t('Repository was renamed'));
|
| 33 |
$this->assertTrue(is_dir($this->path() . '_renamed'), t('Directory was renamed'));
|
| 34 |
|
| 35 |
bitcache_rename_repository($this->repository . '_renamed', $this->repository, array('location' => TRUE));
|
| 36 |
$this->assertFalse(is_null($this->settings()), t('Repository was renamed back'));
|
| 37 |
$this->assertTrue(is_dir($this->path()), t('Directory was renamed back'));
|
| 38 |
}
|
| 39 |
|
| 40 |
function test_delete_repository() {
|
| 41 |
bitcache_delete_repository($this->repository);
|
| 42 |
$this->assertTrue(is_null($this->settings()), t('Repository was deleted'));
|
| 43 |
$this->assertFalse(is_dir($this->path()), t('Directory was deleted'));
|
| 44 |
}
|
| 45 |
|
| 46 |
private function path() {
|
| 47 |
return BITCACHE_ROOT . '/' . $this->repository;
|
| 48 |
}
|
| 49 |
|
| 50 |
private function settings($name = NULL) {
|
| 51 |
return variable_get('bitcache_repository[' . ($name ? $name : $this->repository) . ']', NULL);
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|
| 55 |
//////////////////////////////////////////////////////////////////////////////
|
| 56 |
// Bitcache unit tests (bitstream operations)
|
| 57 |
|
| 58 |
class BitcacheOperationsTestCase extends DrupalWebTestCase {
|
| 59 |
public function getInfo() {
|
| 60 |
return array(
|
| 61 |
'name' => t('Operations'),
|
| 62 |
'description' => t('Exercises the public Bitcache API operations.'),
|
| 63 |
'group' => t('Bitcache'),
|
| 64 |
);
|
| 65 |
}
|
| 66 |
|
| 67 |
public function setup() {
|
| 68 |
$this->repository = 'simpletest';
|
| 69 |
$this->data = 'Simpletest';
|
| 70 |
$this->id = sha1($this->data);
|
| 71 |
//parent::setup('bitcache');
|
| 72 |
}
|
| 73 |
|
| 74 |
public function test_create_repository() {
|
| 75 |
bitcache_create_repository($this->repository, array('title' => 'Simpletest', 'description' => ''));
|
| 76 |
$this->assertFalse(is_null($this->settings()), 'bitcache_create_repository()');
|
| 77 |
|
| 78 |
bitcache_use_repository($this->repository);
|
| 79 |
$this->assertTrue(isset($GLOBALS['bitcache_repository']), 'bitcache_use_repository()');
|
| 80 |
}
|
| 81 |
|
| 82 |
public function test_get_repository() {
|
| 83 |
$this->assertTrue(is_object(bitcache_get_repository($this->repository)), 'bitcache_get_repository()');
|
| 84 |
}
|
| 85 |
|
| 86 |
public function test_get_repository_settings() {
|
| 87 |
$this->assertTrue(is_array(bitcache_get_repository_settings($this->repository)), 'bitcache_get_repository_settings()');
|
| 88 |
}
|
| 89 |
|
| 90 |
public function test_get_repository_path() {
|
| 91 |
$this->assertTrue(is_dir(bitcache_get_repository_path($this->repository)), 'bitcache_get_repository_path()');
|
| 92 |
}
|
| 93 |
|
| 94 |
public function test_get_total_count_0() {
|
| 95 |
$this->assertEqual(bitcache_get_total_count($this->repository), 0, 'bitcache_get_total_count()');
|
| 96 |
}
|
| 97 |
|
| 98 |
public function test_get_total_size_0() {
|
| 99 |
$this->assertEqual(bitcache_get_total_size($this->repository), 0, 'bitcache_get_total_size()');
|
| 100 |
}
|
| 101 |
|
| 102 |
public function test_put() {
|
| 103 |
$this->assertTrue(is_string(bitcache_put(NULL, '')), 'bitcache_put("")');
|
| 104 |
$this->assertTrue(is_string(bitcache_put(NULL, $this->data)), 'bitcache_put("Simpletest")');
|
| 105 |
}
|
| 106 |
|
| 107 |
public function test_put_file() {
|
| 108 |
$this->assertTrue(is_string(bitcache_put_file(NULL, __FILE__)), 'bitcache_put_file(__FILE__)');
|
| 109 |
}
|
| 110 |
|
| 111 |
public function test_get_total_count_3() {
|
| 112 |
$this->assertTrue(bitcache_get_total_count($this->repository) == 3, 'bitcache_get_total_count()');
|
| 113 |
}
|
| 114 |
|
| 115 |
public function test_get_total_size_3() {
|
| 116 |
$this->assertTrue(bitcache_get_total_size($this->repository) > 0, 'bitcache_get_total_size()');
|
| 117 |
}
|
| 118 |
|
| 119 |
public function test_exists() {
|
| 120 |
$this->assertTrue(bitcache_exists(sha1('')), 'bitcache_exists("")'); // FIXME
|
| 121 |
$this->assertTrue(bitcache_exists($this->id), 'bitcache_exists("Simpletest")');
|
| 122 |
$this->assertFalse(bitcache_exists(sha1('Unknown')), '!bitcache_exists("Unknown")');
|
| 123 |
}
|
| 124 |
|
| 125 |
public function test_get() {
|
| 126 |
$this->assertTrue(is_object(bitcache_get($this->id)), 'bitcache_get("Simpletest")');
|
| 127 |
}
|
| 128 |
|
| 129 |
public function test_get_stream() {
|
| 130 |
$this->assertTrue(is_resource(bitcache_get_stream($this->id)), 'bitcache_get_stream("Simpletest")');
|
| 131 |
}
|
| 132 |
|
| 133 |
public function test_get_contents() {
|
| 134 |
$this->assertEqual(bitcache_get_contents($this->id), $this->data, 'bitcache_get_contents("Simpletest")');
|
| 135 |
}
|
| 136 |
|
| 137 |
public function test_delete() {
|
| 138 |
$this->assertTrue(bitcache_delete(sha1('')), 'bitcache_delete("")');
|
| 139 |
$this->assertTrue(bitcache_delete($this->id), 'bitcache_delete("Simpletest")');
|
| 140 |
}
|
| 141 |
|
| 142 |
public function test_delete_repository() {
|
| 143 |
bitcache_use_repository(NULL);
|
| 144 |
$this->assertFalse(isset($GLOBALS['bitcache_repository']), 'bitcache_use_repository()');
|
| 145 |
|
| 146 |
bitcache_delete_repository($this->repository);
|
| 147 |
$this->assertTrue(is_null($this->settings()), 'bitcache_delete_repository()');
|
| 148 |
}
|
| 149 |
|
| 150 |
private function settings($name = NULL) {
|
| 151 |
return variable_get('bitcache_repository[' . ($name ? $name : $this->repository) . ']', NULL);
|
| 152 |
}
|
| 153 |
}
|