PanelTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace yiiunit\debug;
  3. use yii\debug\Module;
  4. use yii\debug\Panel;
  5. class PanelTest extends TestCase
  6. {
  7. public function testGetTraceLine_DefaultLink()
  8. {
  9. $traceConfig = [
  10. 'file' => 'file.php',
  11. 'line' => 10
  12. ];
  13. $panel = $this->getPanel();
  14. $this->assertEquals('<a href="ide://open?url=file://file.php&line=10">file.php:10</a>', $panel->getTraceLine($traceConfig));
  15. }
  16. public function testGetTraceLine_DefaultLink_CustomText()
  17. {
  18. $traceConfig = [
  19. 'file' => 'file.php',
  20. 'line' => 10,
  21. 'text' => 'custom text'
  22. ];
  23. $panel = $this->getPanel();
  24. $this->assertEquals('<a href="ide://open?url=file://file.php&line=10">custom text</a>',
  25. $panel->getTraceLine($traceConfig));
  26. }
  27. public function testGetTraceLine_TextOnly()
  28. {
  29. $panel = $this->getPanel();
  30. $panel->module->traceLine = false;
  31. $traceConfig = [
  32. 'file' => 'file.php',
  33. 'line' => 10
  34. ];
  35. $this->assertEquals('file.php:10', $panel->getTraceLine($traceConfig));
  36. }
  37. public function testGetTraceLine_CustomLinkByString()
  38. {
  39. $traceConfig = [
  40. 'file' => 'file.php',
  41. 'line' => 10
  42. ];
  43. $panel = $this->getPanel();
  44. $panel->module->traceLine = '<a href="phpstorm://open?url=file://file.php&line=10">my custom phpstorm protocol</a>';
  45. $this->assertEquals('<a href="phpstorm://open?url=file://file.php&line=10">my custom phpstorm protocol</a>',
  46. $panel->getTraceLine($traceConfig));
  47. }
  48. public function testGetTraceLine_CustomLinkByCallback()
  49. {
  50. $traceConfig = [
  51. 'file' => 'file.php',
  52. 'line' => 10,
  53. ];
  54. $panel = $this->getPanel();
  55. $expected = 'http://my.custom.link';
  56. $panel->module->traceLine = function () use ($expected) {
  57. return $expected;
  58. };
  59. $this->assertEquals($expected, $panel->getTraceLine($traceConfig));
  60. }
  61. public function testGetTraceLine_CustomLinkByCallback_CustomText()
  62. {
  63. $traceConfig = [
  64. 'file' => 'file.php',
  65. 'line' => 10,
  66. 'text' => 'custom text'
  67. ];
  68. $panel = $this->getPanel();
  69. $panel->module->traceLine = function () {
  70. return '<a href="ide://open?url={file}&line={line}">{text}</a>';
  71. };
  72. $this->assertEquals('<a href="ide://open?url=file.php&line=10">custom text</a>',
  73. $panel->getTraceLine($traceConfig));
  74. }
  75. public function testGetTraceLine_tracePathMappings()
  76. {
  77. $traceConfig = [
  78. 'file' => '/app/file.php',
  79. 'line' => 10,
  80. ];
  81. $panel = $this->getPanel();
  82. $panel->module->tracePathMappings = [
  83. '/app' => '/newpath/' // intentional mismatch of trailing slashes
  84. ];
  85. $this->assertEquals('<a href="ide://open?url=file:///newpath/file.php&line=10">/app/file.php:10</a>',
  86. $panel->getTraceLine($traceConfig));
  87. }
  88. public function testGetTraceLine_tracePathMappings_Multiple()
  89. {
  90. $traceConfig = [
  91. 'file' => '/app/data/file.php',
  92. 'line' => 10,
  93. ];
  94. $panel = $this->getPanel();
  95. $panel->module->tracePathMappings = [
  96. '/app/data' => '/app/localdata',
  97. '/app' => '/newpath'
  98. ];
  99. $this->assertEquals('<a href="ide://open?url=file:///app/localdata/file.php&line=10">/app/data/file.php:10</a>',
  100. $panel->getTraceLine($traceConfig));
  101. }
  102. protected function setUp()
  103. {
  104. parent::setUp();
  105. $this->mockWebApplication();
  106. }
  107. private function getPanel()
  108. {
  109. return new Panel(['module' => new Module('debug')]);
  110. }
  111. }