123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Tests\includes;
- use StatonLab\TripalTestSuite\DBTransaction;
- use StatonLab\TripalTestSuite\TripalTestCase;
- class LinkoutTest extends TripalTestCase {
- // Uncomment to auto start and rollback db transactions per test method.
- use DBTransaction;
- /**
- * Test tripal_blast_generate_linkout_link().
- *
- * @dataProvider provideBlastHit
- */
- public function testGeneralLinkout($hit) {
- // Test with no query parameters.
- $url_prefix = 'http://fake/url/prefix';
- $info = [
- 'query_name' => 'Fred',
- 'score' => 33,
- 'e-value' => '3.4e-55',
- ];
- $hit->{'linkout_id'} = 'Sarah';
- $result = tripal_blast_generate_linkout_link($url_prefix, $hit, $info);
- $expect = '<a href="http://fake/url/prefixSarah" target="_blank">Sarah</a>';
- $this->assertEquals($expect, $result);
- // Check with Query paramters.
- $url_prefix = 'http://fake/url/prefix?me=you&he=her&hit=';
- $result = tripal_blast_generate_linkout_link($url_prefix, $hit, $info);
- $expect = '<a href="http://fake/url/prefix?me=you&he=her&hit=Sarah" target="_blank">Sarah</a>';
- $this->assertEquals($expect, $result);
- }
- /**
- * Test tripal_blast_generate_linkout_gbrowse().
- *
- * @dataProvider provideBlastHit
- */
- public function testGBrowseLinkout($hit) {
- // Process HSPs for $info.
- foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
- $HSPs[] = (array) $hsp_xml;
- }
- // Test with no query parameters.
- $url_prefix = 'http://fake/url/prefix';
- $info = [
- 'query_name' => 'Fred',
- 'score' => 33,
- 'e-value' => '3.4e-55',
- 'HSPs' => $HSPs,
- ];
- $hit->{'linkout_id'} = 'Sarah';
- $result = tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info);
- $expect = '<a href="http://fake/url/prefix?ref=Sarah;&start=1684180;&stop=4062210;&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;&h_feat=BlastHit" target="_blank">Sarah</a>';
- $this->assertEquals($expect, $result);
- }
- /**
- * Test tripal_blast_generate_linkout_jbrowse().
- *
- * @dataProvider provideBlastHit
- */
- public function testJBrowseLinkout($hit) {
- // Proccess the HSPs for $info.
- foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
- $HSPs[] = (array) $hsp_xml;
- }
- // Test with no query parameters.
- $url_prefix = 'http://myserver.com/jbrowse/databasica/?tracks=myfavtrack,anoktrack,blast&';
- $info = [
- 'query_name' => 'Fred',
- 'score' => 33,
- 'e-value' => '3.4e-55',
- 'HSPs' => $HSPs,
- ];
- $hit->{'linkout_id'} = 'Sarah';
- $hit->{'hit_name'} = 'Needleman';
- $result = tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info);
- $expect = '<a href="http://myserver.com/jbrowse/databasica/?tracks=myfavtrack,anoktrack,blast&loc=Sarah:1287842..4458548&addFeatures=[{"seq_id":"Sarah","start":1684180,"end":4062210,"name":"Fred Blast Hit","strand":1,"subfeatures":[{"start":4058460,"end":4058900,"strand":"1","type":"match_part"},{"start":4061822,"end":4062210,"strand":"1","type":"match_part"},{"start":4059787,"end":4060062,"strand":"1","type":"match_part"},{"start":4059171,"end":4059331,"strand":"1","type":"match_part"},{"start":4060624,"end":4060765,"strand":"1","type":"match_part"},{"start":4061617,"end":4061719,"strand":"1","type":"match_part"},{"start":4061248,"end":4061345,"strand":"1","type":"match_part"},{"start":4059420,"end":4059514,"strand":"1","type":"match_part"},{"start":4061415,"end":4061500,"strand":"1","type":"match_part"},{"start":1684180,"end":1684365,"strand":"1","type":"match_part"},{"start":4060282,"end":4060361,"strand":"1","type":"match_part"},{"start":4059598,"end":4059660,"strand":"1","type":"match_part"},{"start":4060479,"end":4060539,"strand":"1","type":"match_part"},{"start":4059018,"end":4059076,"strand":"1","type":"match_part"},{"start":4060854,"end":4060909,"strand":"1","type":"match_part"},{"start":1686050,"end":1686133,"strand":"1","type":"match_part"},{"start":1685333,"end":1685464,"strand":"1","type":"match_part"},{"start":1685160,"end":1685217,"strand":"1","type":"match_part"},{"start":2213219,"end":2213247,"strand":"-1","type":"match_part"}]}]&addTracks=[{"label":"blast","key":"BLAST Result","type":"JBrowse/View/Track/CanvasFeatures","store":"url"}]" target="_blank">Sarah</a>';
- $this->assertEquals($expect, $result);
- }
- /**
- * Data Provider
- */
- public function provideBlastHit() {
- $result = simplexml_load_file(
- DRUPAL_ROOT .'/'. drupal_get_path('module','blast_ui')
- .'/tests/test_files/Citrus_sinensis-orange1.1g015632m.blastresults.xml'
- );
- $hit = $result->{'BlastOutput_iterations'}->{'Iteration'}[0]->{'Iteration_hits'}->{'Hit'};
-
- return [[$hit]];
- }
- }
|