-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathWP_HTML_SpanTest.php
More file actions
73 lines (58 loc) · 1.67 KB
/
WP_HTML_SpanTest.php
File metadata and controls
73 lines (58 loc) · 1.67 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
<?php
/**
* Tests for WP_HTML_Span polyfill.
*
* @package WP_CLI\Entity\Compat
*/
namespace WP_CLI\Entity\Tests\Compat;
use PHPUnit\Framework\TestCase;
use WP_HTML_Span;
/**
* Test the WP_HTML_Span polyfill class.
*/
class WP_HTML_SpanTest extends TestCase {
/**
* Test constructor sets properties correctly.
*/
public function test_constructor_sets_start_and_length() {
$span = new WP_HTML_Span( 10, 25 );
$this->assertSame( 10, $span->start );
$this->assertSame( 25, $span->length );
}
/**
* Test constructor with zero values.
*/
public function test_constructor_with_zero_values() {
$span = new WP_HTML_Span( 0, 0 );
$this->assertSame( 0, $span->start );
$this->assertSame( 0, $span->length );
}
/**
* Test constructor with large values.
*/
public function test_constructor_with_large_values() {
$span = new WP_HTML_Span( 1000000, 5000000 );
$this->assertSame( 1000000, $span->start );
$this->assertSame( 5000000, $span->length );
}
/**
* Test properties are public and accessible.
*/
public function test_properties_are_public() {
$span = new WP_HTML_Span( 5, 10 );
// Properties should be directly accessible.
$span->start = 20;
$span->length = 30;
$this->assertSame( 20, $span->start );
$this->assertSame( 30, $span->length );
}
/**
* Test use case: extracting substring from document.
*/
public function test_use_case_extract_substring() {
$document = '<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->';
$span = new WP_HTML_Span( 21, 18 ); // "<p>Hello World</p>"
$extracted = substr( $document, $span->start, $span->length );
$this->assertSame( '<p>Hello World</p>', $extracted );
}
}