PanelTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. protected function setUp()
  76. {
  77. parent::setUp();
  78. $this->mockWebApplication();
  79. }
  80. private function getPanel()
  81. {
  82. return new Panel(['module' => new Module('debug')]);
  83. }
  84. }