-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTranscriptParserTest.php
More file actions
124 lines (102 loc) · 3.25 KB
/
TranscriptParserTest.php
File metadata and controls
124 lines (102 loc) · 3.25 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
<?php
namespace MrMySQL\YoutubeTranscript\Tests;
use MrMySQL\YoutubeTranscript\TranscriptParser;
use PHPUnit\Framework\TestCase;
class TranscriptParserTest extends TestCase
{
/**
* Test parsing a valid XML string without preserving formatting.
*/
public function testParseValidXmlWithoutFormatting(): void
{
$xml = <<<XML
<transcript>
<text start="0.0" dur="1.5">Hello, world!</text>
<text start="1.5" dur="2.0">Welcome to testing.</text>
</transcript>
XML;
$expected = [
['text' => 'Hello, world!', 'start' => 0.0, 'duration' => 1.5],
['text' => 'Welcome to testing.', 'start' => 1.5, 'duration' => 2.0],
];
$result = TranscriptParser::parse($xml, false);
$this->assertEquals($expected, $result);
}
/**
* Test parsing a valid XML string with formatting preservation.
*/
public function testParseValidXmlWithFormatting(): void
{
$xml = <<<XML
<transcript>
<text start="0.0" dur="1.5">Hello, <b>world</b>!</text>
<text start="1.5" dur="2.0">Welcome to <i>testing</i>.</text>
</transcript>
XML;
$expected = [
['text' => 'Hello, <b>world</b>!', 'start' => 0.0, 'duration' => 1.5],
['text' => 'Welcome to <i>testing</i>.', 'start' => 1.5, 'duration' => 2.0],
];
$result = TranscriptParser::parse($xml, true);
$this->assertEquals($expected, $result);
}
/**
* Test parsing an empty XML string.
*/
public function testParseEmptyXml(): void
{
$result = TranscriptParser::parse('', false);
$this->assertEmpty($result);
}
/**
* Test parsing an XML string with unsupported tags.
*/
public function testParseXmlWithUnsupportedTags(): void
{
$xml = <<<XML
<transcript>
<text start="0.0" dur="1.5">Hello, <custom>world</custom>!</text>
<text start="1.5" dur="2.0">Welcome to <unknown>testing</unknown>.</text>
</transcript>
XML;
$expected = [
['text' => 'Hello, world!', 'start' => 0.0, 'duration' => 1.5],
['text' => 'Welcome to testing.', 'start' => 1.5, 'duration' => 2.0],
];
$result = TranscriptParser::parse($xml, false);
$this->assertEquals($expected, $result);
}
/**
* Test parsing an invalid XML string.
*/
public function testParseInvalidXml(): void
{
$xml = <<<XML
<transcript>
<text start="0.0" dur="1.5">Hello, world!</text>
<text start="1.5" dur="2.0">Welcome to testing.
</transcript>
XML;
$result = TranscriptParser::parse($xml, false);
// Expecting an empty result due to invalid XML.
$this->assertEmpty($result);
}
/**
* Test parsing an XML string with missing attributes.
*/
public function testParseXmlWithMissingAttributes(): void
{
$xml = <<<XML
<transcript>
<text>Hello, world!</text>
<text start="1.5">Welcome to testing.</text>
</transcript>
XML;
$expected = [
['text' => 'Hello, world!', 'start' => 0.0, 'duration' => 0.0],
['text' => 'Welcome to testing.', 'start' => 1.5, 'duration' => 0.0],
];
$result = TranscriptParser::parse($xml, false);
$this->assertEquals($expected, $result);
}
}