| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// RDF API unit tests (repository operations)
|
| 6 |
|
| 7 |
class RepositoryTestCase extends DrupalWebTestCase {
|
| 8 |
function getInfo() {
|
| 9 |
return array(
|
| 10 |
'name' => t('Repositories'),
|
| 11 |
'description' => t('Creates, renames and deletes a local RDF repository.'),
|
| 12 |
'group' => t('RDF API'),
|
| 13 |
);
|
| 14 |
}
|
| 15 |
|
| 16 |
function setup() {
|
| 17 |
$this->repository = 'simpletest';
|
| 18 |
$this->table = RDF_DB_TABLE_PREFIX . $this->repository;
|
| 19 |
|
| 20 |
// Don't call the parent constructor, as that would set up a sandbox
|
| 21 |
// that leads most, if not all, of these tests to fail. Anyone who wants
|
| 22 |
// this sandboxed is feel free to figure it out and submit a patch.
|
| 23 |
//parent::setup('rdf');
|
| 24 |
}
|
| 25 |
|
| 26 |
function test_create_repository() {
|
| 27 |
$this->assertFalse(db_table_exists($this->table), t('Table does not exist'));
|
| 28 |
rdf_db_create_repository($this->repository, array('title' => t('Simpletest'), 'description' => ''));
|
| 29 |
$this->assertTrue(db_table_exists($this->table), t('Table was created'));
|
| 30 |
}
|
| 31 |
|
| 32 |
function test_rename_repository() {
|
| 33 |
rdf_db_rename_repository($this->repository, $this->repository . '_renamed');
|
| 34 |
$this->assertTrue(db_table_exists($this->table . '_renamed'), t('Table was renamed'));
|
| 35 |
|
| 36 |
rdf_db_rename_repository($this->repository . '_renamed', $this->repository);
|
| 37 |
$this->assertTrue(db_table_exists($this->table), t('Table was renamed back'));
|
| 38 |
}
|
| 39 |
|
| 40 |
function test_delete_repository() {
|
| 41 |
rdf_db_delete_repository($this->repository);
|
| 42 |
$this->assertFalse(db_table_exists($this->table), t('Table was deleted'));
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
//////////////////////////////////////////////////////////////////////////////
|
| 47 |
// RDF API unit tests (statement operations)
|
| 48 |
|
| 49 |
class StatementTestCase extends DrupalWebTestCase {
|
| 50 |
const REPOSITORY = 'simpletest';
|
| 51 |
|
| 52 |
public function getInfo() {
|
| 53 |
return array(
|
| 54 |
'name' => t('Statements'),
|
| 55 |
'description' => t('Inserts, queries and deletes RDF statements.'),
|
| 56 |
'group' => t('RDF API'),
|
| 57 |
);
|
| 58 |
}
|
| 59 |
|
| 60 |
public function setup() {
|
| 61 |
rdf_db_create_repository(self::REPOSITORY, array('title' => t('Simpletest'), 'description' => ''));
|
| 62 |
rdf_use_repository(self::REPOSITORY);
|
| 63 |
rdf_delete(NULL, NULL, NULL);
|
| 64 |
rdf_insert_all($this->load_test_data());
|
| 65 |
|
| 66 |
// Don't call the parent constructor, as that would set up a sandbox
|
| 67 |
// that leads most, if not all, of these tests to fail. Anyone who wants
|
| 68 |
// this sandboxed is feel free to figure it out and submit a patch.
|
| 69 |
//parent::setup('rdf');
|
| 70 |
}
|
| 71 |
|
| 72 |
public function teardown() {
|
| 73 |
rdf_use_repository(NULL);
|
| 74 |
rdf_db_delete_repository(self::REPOSITORY);
|
| 75 |
parent::teardown();
|
| 76 |
}
|
| 77 |
|
| 78 |
public function test_count_statements() {
|
| 79 |
$this->assertTrue(rdf_count() > 0, t('Test data was inserted'));
|
| 80 |
$this->assertEqual(rdf_count(), count($this->load_test_data()), t('Expected statement count found'));
|
| 81 |
}
|
| 82 |
|
| 83 |
public function test_insert_statement() {
|
| 84 |
rdf_insert('http://drupal.org/', dc::title, 'Drupal');
|
| 85 |
$this->assertEqual(rdf_count(), count($this->load_test_data()) + 1, t('One statement was inserted'));
|
| 86 |
}
|
| 87 |
|
| 88 |
public function test_insert_duplicates() {
|
| 89 |
rdf_insert_all($this->load_test_data());
|
| 90 |
$this->assertEqual(rdf_count(), count($this->load_test_data()), t('No duplicate statements found'));
|
| 91 |
}
|
| 92 |
|
| 93 |
public function test_query_statements() {
|
| 94 |
foreach ($this->load_test_data() as $stmt) {
|
| 95 |
$this->assertEqual(call_user_func_array('rdf_count', $stmt), 1, t('Querying statement #@index', array('@index' => ++$counter)));
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
public function test_delete_one_statement() {
|
| 100 |
call_user_func_array('rdf_delete', reset($this->load_test_data()));
|
| 101 |
$this->assertEqual(rdf_count(), count($this->load_test_data()) - 1, t('One statement was deleted'));
|
| 102 |
}
|
| 103 |
|
| 104 |
public function test_delete_all_statements() {
|
| 105 |
rdf_delete(NULL, NULL, NULL);
|
| 106 |
$this->assertEqual(rdf_count(), 0, t('All statements were deleted'));
|
| 107 |
}
|
| 108 |
|
| 109 |
private function load_test_data() {
|
| 110 |
return rdf_denormalize(array(
|
| 111 |
'http://drupal.org/project/rdf' => array(
|
| 112 |
dc::title => 'RDF API',
|
| 113 |
dc::creator => rdf_uri('http://ar.to/#self'),
|
| 114 |
),
|
| 115 |
'http://ar.to/#self' => array(
|
| 116 |
foaf::name => 'Arto Bendiken',
|
| 117 |
foaf::homepage => rdf_uri('http://bendiken.net/'),
|
| 118 |
),
|
| 119 |
));
|
| 120 |
}
|
| 121 |
}
|