ChadoComplianceTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Tests\tripal_chado\api;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. module_load_include('inc', 'tripal_chado', 'api/ChadoSchema');
  6. /**
  7. * Tests the current Chado Database is compliant with the schema definition used by Tripal
  8. */
  9. class ChadoComplianceTest extends TripalTestCase {
  10. // Uncomment to auto start and rollback db transactions per test method.
  11. // use DBTransaction;
  12. /**
  13. * DataProvider, a list of all chado tables.
  14. *
  15. * @return array
  16. */
  17. public function chadoTableProvider() {
  18. // @todo expose all tables.
  19. return [
  20. ['organism'],
  21. ['feature'],
  22. ['stock'],
  23. ];
  24. }
  25. /**
  26. * Tests Compliance for a given table.
  27. *
  28. * The following is tested:
  29. * 1. The table exists in the correct schema.
  30. * 2. It has all the fields we expect.
  31. * 3. Each field is the type we expect.
  32. * 4. It has all the constraints we expect.
  33. * 5. Each constraint consists of the columns we expect.
  34. *
  35. * @dataProvider chadoTableProvider
  36. *
  37. * @group api
  38. * @group chado
  39. * @group chado-schema
  40. * @group chado-compliance
  41. * @group lacey
  42. */
  43. public function testTableCompliance($table_name) {
  44. // Create the ChadoSchema class to aid in testing.
  45. $chado_schema = new \ChadoSchema();
  46. // Check #1: The table exists in the correct schema.
  47. $this->assertTrue(
  48. $chado_schema->checkTableExists($table_name),
  49. t(':table_name should exist in the :chado schema.',
  50. array(':table_name' => $table_name, ':chado' => $schema_name))
  51. );
  52. // Retrieve the schema for this table.
  53. // For each column in this table...
  54. // Check #2: The given field exists in the table.
  55. // Check #3: The field is the type we expect.
  56. // For each constraint on this table...
  57. // Check #4: The constraint exists.
  58. // Check #5: The constraint consists of the columns we expect.
  59. }
  60. }