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