ChadoSchemaTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Tests\tripal_chado\api;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. use Faker\Factory;
  6. module_load_include('inc', 'tripal_chado', 'api/ChadoSchema');
  7. /**
  8. * Tests the ChadoSchema class.
  9. *
  10. * @todo test "Check" functions in the ChadoSchema class.
  11. */
  12. class ChadoSchemaTest extends TripalTestCase {
  13. use DBTransaction;
  14. /**
  15. * Tests that the class can be initiated with or without a record specified
  16. *
  17. * @group api
  18. * @group chado
  19. * @group chado-schema
  20. * @group lacey
  21. */
  22. public function testInitClass() {
  23. // Test with no parameters.
  24. $chado_schema = new \ChadoSchema();
  25. $this->assertNotNull($chado_schema);
  26. // Test with version.
  27. $chado_schema = new \ChadoSchema('1.3');
  28. $this->assertNotNull($chado_schema);
  29. }
  30. /**
  31. * Tests the ChadoSchema->getVersion() method.
  32. *
  33. * @group api
  34. * @group chado
  35. * @group chado-schema
  36. * @group lacey
  37. */
  38. public function testGetVersion() {
  39. // Generate a fake version.
  40. $faker = Factory::create();
  41. $version = $faker->randomFloat(2, 1, 5);
  42. // Check version can be retrieved when we set it.
  43. $chado_schema = new \ChadoSchema($version);
  44. $retrieved_version = $chado_schema->getVersion();
  45. $this->assertEquals(
  46. $version,
  47. $retrieved_version,
  48. t('The version retrieved via ChadoSchema->getVersion, :ret, should equal that set, :set',
  49. array(':ret' => $retrieved_version, ':set' => $version))
  50. );
  51. // @todo Check version can be retrieved when it's looked up?
  52. }
  53. /**
  54. * Tests the ChadoSchema->getSchemaName() method.
  55. *
  56. * @group api
  57. * @group chado
  58. * @group chado-schema
  59. * @group lacey
  60. */
  61. public function testGetSchemaName() {
  62. // Generate a fake version.
  63. $faker = Factory::create();
  64. $version = $faker->randomFloat(2, 1, 5);
  65. $schema_name = $faker->word();
  66. // Check the schema name can be retrieved when we set it.
  67. $chado_schema = new \ChadoSchema($version, $schema_name);
  68. $retrieved_schema = $chado_schema->getSchemaName();
  69. $this->assertEquals(
  70. $schema_name,
  71. $retrieved_schema,
  72. t('The schema name retrieved via ChadoSchema->getSchemaName, :ret, should equal that set, :set',
  73. array(':ret' => $retrieved_schema, ':set' => $schema_name))
  74. );
  75. // @todo Check schema name can be retrieved when it's looked up?
  76. }
  77. /**
  78. * Tests ChadoSchema->getTableNames() method.
  79. *
  80. * @dataProvider knownTableProvider
  81. *
  82. * @group api
  83. * @group chado
  84. * @group chado-schema
  85. * @group lacey
  86. */
  87. public function testGetTableNames($version, $known_tables) {
  88. // Check: Known tables for a given version are returned.
  89. $chado_schema = new \ChadoSchema($version);
  90. $returned_tables = $chado_schema->getTableNames();
  91. foreach ($known_tables as $table_name) {
  92. $this->assertArrayHasKey(
  93. $table_name,
  94. $returned_tables,
  95. t('The table, :known, should exist in the returned tables list for version :version.',
  96. array(':known' => $table_name, ':version' => $version))
  97. );
  98. }
  99. }
  100. /**
  101. * Data Provider: returns known tables specific to a given chado version.
  102. *
  103. * @return array
  104. */
  105. public function knownTableProvider() {
  106. // chado version, array of 3 tables specific to version.
  107. return [
  108. ['1.2', ['cell_line_relationship', 'cvprop', 'chadoprop']],
  109. ['1.3', ['analysis_cvterm', 'dbprop', 'organism_pub']],
  110. ];
  111. }
  112. }