-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathHelpTest.php
More file actions
175 lines (128 loc) · 4.86 KB
/
Copy pathHelpTest.php
File metadata and controls
175 lines (128 loc) · 4.86 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
use WP_CLI\Tests\TestCase;
class HelpTest extends TestCase {
public static function set_up_before_class() {
require_once dirname( __DIR__ ) . '/php/class-wp-cli.php';
require_once dirname( __DIR__ ) . '/php/class-wp-cli-command.php';
require_once dirname( __DIR__ ) . '/php/commands/help.php';
}
public function test_parse_reference_links(): void {
$original_force_hyperlink = getenv( 'FORCE_HYPERLINK' );
putenv( 'FORCE_HYPERLINK=0' );
try {
$test_class = new ReflectionClass( 'Help_Command' );
$method = $test_class->getMethod( 'parse_reference_links' );
if ( PHP_VERSION_ID < 80100 ) {
// @phpstan-ignore method.deprecated
$method->setAccessible( true );
}
$desc = 'This is a [reference link](https://wordpress.org/). It should be displayed very nice!';
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
This is a [reference link][1]. It should be displayed very nice!
---
[1] https://wordpress.org/
EOL;
$this->assertSame( $expected, $result );
$desc = 'This is a [reference link](https://wordpress.org/) and [second link](http://wp-cli.org/). It should be displayed very nice!';
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
This is a [reference link][1] and [second link][2]. It should be displayed very nice!
---
[1] https://wordpress.org/
[2] http://wp-cli.org/
EOL;
$this->assertSame( $expected, $result );
$desc = <<<'EOL'
This is a [reference link](https://wordpress.org/) and [second link](http://wp-cli.org/).
It should be displayed very nice!
EOL;
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
This is a [reference link][1] and [second link][2].
It should be displayed very nice!
---
[1] https://wordpress.org/
[2] http://wp-cli.org/
EOL;
$this->assertSame( $expected, $result );
$desc = <<<'EOL'
This is a [reference link](https://wordpress.org/) and [second link](http://wp-cli.org/).
It should be displayed very nice!
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
This is a [reference link][1] and [second link][2].
It should be displayed very nice!
---
[1] https://wordpress.org/
[2] http://wp-cli.org/
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$this->assertSame( $expected, $result );
$desc = <<<'EOL'
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$this->assertSame( $expected, $result );
$desc = <<<'EOL'
This is a long description.
It doesn't have any link.
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$result = $method->invokeArgs( null, [ $desc ] );
$expected = <<<'EOL'
This is a long description.
It doesn't have any link.
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$this->assertSame( $expected, $result );
} finally {
putenv( false === $original_force_hyperlink ? 'FORCE_HYPERLINK' : "FORCE_HYPERLINK=$original_force_hyperlink" );
}
}
public function test_parse_reference_links_with_forced_hyperlinks(): void {
$original_force_hyperlink = getenv( 'FORCE_HYPERLINK' );
putenv( 'FORCE_HYPERLINK=1' );
try {
$test_class = new ReflectionClass( 'Help_Command' );
$method = $test_class->getMethod( 'parse_reference_links' );
if ( PHP_VERSION_ID < 80100 ) {
// @phpstan-ignore method.deprecated
$method->setAccessible( true );
}
$desc = 'This is a [reference link](https://wordpress.org/). It should be displayed very nice!';
$result = $method->invokeArgs( null, [ $desc ] );
$expected_link = "\033]8;;https://wordpress.org/\033\\reference link\033]8;;\033\\";
$expected = "This is a {$expected_link}. It should be displayed very nice!";
$this->assertSame( $expected, $result );
$desc = <<<'EOL'
This is a [reference link](https://wordpress.org/) and [second link](http://wp-cli.org/).
It should be displayed very nice!
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$result = $method->invokeArgs( null, [ $desc ] );
$expected_link2 = "\033]8;;http://wp-cli.org/\033\\second link\033]8;;\033\\";
$expected = <<<EOL
This is a {$expected_link} and {$expected_link2}.
It should be displayed very nice!
## Example
It doesn't expect to be link here like [reference link](https://wordpress.org/).
EOL;
$this->assertSame( $expected, $result );
} finally {
putenv( false === $original_force_hyperlink ? 'FORCE_HYPERLINK' : "FORCE_HYPERLINK=$original_force_hyperlink" );
}
}
}