ChadoQueryTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class ChadoQueryTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * @group filter
  10. * See PR 827.
  11. */
  12. public function test_filter_level() {
  13. $stock = factory('chado.stock')->create(['uniquename' => 'octopus_core_test_name']);
  14. // Test 1. Pass a single filter.
  15. $selector = [
  16. 'stock_id' => $stock->stock_id,
  17. 'uniquename' => [
  18. 'op' => 'LIKE',
  19. 'data' => 'octopus%',
  20. ],
  21. ];
  22. $object = chado_generate_var('stock', $selector);
  23. $this->assertNotNull($object->stock_id);
  24. $this->assertEquals($stock->stock_id, $object->stock_id);
  25. // Test 2 Pass an array of filters with a single item.
  26. $selector = [
  27. 'stock_id' => $stock->stock_id,
  28. 'uniquename' => [
  29. [
  30. 'op' => 'LIKE',
  31. 'data' => 'octopus%',
  32. ],
  33. ],
  34. ];
  35. $object = chado_generate_var('stock', $selector);
  36. $this->assertNotNull($object->stock_id);
  37. $this->assertEquals($stock->stock_id, $object->stock_id);
  38. // Test 3 Pass an array of filters with multiple items.
  39. $selector = [
  40. 'type_id' => [
  41. [
  42. 'op' => '>',
  43. 'data' => ($stock->type_id - 1),
  44. ],
  45. [
  46. 'op' => '<',
  47. 'data' => ($stock->type_id + 1),
  48. ],
  49. ],
  50. ];
  51. $object = chado_generate_var('stock', $selector);
  52. $this->assertNotNull($object->stock_id);
  53. $this->assertEquals($stock->stock_id, $object->stock_id);
  54. }
  55. }