TripalChadoPropertyAPITest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class TripalChadoPropertyAPITest extends TripalTestCase {
  6. use DBTransaction;
  7. /**
  8. * @group chado
  9. * @group api
  10. *
  11. */
  12. public function test_chado_insert_property() {
  13. $feature = factory('chado.feature')->create();
  14. $term = factory('chado.cvterm')->create();
  15. $value = 'chado_API_test_value';
  16. // Linker column
  17. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  18. $property = [
  19. 'type_id' => $term->cvterm_id,
  20. 'value' => $value,
  21. ];
  22. chado_insert_property($record, $property);
  23. $result = db_select('chado.featureprop', 'f')
  24. ->fields('f')
  25. ->condition('f.feature_id', $feature->feature_id)
  26. ->execute()
  27. ->fetchObject();
  28. $this->assertNotEmpty($result);
  29. $this->assertEquals($value, $result->value);
  30. $this->assertEquals($term->cvterm_id, $result->type_id);
  31. $this->assertEquals('0', $result->rank);
  32. }
  33. /**
  34. * @group chado
  35. * @group api
  36. *
  37. */
  38. public function test_chado_get_property() {
  39. $feature = factory('chado.feature')->create();
  40. $term = factory('chado.cvterm')->create();
  41. $value = 'chado_API_test_value';
  42. // Linker column
  43. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  44. $property = [
  45. 'type_id' => $term->cvterm_id,
  46. 'value' => $value,
  47. ];
  48. $prop = chado_insert_property($record, $property);
  49. $retrieved = chado_get_property($record, $property);
  50. $this->assertNotFalse($retrieved);
  51. $this->assertEquals($value, $retrieved->value);
  52. $record = ['prop_id' => $prop['featureprop_id'], 'table' => 'feature'];
  53. $retrieved = chado_get_property($record, $property);
  54. $this->assertNotNull($retrieved);
  55. $this->assertEquals($value, $retrieved->value);
  56. }
  57. /**
  58. * @group chado
  59. * @group api
  60. */
  61. public function test_chado_update_property() {
  62. $feature = factory('chado.feature')->create();
  63. $term = factory('chado.cvterm')->create();
  64. $value = 'chado_API_test_value';
  65. $new_value = 'chado_API_new';
  66. // Linker column
  67. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  68. $property = [
  69. 'type_id' => $term->cvterm_id,
  70. 'value' => $value,
  71. ];
  72. chado_insert_property($record, $property);
  73. $property['value'] = $new_value;
  74. chado_update_property($record, $property);
  75. $result = db_select('chado.featureprop', 'f')
  76. ->fields('f')
  77. ->condition('f.feature_id', $feature->feature_id)
  78. ->execute()
  79. ->fetchObject();
  80. $this->assertNotEmpty($result);
  81. $this->assertEquals($new_value, $result->value);
  82. $this->assertEquals($term->cvterm_id, $result->type_id);
  83. $this->assertEquals('0', $result->rank);
  84. }
  85. /**
  86. * @group chado
  87. * @group api
  88. */
  89. public function test_chado_delete_property() {
  90. $feature = factory('chado.feature')->create();
  91. $term = factory('chado.cvterm')->create();
  92. $value = 'chado_API_test_value';
  93. // Linker column
  94. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  95. $property = [
  96. 'type_id' => $term->cvterm_id,
  97. 'value' => $value,
  98. ];
  99. chado_insert_property($record, $property);
  100. chado_delete_property($record, $property);
  101. $result = db_select('chado.featureprop', 'f')
  102. ->fields('f')
  103. ->condition('f.feature_id', $feature->feature_id)
  104. ->execute()
  105. ->fetchObject();
  106. $this->assertFalse($result);
  107. $prop = chado_insert_property($record, $property);
  108. $record = ['prop_id' => $prop['featureprop_id'], 'table' => 'feature'];
  109. chado_delete_property($record, $property);
  110. }
  111. /**
  112. * @group chado
  113. * @group api
  114. */
  115. function test_chado_get_record_with_property() {
  116. // * Get all records in the base table assigned one or more properties.
  117. $feature = factory('chado.feature')->create();
  118. $term = factory('chado.cvterm')->create();
  119. $value = 'chado_API_test_value';
  120. // Linker column
  121. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  122. $property = [
  123. 'type_id' => $term->cvterm_id,
  124. 'value' => $value,
  125. ];
  126. chado_insert_property($record, $property);
  127. unset($record['id']);
  128. $records = chado_get_record_with_property($record, $property);
  129. $this->assertNotEmpty($records);
  130. $this->assertEquals(1, count($records));
  131. $feature = factory('chado.feature')->create();
  132. $record = ['table' => 'feature', 'id' => $feature->feature_id];
  133. chado_insert_property($record, $property);
  134. $records = chado_get_record_with_property($record, $property);
  135. $this->assertNotEmpty($records);
  136. $this->assertEquals(2, count($records));
  137. }
  138. }