Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
62.50% |
5 / 8 |
CRAP | |
82.35% |
14 / 17 |
MockPageContent | |
0.00% |
0 / 1 |
|
62.50% |
5 / 8 |
13.93 | |
82.35% |
14 / 17 |
__construct | |
100.00% |
1 / 1 |
3 | |
100.00% |
3 / 3 |
|||
getRoles | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
hasRole | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
checkRole | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
getModel | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getFormat | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getContent | |
0.00% |
0 / 1 |
2.06 | |
75.00% |
3 / 4 |
|||
getRedirectTarget | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
<?php | |
declare( strict_types = 1 ); | |
namespace Wikimedia\Parsoid\Mocks; | |
use Wikimedia\Parsoid\Config\PageContent; | |
class MockPageContent extends PageContent { | |
/** | |
* Alas, this is public because parserTests is reaching in and altering | |
* the main content when various modes are run. | |
* | |
* @var array | |
*/ | |
public $data = []; | |
/** | |
* @param array $data Page content data. Keys are roles, values are arrays or strings. | |
* A string value is considered as an array [ 'content' => $value ]. Array keys are: | |
* - content: (string) The slot's content. | |
* - contentmodel: (string, default 'wikitext') The slot's content model. | |
* - contentformat: (string, default 'text/x-wiki') The slot's content format. | |
* - redirect: (string, optional) The redirect target (same format as PageConfig::getTitle), | |
* if this content is a redirect. | |
*/ | |
public function __construct( array $data ) { | |
foreach ( $data as $role => $v ) { | |
$this->data[$role] = is_string( $v ) ? [ 'content' => $v ] : $v; | |
} | |
} | |
/** @inheritDoc */ | |
public function getRoles(): array { | |
return array_keys( $this->data ); | |
} | |
/** @inheritDoc */ | |
public function hasRole( string $role ): bool { | |
return isset( $this->data[$role] ); | |
} | |
/** | |
* @param string $role | |
*/ | |
private function checkRole( string $role ): void { | |
if ( !isset( $this->data[$role] ) ) { | |
throw new \InvalidArgumentException( "Unknown role \"$role\"" ); | |
} | |
} | |
/** @inheritDoc */ | |
public function getModel( string $role ): string { | |
$this->checkRole( $role ); | |
return $this->data[$role]['contentmodel'] ?? 'wikitext'; | |
} | |
/** @inheritDoc */ | |
public function getFormat( string $role ): string { | |
$this->checkRole( $role ); | |
return $this->data[$role]['contentformat'] ?? 'text/x-wiki'; | |
} | |
/** @inheritDoc */ | |
public function getContent( string $role ): string { | |
$this->checkRole( $role ); | |
if ( !isset( $this->data[$role]['content'] ) ) { | |
throw new \InvalidArgumentException( 'Unknown role or missing content failure' ); | |
} | |
return $this->data[$role]['content']; | |
} | |
/** @inheritDoc */ | |
public function getRedirectTarget(): ?string { | |
return $this->data['main']['redirect'] ?? null; | |
} | |
} |