123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?php
- namespace Tests\tripal_chado\api;
- use StatonLab\TripalTestSuite\DBTransaction;
- use StatonLab\TripalTestSuite\TripalTestCase;
- use Faker\Factory;
- module_load_include('inc', 'tripal_chado', 'api/ChadoSchema');
- class ChadoSchemaTest extends TripalTestCase {
- use DBTransaction;
-
- public function testInitClass() {
-
- $chado_schema = new \ChadoSchema();
- $this->assertNotNull($chado_schema);
-
- $chado_schema = new \ChadoSchema('1.3');
- $this->assertNotNull($chado_schema);
- }
-
- public function testGetVersion() {
-
- $faker = Factory::create();
- $version = $faker->randomFloat(2, 1, 5);
-
- $chado_schema = new \ChadoSchema($version);
- $retrieved_version = $chado_schema->getVersion();
- $this->assertEquals(
- $version,
- $retrieved_version,
- t('The version retrieved via ChadoSchema->getVersion, "!ret", should equal that set, "!set"',
- ['!ret' => $retrieved_version, '!set' => $version])
- );
-
- }
-
- public function testGetSchemaName() {
-
- $faker = Factory::create();
- $version = $faker->randomFloat(2, 1, 5);
- $schema_name = $faker->word();
-
- $chado_schema = new \ChadoSchema($version, $schema_name);
- $retrieved_schema = $chado_schema->getSchemaName();
- $this->assertEquals(
- $schema_name,
- $retrieved_schema,
- t('The schema name retrieved via ChadoSchema->getSchemaName, "!ret", should equal that set, "!set"',
- ['!ret' => $retrieved_schema, '!set' => $schema_name])
- );
-
- }
-
- public function testGetTableNames($version, $known_tables) {
-
- $chado_schema = new \ChadoSchema($version);
- $returned_tables = $chado_schema->getTableNames();
- foreach ($known_tables as $table_name) {
- $this->assertArrayHasKey(
- $table_name,
- $returned_tables,
- t('The table, "!known", should exist in the returned tables list for version !version.',
- [':known' => $table_name, ':version' => $version])
- );
- }
- }
-
- public function testGetTableSchema($version, $table_name) {
-
- $chado_schema = new \ChadoSchema($version);
- $table_schema = $chado_schema->getTableSchema($table_name);
- $this->assertNotEmpty(
- $table_schema,
- t('Returned schema for "!table" in chado v!version should not be empty.',
- ['!table' => $table_name, '!version' => $version])
- );
- $this->assertArrayHasKey(
- 'fields',
- $table_schema,
- t('The schema array for "!table" should have columns listed in an "fields" array',
- ['!table' => $table_name])
- );
-
-
- if (isset($table_schema['primary key'])) {
- $this->assertTrue(is_array($table_schema['primary key']),
- t('The primary key of the Tripal Schema definition for "!table" must be an array.',
- ['!table' => $table_name]));
- }
- $this->assertArrayHasKey(
- 'foreign keys',
- $table_schema,
- t('The schema array for "!table" should have foreign keys listed in an "foreign keys" array',
- ['!table' => $table_name])
- );
- }
-
- public function testGetCustomTableSchema($table_name) {
-
- $chado_schema = new \ChadoSchema();
- $table_schema = $chado_schema->getCustomTableSchema($table_name);
- $this->assertNotEmpty(
- $table_schema,
- t('Returned schema for "!table" in chado v!version should not be empty.',
- ['!table' => $table_name, '!version' => $version])
- );
- $this->assertArrayHasKey(
- 'fields',
- $table_schema,
- t('The schema array for "!table" should have columns listed in an "fields" array',
- ['!table' => $table_name])
- );
-
-
- }
-
- public function testGetBaseTables($version, $known_tables) {
-
- $chado_schema = new \ChadoSchema($version);
- $returned_tables = $chado_schema->getBaseTables();
- foreach ($known_tables as $table_name) {
- $found = FALSE;
- foreach ($returned_tables as $check_table) {
- if ($check_table == $table_name) {
- $found = TRUE;
- }
- }
- $this->assertTrue($found, "{$table_name} was not returned by getBaseTables for Chado v {$version}");
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function knownTableProvider() {
-
- return [
- ['1.2', ['cell_line_relationship', 'cvprop', 'chadoprop']],
- ['1.3', ['analysis_cvterm', 'dbprop', 'organism_pub']],
- ];
- }
-
- public function knownBaseTableProvider() {
-
- return [
- [
- '1.2',
- ['organism', 'feature', 'stock', 'project', 'analysis', 'phylotree'],
- ],
- [
- '1.3',
- ['organism', 'feature', 'stock', 'project', 'analysis', 'phylotree'],
- ],
- ];
- }
-
- public function knownCustomTableProvider() {
- return [
- ['library_feature_count'],
- ['organism_feature_count'],
- ['tripal_gff_temp'],
- ];
- }
-
- public function chadoTableProvider() {
-
- $dataset = [];
- foreach (['1.11', '1.2', '1.3'] as $version) {
- $chado_schema = new \ChadoSchema();
- $version = $chado_schema->getVersion();
- foreach ($chado_schema->getTableNames() as $table_name) {
- $dataset[] = [$version, $table_name];
- }
- }
- return $dataset;
- }
- }
|