ChadoQueryTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = array(
  16. 'stock_id' => $stock->stock_id,
  17. 'uniquename' => array(
  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 = array(
  27. 'stock_id' => $stock->stock_id,
  28. 'uniquename' => array(
  29. array(
  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 = array(
  40. 'type_id' => array(
  41. array(
  42. 'op' => '>',
  43. 'data' => ($stock->type_id - 1),
  44. ),
  45. array(
  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. }