mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-17 12:43:02 +00:00
dbf5d7084a
Since SkinVector provides name via skin.json the name must be passed in the test constructor. This will be required as part of I5772eb760e4fc56d2062a333ba4d7ca6995f3db2 Change-Id: I4087deb8b0726c9959ac15d77a0ed2442e4890f6
113 lines
3 KiB
PHP
113 lines
3 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Tests\Integration;
|
|
|
|
use MediaWikiIntegrationTestCase;
|
|
use RequestContext;
|
|
use SkinVector;
|
|
use Title;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* Class VectorTemplateTest
|
|
* @package MediaWiki\Skins\Vector\Tests\Unit
|
|
* @group Vector
|
|
* @group Skins
|
|
*
|
|
* @coversDefaultClass \SkinVector
|
|
*/
|
|
class SkinVectorTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @return \VectorTemplate
|
|
*/
|
|
private function provideVectorTemplateObject() {
|
|
$template = new SkinVector( [ 'name' => 'vector' ] );
|
|
return $template;
|
|
}
|
|
|
|
/**
|
|
* @param string $nodeString an HTML of the node we want to verify
|
|
* @param string $tag Tag of the element we want to check
|
|
* @param string $attribute Attribute of the element we want to check
|
|
* @param string $search Value of the attribute we want to verify
|
|
* @return bool
|
|
*/
|
|
private function expectNodeAttribute( $nodeString, $tag, $attribute, $search ) {
|
|
$node = new \DOMDocument();
|
|
$node->loadHTML( $nodeString );
|
|
$element = $node->getElementsByTagName( $tag )->item( 0 );
|
|
if ( !$element ) {
|
|
return false;
|
|
}
|
|
|
|
$values = explode( ' ', $element->getAttribute( $attribute ) );
|
|
return in_array( $search, $values );
|
|
}
|
|
|
|
/**
|
|
* @covers ::getMenuProps
|
|
*/
|
|
public function testGetMenuProps() {
|
|
$title = Title::newFromText( 'SkinVector' );
|
|
$context = RequestContext::getMain();
|
|
$context->setTitle( $title );
|
|
$context->setLanguage( 'fr' );
|
|
$vectorTemplate = $this->provideVectorTemplateObject();
|
|
$this->setTemporaryHook( 'PersonalUrls', [
|
|
function ( &$personal_urls, &$title, $skin ) {
|
|
$personal_urls = [];
|
|
}
|
|
] );
|
|
$this->setTemporaryHook( 'SkinTemplateNavigation', [
|
|
function ( &$skinTemplate, &$content_navigation ) {
|
|
$content_navigation = [
|
|
'actions' => [],
|
|
'namespaces' => [],
|
|
'variants' => [],
|
|
'views' => [],
|
|
];
|
|
}
|
|
] );
|
|
$openVectorTemplate = TestingAccessWrapper::newFromObject( $vectorTemplate );
|
|
|
|
$props = $openVectorTemplate->getMenuProps();
|
|
$views = $props['data-page-actions'];
|
|
$namespaces = $props['data-namespace-tabs'];
|
|
|
|
$this->assertSame(
|
|
[
|
|
'id' => 'p-views',
|
|
'label-id' => 'p-views-label',
|
|
'label' => $context->msg( 'views' )->text(),
|
|
'list-classes' => 'vector-menu-content-list',
|
|
'html-items' => '',
|
|
'is-dropdown' => false,
|
|
'html-tooltip' => '',
|
|
'html-after-portal' => '',
|
|
'class' => 'vector-menu-empty emptyPortlet vector-menu vector-menu-tabs vectorTabs',
|
|
],
|
|
$views
|
|
);
|
|
|
|
$variants = $props['data-variants'];
|
|
$actions = $props['data-page-actions-more'];
|
|
$this->assertSame(
|
|
'vector-menu-empty emptyPortlet vector-menu vector-menu-tabs vectorTabs',
|
|
$namespaces['class']
|
|
);
|
|
$this->assertSame(
|
|
'vector-menu-empty emptyPortlet vector-menu vector-menu-dropdown vectorMenu',
|
|
$variants['class']
|
|
);
|
|
$this->assertSame(
|
|
'vector-menu-empty emptyPortlet vector-menu vector-menu-dropdown vectorMenu',
|
|
$actions['class']
|
|
);
|
|
$this->assertSame(
|
|
'vector-menu-empty emptyPortlet vector-menu',
|
|
$props['data-personal-menu']['class']
|
|
);
|
|
}
|
|
|
|
}
|