LinkoutTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Tests\includes;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class LinkoutTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * Test tripal_blast_generate_linkout_link().
  10. *
  11. * @dataProvider provideBlastHit
  12. */
  13. public function testGeneralLinkout($hit) {
  14. // Test with no query parameters.
  15. $url_prefix = 'http://fake/url/prefix';
  16. $info = [
  17. 'query_name' => 'Fred',
  18. 'score' => 33,
  19. 'e-value' => '3.4e-55',
  20. ];
  21. $hit->{'linkout_id'} = 'Sarah';
  22. $result = tripal_blast_generate_linkout_link($url_prefix, $hit, $info);
  23. $expect = '<a href="http://fake/url/prefixSarah" target="_blank">Sarah</a>';
  24. $this->assertEquals($expect, $result);
  25. // Check with Query paramters.
  26. $url_prefix = 'http://fake/url/prefix?me=you&he=her&hit=';
  27. $result = tripal_blast_generate_linkout_link($url_prefix, $hit, $info);
  28. $expect = '<a href="http://fake/url/prefix?me=you&amp;he=her&amp;hit=Sarah" target="_blank">Sarah</a>';
  29. $this->assertEquals($expect, $result);
  30. }
  31. /**
  32. * Test tripal_blast_generate_linkout_gbrowse().
  33. *
  34. * @dataProvider provideBlastHit
  35. */
  36. public function testGBrowseLinkout($hit) {
  37. // Process HSPs for $info.
  38. foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
  39. $HSPs[] = (array) $hsp_xml;
  40. }
  41. // Test with no query parameters.
  42. $url_prefix = 'http://fake/url/prefix';
  43. $info = [
  44. 'query_name' => 'Fred',
  45. 'score' => 33,
  46. 'e-value' => '3.4e-55',
  47. 'HSPs' => $HSPs,
  48. ];
  49. $hit->{'linkout_id'} = 'Sarah';
  50. $result = tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info);
  51. $expect = '<a href="http://fake/url/prefix?ref=Sarah;&amp;start=1684180;&amp;stop=4062210;&amp;add=Sarah%20BLAST%20BlastHit%204058460..4058900%2C4061822..4062210%2C4059787..4060062%2C4059171..4059331%2C4060624..4060765%2C4061617..4061719%2C4061248..4061345%2C4059420..4059514%2C4061415..4061500%2C1684180..1684365%2C4060282..4060361%2C4059598..4059660%2C4060479..4060539%2C4059018..4059076%2C4060854..4060909%2C1686050..1686133%2C1685333..1685464%2C1685160..1685217%2C2213219..2213247;&amp;h_feat=BlastHit" target="_blank">Sarah</a>';
  52. $this->assertEquals($expect, $result);
  53. }
  54. /**
  55. * Test tripal_blast_generate_linkout_jbrowse().
  56. *
  57. * @dataProvider provideBlastHit
  58. */
  59. public function testJBrowseLinkout($hit) {
  60. // Proccess the HSPs for $info.
  61. foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
  62. $HSPs[] = (array) $hsp_xml;
  63. }
  64. // Test with no query parameters.
  65. $url_prefix = 'http://myserver.com/jbrowse/databasica/?tracks=myfavtrack,anoktrack,blast&';
  66. $info = [
  67. 'query_name' => 'Fred',
  68. 'score' => 33,
  69. 'e-value' => '3.4e-55',
  70. 'HSPs' => $HSPs,
  71. ];
  72. $hit->{'linkout_id'} = 'Sarah';
  73. $hit->{'hit_name'} = 'Needleman';
  74. $result = tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info);
  75. $expect = '<a href="http://myserver.com/jbrowse/databasica/?tracks=myfavtrack,anoktrack,blast&amp;loc=Sarah:1287842..4458548&amp;addFeatures=[{&quot;seq_id&quot;:&quot;Sarah&quot;,&quot;start&quot;:1684180,&quot;end&quot;:4062210,&quot;name&quot;:&quot;Fred Blast Hit&quot;,&quot;strand&quot;:1,&quot;subfeatures&quot;:[{&quot;start&quot;:4058460,&quot;end&quot;:4058900,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4061822,&quot;end&quot;:4062210,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4059787,&quot;end&quot;:4060062,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4059171,&quot;end&quot;:4059331,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4060624,&quot;end&quot;:4060765,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4061617,&quot;end&quot;:4061719,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4061248,&quot;end&quot;:4061345,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4059420,&quot;end&quot;:4059514,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4061415,&quot;end&quot;:4061500,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:1684180,&quot;end&quot;:1684365,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4060282,&quot;end&quot;:4060361,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4059598,&quot;end&quot;:4059660,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4060479,&quot;end&quot;:4060539,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4059018,&quot;end&quot;:4059076,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:4060854,&quot;end&quot;:4060909,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:1686050,&quot;end&quot;:1686133,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:1685333,&quot;end&quot;:1685464,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:1685160,&quot;end&quot;:1685217,&quot;strand&quot;:&quot;1&quot;,&quot;type&quot;:&quot;match_part&quot;},{&quot;start&quot;:2213219,&quot;end&quot;:2213247,&quot;strand&quot;:&quot;-1&quot;,&quot;type&quot;:&quot;match_part&quot;}]}]&amp;addTracks=[{&quot;label&quot;:&quot;blast&quot;,&quot;key&quot;:&quot;BLAST Result&quot;,&quot;type&quot;:&quot;JBrowse/View/Track/CanvasFeatures&quot;,&quot;store&quot;:&quot;url&quot;}]" target="_blank">Sarah</a>';
  76. $this->assertEquals($expect, $result);
  77. }
  78. /**
  79. * Data Provider
  80. */
  81. public function provideBlastHit() {
  82. $result = simplexml_load_file(
  83. DRUPAL_ROOT .'/'. drupal_get_path('module','blast_ui')
  84. .'/tests/test_files/Citrus_sinensis-orange1.1g015632m.blastresults.xml'
  85. );
  86. $hit = $result->{'BlastOutput_iterations'}->{'Iteration'}[0]->{'Iteration_hits'}->{'Hit'};
  87. return [[$hit]];
  88. }
  89. }