2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
|
2022-05-03 18:11:54 +00:00
|
|
|
namespace MediaWiki\Minerva;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2022-03-04 16:40:54 +00:00
|
|
|
use MediaWiki\Minerva\Skins\SkinMinerva;
|
2023-08-19 04:23:00 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2021-10-11 22:53:10 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2017-07-12 15:12:40 +00:00
|
|
|
use OutputPage;
|
|
|
|
use RequestContext;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2022-03-04 16:40:54 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Minerva\Skins\SkinMinerva
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2021-10-11 22:53:10 +00:00
|
|
|
class SkinMinervaTest extends MediaWikiIntegrationTestCase {
|
2023-08-01 00:12:59 +00:00
|
|
|
private const ATTRIBUTE_NOTIFICATION_HREF = [
|
|
|
|
'key' => 'href',
|
|
|
|
'value' => '/wiki/Special:Notifications',
|
|
|
|
];
|
|
|
|
private const ATTRIBUTE_NOTIFICATION_DATA_EVENT_NAME = [
|
|
|
|
'key' => 'data-event-name',
|
|
|
|
'value' => 'ui.notifications',
|
|
|
|
];
|
|
|
|
|
|
|
|
private const ATTRIBUTE_NOTIFICATION_DATA_COUNTER_TEXT = [
|
|
|
|
'key' => 'data-counter-text',
|
|
|
|
'value' => "13",
|
|
|
|
];
|
|
|
|
private const ATTRIBUTE_NOTIFICATION_DATA_COUNTER_NUM = [
|
|
|
|
'key' => 'data-counter-num',
|
|
|
|
'value' => 13,
|
|
|
|
];
|
|
|
|
private const ATTRIBUTE_NOTIFICATION_TITLE = [
|
|
|
|
'key' => 'title',
|
|
|
|
'value' => "Your alerts",
|
|
|
|
];
|
|
|
|
|
2021-01-15 20:57:04 +00:00
|
|
|
/**
|
|
|
|
* @param array $options
|
|
|
|
*/
|
2019-04-10 21:43:50 +00:00
|
|
|
private function overrideSkinOptions( $options ) {
|
|
|
|
$mockOptions = new SkinOptions();
|
|
|
|
$mockOptions->setMultiple( $options );
|
|
|
|
$this->setService( 'Minerva.SkinOptions', $mockOptions );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::setContext
|
|
|
|
* @covers ::hasCategoryLinks
|
|
|
|
*/
|
|
|
|
public function testHasCategoryLinksWhenOptionIsOff() {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->never() )
|
|
|
|
->method( 'getCategoryLinks' );
|
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
2022-03-10 21:39:37 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
2021-11-13 17:58:14 +00:00
|
|
|
$this->assertFalse( $skin->hasCategoryLinks() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideHasCategoryLinks
|
|
|
|
* @param array $categoryLinks
|
|
|
|
* @param bool $expected
|
|
|
|
* @covers ::setContext
|
2017-12-29 20:26:59 +00:00
|
|
|
* @covers ::hasCategoryLinks
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
public function testHasCategoryLinks( array $categoryLinks, $expected ) {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->once() )
|
|
|
|
->method( 'getCategoryLinks' )
|
2021-12-17 10:29:48 +00:00
|
|
|
->willReturn( $categoryLinks );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
2022-03-10 21:39:37 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
2022-03-04 19:11:16 +00:00
|
|
|
$this->assertEquals( $expected, $skin->hasCategoryLinks() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 08:58:18 +00:00
|
|
|
public static function provideHasCategoryLinks() {
|
2017-07-12 15:12:40 +00:00
|
|
|
return [
|
|
|
|
[ [], false ],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>',
|
|
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'unexpected' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
|
|
],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2023-08-01 00:12:59 +00:00
|
|
|
|
|
|
|
public static function provideGetNotificationButtons() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[],
|
|
|
|
[]
|
|
|
|
],
|
|
|
|
//
|
|
|
|
// CIRCLE
|
|
|
|
//
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'tag-name' => 'a',
|
|
|
|
'classes' => 'mw-echo-notifications-badge mw-echo-notification-badge-nojs '
|
|
|
|
. ' mw-echo-unseen-notifications',
|
|
|
|
'array-attributes' => [
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_HREF,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_TEXT,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_NUM,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_TITLE,
|
|
|
|
[
|
|
|
|
'key' => 'id',
|
|
|
|
'value' => 'pt-notifications-alert',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'data-icon' => [
|
|
|
|
'icon' => 'circle'
|
|
|
|
],
|
|
|
|
'label' => 'Alerts (13)',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'name' => 'notifications-alert',
|
|
|
|
'id' => 'pt-notifications-alert',
|
|
|
|
'class' => 'notification-count notification-unseen mw-echo-unseen-notifications mw-list-item',
|
|
|
|
'array-links' => [
|
|
|
|
[
|
|
|
|
'icon' => 'circle',
|
|
|
|
'array-attributes' => [
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_HREF,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_TEXT,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_NUM,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_TITLE,
|
|
|
|
[
|
|
|
|
'key' => 'class',
|
|
|
|
'value' => 'mw-echo-notifications-badge '
|
|
|
|
. 'mw-echo-notification-badge-nojs oo-ui-icon-bellOutline '
|
|
|
|
. 'mw-echo-unseen-notifications',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'text' => 'Alerts (13)'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
],
|
|
|
|
//
|
|
|
|
// BELL
|
|
|
|
//
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'tag-name' => 'a',
|
|
|
|
'classes' => 'mw-echo-notifications-badge mw-echo-notification-badge-nojs',
|
|
|
|
'array-attributes' => [
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_HREF,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_TEXT,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_NUM,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_TITLE,
|
|
|
|
[
|
|
|
|
'key' => 'id',
|
|
|
|
'value' => 'pt-notifications-alert',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'data-icon' => [
|
2023-09-05 17:07:13 +00:00
|
|
|
'icon' => 'bellOutline-base20'
|
2023-08-01 00:12:59 +00:00
|
|
|
],
|
|
|
|
'label' => 'Alerts (13)',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'html-item' => 'n/a',
|
|
|
|
'name' => 'notifications-alert',
|
|
|
|
'html' => 'HTML',
|
|
|
|
'id' => 'pt-notifications-alert',
|
|
|
|
'class' => 'mw-list-item',
|
|
|
|
'array-links' => [
|
|
|
|
[
|
2023-09-05 17:07:13 +00:00
|
|
|
'icon' => 'bellOutline-base20',
|
2023-08-01 00:12:59 +00:00
|
|
|
'array-attributes' => [
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_HREF,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_TEXT,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_DATA_COUNTER_NUM,
|
|
|
|
self::ATTRIBUTE_NOTIFICATION_TITLE,
|
|
|
|
[
|
|
|
|
'key' => 'class',
|
|
|
|
'value' => 'mw-echo-notifications-badge mw-echo-notification-badge-nojs',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'text' => 'Alerts (13)'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetNotificationButtons
|
|
|
|
* @param array $expected
|
|
|
|
* @param array $from
|
|
|
|
* @covers ::getNotificationButtons
|
|
|
|
*/
|
|
|
|
public function testGetNotificationButtons( $expected, $from ) {
|
|
|
|
$btns = SkinMinerva::getNotificationButtons( $from );
|
|
|
|
$this->assertEquals( $expected['classes'] ?? '', $btns[0]['classes'] ?? '' );
|
|
|
|
$this->assertEquals( $expected['data-attributes'] ?? [], $btns[0]['data-attributes'] ?? [] );
|
|
|
|
$this->assertEquals( $expected['data-icon'] ?? [], $btns[0]['data-icon'] ?? [] );
|
|
|
|
$this->assertEquals( $expected['data-label'] ?? '', $btns[0]['data-label'] ?? '' );
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|