| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use LogEntryBase; |
| 6 |
use PHPUnit\Framework\Assert; |
| 7 |
use XMLReader; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class DumpAsserter { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $xml = null; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
protected $schemaVersion; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
private $varMapping = []; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function __construct( $schemaVersion ) { |
| 37 |
$this->schemaVersion = $schemaVersion; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public function skipToNode( $name, $allowAscend = false ) { |
| 53 |
$depth = 0; |
| 54 |
while ( true ) { |
| 55 |
$current = $this->xml->name; |
| 56 |
if ( $this->xml->nodeType == XMLReader::ELEMENT ) { |
| 57 |
if ( $current == $name ) { |
| 58 |
return true; |
| 59 |
} |
| 60 |
|
| 61 |
if ( !$this->xml->isEmptyElement ) { |
| 62 |
$depth++; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if ( $this->xml->nodeType == XMLReader::END_ELEMENT ) { |
| 67 |
$depth--; |
| 68 |
if ( $depth < 0 && !$allowAscend ) { |
| 69 |
return false; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
if ( !$this->xml->read() ) { |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public function skipIntoNode( $name, $allowAscend = false ) { |
| 93 |
Assert::assertTrue( $this->skipToNode( $name, $allowAscend ), |
| 94 |
"Skipping to $name" ); |
| 95 |
|
| 96 |
Assert::assertTrue( !$this->xml->isEmptyElement, |
| 97 |
"Skipping into $name" ); |
| 98 |
|
| 99 |
$this->xml->read(); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public function skipToNodeEnd( $name ) { |
| 111 |
while ( $this->xml->read() ) { |
| 112 |
if ( $this->xml->nodeType == XMLReader::END_ELEMENT && |
| 113 |
$this->xml->name == $name |
| 114 |
) { |
| 115 |
return true; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public function skipPastNodeEnd( $name ) { |
| 133 |
Assert::assertTrue( $this->skipToNodeEnd( $name ), |
| 134 |
"Skipping to end of $name" ); |
| 135 |
while ( $this->xml->read() ) { |
| 136 |
if ( $this->xml->nodeType == XMLReader::ELEMENT ) { |
| 137 |
return true; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public function open( $fname ) { |
| 150 |
$this->xml = new XMLReader(); |
| 151 |
|
| 152 |
Assert::assertTrue( $this->xml->open( $fname ), |
| 153 |
"Opening temporary file $fname via XMLReader failed" ); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
public function assertDumpStart( $fname, $siteInfoTemplate = null, $language = 'en' ) { |
| 169 |
$this->open( $fname ); |
| 170 |
$this->assertDumpHead( $siteInfoTemplate, $language ); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public function assertDumpHead( $siteInfoTemplate = null, $language = 'en' ) { |
| 190 |
$this->assertNodeStart( 'mediawiki', false ); |
| 191 |
$this->assertAttributes( [ |
| 192 |
"xmlns" => "http://www.mediawiki.org/xml/export-{$this->schemaVersion}/", |
| 193 |
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", |
| 194 |
"xsi:schemaLocation" => "http://www.mediawiki.org/xml/export-{$this->schemaVersion}/ " |
| 195 |
. "http://www.mediawiki.org/xml/export-{$this->schemaVersion}.xsd", |
| 196 |
"version" => "{$this->schemaVersion}", |
| 197 |
"xml:lang" => "{$language}" |
| 198 |
] ); |
| 199 |
|
| 200 |
$this->assertNodeStart( 'siteinfo', false ); |
| 201 |
|
| 202 |
if ( $siteInfoTemplate ) { |
| 203 |
|
| 204 |
$this->assertDOM( $siteInfoTemplate ); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
$this->skipPastNodeEnd( 'siteinfo' ); |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public function assertDumpEnd( $name = "mediawiki" ) { |
| 219 |
$this->assertNodeEnd( $name, false ); |
| 220 |
if ( $this->xml->read() ) { |
| 221 |
$this->skipWhitespace(); |
| 222 |
} |
| 223 |
Assert::assertEquals( $this->xml->nodeType, XMLReader::NONE, |
| 224 |
"No proper entity left to parse" ); |
| 225 |
$this->close(); |
| 226 |
} |
| 227 |
|
| 228 |
public function close() { |
| 229 |
$this->xml->close(); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public function skipWhitespace() { |
| 236 |
$cont = true; |
| 237 |
while ( $cont && ( ( $this->xml->nodeType == XMLReader::NONE ) |
| 238 |
|| ( $this->xml->nodeType == XMLReader::WHITESPACE ) |
| 239 |
|| ( $this->xml->nodeType == XMLReader::SIGNIFICANT_WHITESPACE ) ) ) { |
| 240 |
$cont = $this->xml->read(); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
public function assertNodeStart( $name, $skip = true ) { |
| 254 |
$this->skipWhitespace(); |
| 255 |
Assert::assertEquals( $name, $this->xml->name, "Node name" ); |
| 256 |
Assert::assertEquals( XMLReader::ELEMENT, $this->xml->nodeType, "Node type" ); |
| 257 |
if ( $skip ) { |
| 258 |
Assert::assertTrue( $this->xml->read(), "Skipping past start tag" ); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
public function assertAttributes( $attributes, $skip = true ) { |
| 271 |
Assert::assertEquals( XMLReader::ELEMENT, $this->xml->nodeType, "Node type" ); |
| 272 |
$actualAttributes = $this->getAttributeArray( $this->xml ); |
| 273 |
|
| 274 |
$attributes = array_map( |
| 275 |
function ( $v ) { |
| 276 |
return $this->resolveVars( $v ); |
| 277 |
}, |
| 278 |
$attributes |
| 279 |
); |
| 280 |
$actualAttributes = array_intersect_key( $actualAttributes, $attributes ); |
| 281 |
|
| 282 |
Assert::assertEquals( $attributes, $actualAttributes, "Attributes" ); |
| 283 |
|
| 284 |
if ( $skip ) { |
| 285 |
Assert::assertTrue( $this->xml->read(), "Skipping past start tag" ); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public function assertEmptyNode( $name, $skip = true, $skip_ws = true ) { |
| 300 |
$this->assertNodeStart( $name, false ); |
| 301 |
Assert::assertFalse( !$this->xml->isEmptyElement, "$name tag has content" ); |
| 302 |
|
| 303 |
if ( $skip ) { |
| 304 |
Assert::assertTrue( $this->xml->read(), "Skipping $name tag" ); |
| 305 |
if ( ( $this->xml->nodeType == XMLReader::END_ELEMENT ) |
| 306 |
&& ( $this->xml->name == $name ) |
| 307 |
) { |
| 308 |
$this->xml->read(); |
| 309 |
} |
| 310 |
|
| 311 |
if ( $skip_ws ) { |
| 312 |
$this->skipWhitespace(); |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public function assertNodeEnd( $name, $skip = true ) { |
| 327 |
$this->skipWhitespace(); |
| 328 |
Assert::assertEquals( $name, $this->xml->name, "Node name" ); |
| 329 |
Assert::assertEquals( XMLReader::END_ELEMENT, $this->xml->nodeType, "Node type" ); |
| 330 |
if ( $skip ) { |
| 331 |
|
| 332 |
|
| 333 |
$this->xml->read(); |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public function assertTextNode( $name, $text, $skip_ws = true ) { |
| 349 |
$this->assertNodeStart( $name ); |
| 350 |
|
| 351 |
if ( $text !== false ) { |
| 352 |
$text = $this->resolveVars( $text ); |
| 353 |
$actual = $this->resolveVars( $this->xml->value ); |
| 354 |
Assert::assertEquals( $text, $actual, "Text of node " . $name ); |
| 355 |
} |
| 356 |
Assert::assertTrue( $this->xml->read(), "Skipping past processed text of " . $name ); |
| 357 |
$this->assertNodeEnd( $name ); |
| 358 |
|
| 359 |
if ( $skip_ws ) { |
| 360 |
$this->skipWhitespace(); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
public function assertPageStart( $id, $ns, $name ) { |
| 377 |
$this->assertNodeStart( "page" ); |
| 378 |
$this->assertTextNode( "title", $name ); |
| 379 |
$this->assertTextNode( "ns", $ns ); |
| 380 |
$this->assertTextNode( "id", $id ); |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
public function assertPageEnd() { |
| 388 |
$this->assertNodeEnd( "page" ); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public function assertRevisionProperties( $id, $summary, |
| 406 |
$text_sha1, $hasEarlyText = 'maybe', $parentid = false, |
| 407 |
$model = CONTENT_MODEL_WIKITEXT, $format = CONTENT_FORMAT_WIKITEXT, |
| 408 |
&$foundText = '' |
| 409 |
) { |
| 410 |
$this->assertTextNode( "id", $id ); |
| 411 |
if ( $parentid !== false ) { |
| 412 |
$this->assertTextNode( "parentid", $parentid ); |
| 413 |
} |
| 414 |
$this->assertTextNode( "timestamp", false ); |
| 415 |
|
| 416 |
$this->assertNodeStart( "contributor" ); |
| 417 |
$this->assertTextNode( "username", false ); |
| 418 |
$this->assertTextNode( "id", false ); |
| 419 |
$this->assertNodeEnd( "contributor" ); |
| 420 |
|
| 421 |
$this->assertTextNode( "comment", $summary ); |
| 422 |
|
| 423 |
if ( $this->schemaVersion >= XML_DUMP_SCHEMA_VERSION_11 ) { |
| 424 |
$this->assertTextNode( "origin", false ); |
| 425 |
} |
| 426 |
|
| 427 |
$this->assertTextNode( "model", $model ); |
| 428 |
|
| 429 |
$this->assertTextNode( "format", $format ); |
| 430 |
|
| 431 |
if ( $hasEarlyText === 'yes' || ( $this->xml->name == "text" && $hasEarlyText === 'maybe' ) ) { |
| 432 |
$foundText = true; |
| 433 |
$this->assertNodeStart( "text", false ); |
| 434 |
$this->xml->next(); |
| 435 |
$this->skipWhitespace(); |
| 436 |
} else { |
| 437 |
$foundText = false; |
| 438 |
} |
| 439 |
|
| 440 |
if ( $text_sha1 ) { |
| 441 |
$this->assertTextNode( "sha1", $text_sha1 ); |
| 442 |
} else { |
| 443 |
$this->assertEmptyNode( "sha1" ); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
public function assertRevision( $id, $summary, $text_id, $text_bytes, |
| 463 |
$text_sha1, $text = false, $parentid = false, |
| 464 |
$model = CONTENT_MODEL_WIKITEXT, $format = CONTENT_FORMAT_WIKITEXT |
| 465 |
) { |
| 466 |
$this->assertNodeStart( "revision" ); |
| 467 |
|
| 468 |
$this->assertRevisionProperties( |
| 469 |
$id, |
| 470 |
$summary, |
| 471 |
$text_sha1, |
| 472 |
'maybe', |
| 473 |
$parentid, |
| 474 |
$model, |
| 475 |
$format, |
| 476 |
$text_found |
| 477 |
); |
| 478 |
|
| 479 |
if ( !$text_found ) { |
| 480 |
$this->assertText( $id, $text_id, $text_bytes, $text ); |
| 481 |
} |
| 482 |
|
| 483 |
$this->assertNodeEnd( "revision" ); |
| 484 |
$this->skipWhitespace(); |
| 485 |
} |
| 486 |
|
| 487 |
public function assertText( $id, $text_id, $text_bytes, $text ) { |
| 488 |
$this->assertNodeStart( "text", false ); |
| 489 |
if ( $text_bytes !== false ) { |
| 490 |
Assert::assertEquals( $this->xml->getAttribute( "bytes" ), $text_bytes, |
| 491 |
"Attribute 'bytes' of revision " . $id ); |
| 492 |
} |
| 493 |
|
| 494 |
if ( $text === false ) { |
| 495 |
Assert::assertEquals( $this->xml->getAttribute( "id" ), $text_id, |
| 496 |
"Text id of revision " . $id ); |
| 497 |
Assert::assertNull( $this->xml->getAttribute( "xml:space" ), |
| 498 |
"xml:space attribute shout not be present" ); |
| 499 |
$this->assertEmptyNode( "text" ); |
| 500 |
} else { |
| 501 |
|
| 502 |
Assert::assertEquals( $this->xml->getAttribute( "xml:space" ), "preserve", |
| 503 |
"xml:space=preserve should be present" ); |
| 504 |
Assert::assertTrue( $this->xml->read(), "Skipping text start tag" ); |
| 505 |
Assert::assertEquals( $text, $this->xml->value, "Text of revision " . $id ); |
| 506 |
Assert::assertTrue( $this->xml->read(), "Skipping past text" ); |
| 507 |
$this->assertNodeEnd( "text" ); |
| 508 |
$this->skipWhitespace(); |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public function assertLogItem( $id, $user_name, $user_id, $comment, $type, |
| 526 |
$subtype, $title, $parameters = [] |
| 527 |
) { |
| 528 |
$this->assertNodeStart( "logitem" ); |
| 529 |
|
| 530 |
$this->assertTextNode( "id", $id ); |
| 531 |
$this->assertTextNode( "timestamp", false ); |
| 532 |
|
| 533 |
$this->assertNodeStart( "contributor" ); |
| 534 |
$this->assertTextNode( "username", $user_name ); |
| 535 |
$this->assertTextNode( "id", $user_id ); |
| 536 |
$this->assertNodeEnd( "contributor" ); |
| 537 |
|
| 538 |
if ( $comment !== null ) { |
| 539 |
$this->assertTextNode( "comment", $comment ); |
| 540 |
} |
| 541 |
$this->assertTextNode( "type", $type ); |
| 542 |
$this->assertTextNode( "action", $subtype ); |
| 543 |
$this->assertTextNode( "logtitle", $title ); |
| 544 |
|
| 545 |
$this->assertNodeStart( "params" ); |
| 546 |
$parameters_xml = LogEntryBase::extractParams( $this->xml->value, "$type/$subtype" ); |
| 547 |
Assert::assertEquals( $parameters, $parameters_xml ); |
| 548 |
Assert::assertTrue( $this->xml->read(), "Skipping past processed text of params" ); |
| 549 |
$this->assertNodeEnd( "params" ); |
| 550 |
|
| 551 |
$this->assertNodeEnd( "logitem" ); |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
public function getLineNumber( ?XMLReader $xml = null ) { |
| 562 |
$xml ??= $this->xml; |
| 563 |
|
| 564 |
if ( $xml->nodeType == XMLReader::NONE ) { |
| 565 |
return 0; |
| 566 |
} |
| 567 |
|
| 568 |
return $xml->expand()->getLineNo(); |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
public function assertDOM( $file ) { |
| 587 |
$exXml = new XMLReader(); |
| 588 |
|
| 589 |
Assert::assertTrue( $exXml->open( $file ), |
| 590 |
"Opening fixture file $file via XMLReader failed" ); |
| 591 |
|
| 592 |
$line = 0; |
| 593 |
while ( true ) { |
| 594 |
$line = max( $line, $this->getLineNumber( $exXml ) ); |
| 595 |
$location = "[$file line $line] "; |
| 596 |
|
| 597 |
while ( $exXml->nodeType == XMLReader::NONE |
| 598 |
|| $exXml->nodeType == XMLReader::WHITESPACE |
| 599 |
|| $exXml->nodeType == XMLReader::SIGNIFICANT_WHITESPACE |
| 600 |
|| $exXml->nodeType == XMLReader::COMMENT |
| 601 |
|| ( $exXml->nodeType == XMLReader::ELEMENT && $exXml->name === 'test:data' ) ) { |
| 602 |
|
| 603 |
|
| 604 |
if ( !$exXml->read() ) { |
| 605 |
break 2; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
if ( $exXml->nodeType == XMLReader::END_ELEMENT && $exXml->name === 'test:data' ) { |
| 610 |
break 2; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
while ( $this->xml->nodeType == XMLReader::NONE |
| 615 |
|| $this->xml->nodeType == XMLReader::WHITESPACE |
| 616 |
|| $this->xml->nodeType == XMLReader::SIGNIFICANT_WHITESPACE |
| 617 |
|| $this->xml->nodeType == XMLReader::COMMENT ) { |
| 618 |
Assert::assertTrue( $this->xml->read(), $location . 'Document ended unexpectedly' ); |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
if ( $exXml->nodeType == XMLReader::ELEMENT && $exXml->name === 'test:end' ) { |
| 623 |
break; |
| 624 |
} |
| 625 |
|
| 626 |
$line = max( $line, $this->getLineNumber( $exXml ) ); |
| 627 |
$location = "[$file line $line] "; |
| 628 |
|
| 629 |
Assert::assertSame( $exXml->nodeType, $this->xml->nodeType, $location . 'Node type' ); |
| 630 |
Assert::assertSame( $exXml->name, $this->xml->name, $location . 'Node type' ); |
| 631 |
Assert::assertSame( |
| 632 |
$exXml->hasValue, |
| 633 |
$this->xml->hasValue, |
| 634 |
$location . 'Node has value?' |
| 635 |
); |
| 636 |
Assert::assertSame( |
| 637 |
$exXml->hasAttributes, |
| 638 |
$this->xml->hasAttributes, |
| 639 |
$location . 'Node has attributes?' |
| 640 |
); |
| 641 |
|
| 642 |
if ( $exXml->hasValue ) { |
| 643 |
$expValue = $this->resolveVars( $exXml->value ); |
| 644 |
$actValue = $this->resolveVars( $this->xml->value ); |
| 645 |
Assert::assertSame( $expValue, $actValue, $location . 'Node value' ); |
| 646 |
} |
| 647 |
|
| 648 |
if ( $exXml->hasAttributes ) { |
| 649 |
$expectedAttributes = $this->getAttributeArray( $exXml ); |
| 650 |
$actualAttributes = $this->getAttributeArray( $this->xml ); |
| 651 |
|
| 652 |
Assert::assertEquals( $expectedAttributes, $actualAttributes, $location . 'Attributes' ); |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
if ( !$exXml->read() ) { |
| 657 |
break; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
if ( $exXml->nodeType == XMLReader::END_ELEMENT && $exXml->name === 'test:data' ) { |
| 662 |
break; |
| 663 |
} |
| 664 |
|
| 665 |
Assert::assertTrue( $this->xml->read(), $location . 'Document ended unexpectedly' ); |
| 666 |
} |
| 667 |
|
| 668 |
$exXml->close(); |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
public function stripTestTags( $text ) { |
| 679 |
$text = preg_replace( '@<!--.*?-->@s', '', $text ); |
| 680 |
$text = preg_replace( '@</?test:[^>]+>@', '', $text ); |
| 681 |
return $text; |
| 682 |
} |
| 683 |
|
| 684 |
private function getAttributeArray( ?XMLReader $xml = null ) { |
| 685 |
if ( !$xml ) { |
| 686 |
$xml = $this->xml; |
| 687 |
} |
| 688 |
|
| 689 |
if ( $xml->nodeType !== XMLReader::ELEMENT ) { |
| 690 |
return null; |
| 691 |
} |
| 692 |
|
| 693 |
if ( !$xml->hasAttributes ) { |
| 694 |
return []; |
| 695 |
} |
| 696 |
|
| 697 |
$attr = []; |
| 698 |
while ( $xml->moveToNextAttribute() ) { |
| 699 |
$attr[$xml->name] = $this->resolveVars( $xml->value ); |
| 700 |
} |
| 701 |
|
| 702 |
return $attr; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
public function resolveVars( $text ) { |
| 711 |
return str_replace( |
| 712 |
array_keys( $this->varMapping ), |
| 713 |
array_values( $this->varMapping ), |
| 714 |
$text |
| 715 |
); |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
public function setVarMapping( $name, $value ) { |
| 725 |
$key = '{{' . $name . '}}'; |
| 726 |
$this->varMapping[$key] = $value; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
public function getSchemaVersion() { |
| 733 |
return $this->schemaVersion; |
| 734 |
} |
| 735 |
|
| 736 |
} |