jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/365680 )
Change subject: Remove duplicated tests
......................................................................
Remove duplicated tests
These tests are duplicated in MobileFrontend and MinervaNeue
To make CI pass in wmf9 we need to make sure they are only
registered once (in the new place - MinervaNeue)
Change-Id: I67760c9c475a31c7003e59ed5515ed93bfd77d18
---
D tests/phpunit/MenuBuilderTest.php
D tests/phpunit/skins/SkinMinervaPageActionsTest.php
D tests/phpunit/skins/SkinMinervaTest.php
D tests/phpunit/skins/SkinUserPageHelperTest.php
4 files changed, 0 insertions(+), 940 deletions(-)
Approvals:
Thcipriani: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/MenuBuilderTest.php
b/tests/phpunit/MenuBuilderTest.php
deleted file mode 100644
index da6430c..0000000
--- a/tests/phpunit/MenuBuilderTest.php
+++ /dev/null
@@ -1,253 +0,0 @@
-<?php
-
-namespace Tests\MediaWiki\Minerva;
-
-use MediaWiki\Minerva\MenuBuilder;
-use MediaWiki\Minerva\MenuEntry;
-
-/**
- * @group MobileFrontend
- */
-class MenuTest extends \PHPUnit_Framework_TestCase {
- private $homeComponent = [
- 'text' => 'Home',
- 'href' => '/Main_page',
- 'class' => 'mw-ui-icon mw-ui-icon-before mw-ui-icon-home',
- 'data-event-name' => 'home',
- ];
-
- private $nearbyComponent = [
- 'text' => 'Nearby',
- 'href' => '/wiki/Special:Nearby',
- 'class' => 'mw-ui-icon mw-ui-icon-before mw-ui-icon-nearby',
- ];
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::getEntries
- */
- public function testItShouldntHaveEntriesByDefault() {
- $menu = new MenuBuilder();
-
- $this->assertEmpty( $menu->getEntries() );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- * @covers \MediaWiki\Minerva\MenuBuilder::search
- * @covers \MediaWiki\Minerva\MenuBuilder::getEntries
- * @covers \MediaWiki\Minerva\MenuEntry::addComponent
- */
- public function testInsertingAnEntry() {
- $menu = new MenuBuilder();
- $menu->insert( 'home' )
- ->addComponent(
- $this->homeComponent['text'],
- $this->homeComponent['href'],
- $this->homeComponent['class'],
- [
- 'data-event-name' =>
$this->homeComponent['data-event-name']
- ]
- );
-
- $expectedEntries = [
- [
- 'name' => 'home',
- 'components' => [ $this->homeComponent ],
- ],
- ];
-
- $this->assertEquals( $expectedEntries, $menu->getEntries() );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- * @covers \MediaWiki\Minerva\MenuBuilder::search
- * @covers \MediaWiki\Minerva\MenuBuilder::getEntries
- * @covers \MediaWiki\Minerva\MenuEntry::addComponent
- */
- public function testInsertingAnEntryAfterAnother() {
- $menu = new MenuBuilder();
- $menu->insert( 'home' )
- ->addComponent(
- $this->homeComponent['text'],
- $this->homeComponent['href'],
- $this->homeComponent['class'],
- [
- 'data-event-name' =>
$this->homeComponent['data-event-name']
- ]
- );
- $menu->insert( 'another_home' )
- ->addComponent(
- $this->homeComponent['text'],
- $this->homeComponent['href'],
- $this->homeComponent['class'],
- [
- 'data-event-name' =>
$this->homeComponent['data-event-name']
- ]
- );
- $menu->insertAfter( 'home', 'nearby' )
- ->addComponent(
- $this->nearbyComponent['text'],
- $this->nearbyComponent['href'],
- $this->nearbyComponent['class']
- );
-
- $expectedEntries = [
- [
- 'name' => 'home',
- 'components' => [ $this->homeComponent ],
- ],
- [
- 'name' => 'nearby',
- 'components' => [ $this->nearbyComponent ],
- ],
- [
- 'name' => 'another_home',
- 'components' => [ $this->homeComponent ],
- ],
- ];
-
- $this->assertEquals( $expectedEntries, $menu->getEntries() );
- }
-
- /**
- * @expectedException \DomainException
- * @expectedExceptionMessage The "home" entry doesn't exist.
- * @covers \MediaWiki\Minerva\MenuBuilder::insertAfter
- * @covers \MediaWiki\Minerva\MenuBuilder::search
- * @covers \MediaWiki\Minerva\MenuEntry::addComponent
- */
- public function testInsertAfterWhenTargetEntryDoesntExist() {
- $menu = new MenuBuilder();
- $menu->insertAfter( 'home', 'nearby' )
- ->addComponent(
- $this->nearbyComponent['text'],
- $this->nearbyComponent['href'],
- $this->nearbyComponent['class']
- );
- }
-
- /**
- * @expectedException \DomainException
- * @expectedExceptionMessage The "car" entry already exists.
- * @covers \MediaWiki\Minerva\MenuBuilder::insertAfter
- */
- public function testInsertAfterWithAnEntryWithAnExistingName() {
- $menu = new MenuBuilder();
- $menu->insert( 'home' );
- $menu->insert( 'car' );
- $menu->insertAfter( 'home', 'car' );
- }
-
- /**
- * @expectedException \DomainException
- * @expectedExceptionMessage The "home" entry already exists.
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- */
- public function testInsertingAnEntryWithAnExistingName() {
- $menu = new MenuBuilder();
- $menu->insert( 'home' );
- $menu->insert( 'home' );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- * @covers \MediaWiki\Minerva\MenuBuilder::insertAfter
- */
- public function testInsertingAnEntryAfterAnotherOne() {
- $menu = new MenuBuilder();
- $menu->insert( 'first' );
- $menu->insert( 'last' );
- $menu->insertAfter( 'first', 'middle' );
- $items = $menu->getEntries();
- $this->assertCount( 3, $items );
- $this->assertSame( 'first', $items[0]['name'] );
- $this->assertSame( 'middle', $items[1]['name'] );
- $this->assertSame( 'last', $items[2]['name'] );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- * @covers \MediaWiki\Minerva\MenuBuilder::getEntries
- * @covers \MediaWiki\Minerva\MenuEntry::addComponent
- */
- public function testinsertingAnEntryWithMultipleComponents() {
- $authLoginComponent = [
- 'text' => 'Phuedx (WMF)',
- 'href' => '/wiki/User:Phuedx_(WMF)',
- 'class' =>
- 'mw-ui-icon mw-ui-icon-before
mw-ui-icon-profile truncated-text primary-action',
- ];
- $authLogoutComponent = [
- 'text' => 'Logout',
- 'href' => '/wiki/Special:UserLogout',
- 'class' =>
- 'mw-ui-icon mw-ui-icon-element secondary-logout
secondary-action truncated-text',
- ];
-
- $menu = new MenuBuilder();
- $menu->insert( 'auth' )
- ->addComponent(
- $authLoginComponent['text'],
- $authLoginComponent['href'],
- $authLoginComponent['class']
- )
- ->addComponent(
- $authLogoutComponent['text'],
- $authLogoutComponent['href'],
- $authLogoutComponent['class']
- );
-
- $expectedEntries = [
- [
- 'name' => 'auth',
- 'components' => [
- $authLoginComponent,
- $authLogoutComponent
- ],
- ],
- ];
-
- $this->assertEquals( $expectedEntries, $menu->getEntries() );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuBuilder::insert
- * @covers \MediaWiki\Minerva\MenuBuilder::getEntries
- * @covers \MediaWiki\Minerva\MenuEntry::addComponent
- */
- public function testInsertingAJavascriptOnlyEntry() {
- $menu = new MenuBuilder();
- $menu->insert( 'nearby', $isJSOnly = true )
- ->addComponent(
- $this->nearbyComponent['text'],
- $this->nearbyComponent['href'],
- $this->nearbyComponent['class']
- );
-
- $expectedEntries = [
- [
- 'name' => 'nearby',
- 'components' => [ $this->nearbyComponent ],
- 'class' => 'jsonly'
- ],
- ];
-
- $this->assertEquals( $expectedEntries, $menu->getEntries() );
- }
-
- /**
- * @covers \MediaWiki\Minerva\MenuEntry::__construct
- * @covers \MediaWiki\Minerva\MenuEntry::getName()
- * @covers \MediaWiki\Minerva\MenuEntry::isJSOnly()
- * @covers \MediaWiki\Minerva\MenuEntry::getComponents()
- */
- public function testMenuEntryConstruction() {
- $name = 'test';
- $isJSOnly = true;
- $entry = new MenuEntry( $name, $isJSOnly );
- $this->assertSame( $name, $entry->getName() );
- $this->assertSame( $isJSOnly, $entry->isJSOnly() );
- $this->assertSame( [], $entry->getComponents() );
- }
-}
diff --git a/tests/phpunit/skins/SkinMinervaPageActionsTest.php
b/tests/phpunit/skins/SkinMinervaPageActionsTest.php
deleted file mode 100644
index c807593..0000000
--- a/tests/phpunit/skins/SkinMinervaPageActionsTest.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-
-// FIXME: That this class exists is an indicator that at least
SkinMinerva#isAllowedPageAction
-// should be extracted from SkinMinerva.
-class TestSkinMinerva extends SkinMinerva {
- public function isAllowedPageAction( $action ) {
- return parent::isAllowedPageAction( $action );
- }
-
- public function setContentHandler( ContentHandler $contentHandler ) {
- $this->contentHandler = $contentHandler;
- }
-
- public function setDoesPageHaveLanguages( $doesPageHaveLanguages ) {
- $this->doesPageHaveLanguages = $doesPageHaveLanguages;
- }
-
- public function overWriteUserPageHelper( $helper ) {
- $this->userPageHelper = $helper;
- }
-}
-
-/**
- * @group MobileFrontend
- */
-class SkinMinervaPageActionsTest extends MediaWikiTestCase {
-
- /**
- * @var TestSkinMinerva
- */
- private $skin;
-
- protected function setUp() {
- parent::setUp();
-
- $this->skin = $this->getSkin( Title::newFromText(
'SkinMinervaPageActionsTest' ) );
- }
-
- /**
- * @param Title $title
- * @return TestSkinMinerva
- */
- private function getSkin( Title $title ) {
- $requestContext = new RequestContext();
- $requestContext->setTitle( $title );
-
- $result = new TestSkinMinerva();
- $result->setContext( $requestContext );
-
- return $result;
- }
-
- /**
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function test_page_actions_arent_allowed_when_on_the_main_page()
{
- $skin = $this->getSkin( Title::newMainPage() );
-
- $this->assertFalse( $skin->isAllowedPageAction( 'watch' ) );
- }
-
- /**
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function test_invalid_page_actions_arent_allowed() {
- $this->setMwGlobals( 'wgMinervaPageActions', [] );
-
- // By default, the "talk" and "watch" page actions are allowed
but are now deemed invalid.
- $this->assertFalse( $this->skin->isAllowedPageAction( 'talk' )
);
- $this->assertFalse( $this->skin->isAllowedPageAction( 'watch' )
);
- }
-
- /**
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function test_valid_page_actions_are_allowed() {
- $this->assertTrue( $this->skin->isAllowedPageAction( 'talk' ) );
- $this->assertTrue( $this->skin->isAllowedPageAction( 'watch' )
);
- }
-
- public static function editPageActionProvider() {
- return [
- [ false, false, false ],
- [ true, false, false ],
- [ true, true, true ]
- ];
- }
-
- /**
- * The "edit" page action is allowed when the page doesn't support
direct editing via the API.
- *
- * @dataProvider editPageActionProvider
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function test_edit_page_action(
- $supportsDirectEditing,
- $supportsDirectApiEditing,
- $expected
- ) {
- $contentHandler = $this->getMockBuilder( 'ContentHandler' )
- ->disableOriginalConstructor()
- ->getMock();
-
- $contentHandler->method( 'supportsDirectEditing' )
- ->will( $this->returnValue( $supportsDirectEditing ) );
-
- $contentHandler->method( 'supportsDirectApiEditing' )
- ->will( $this->returnValue( $supportsDirectApiEditing )
);
-
- $this->skin->setContentHandler( $contentHandler );
-
- $this->assertEquals( $expected,
$this->skin->isAllowedPageAction( 'edit' ) );
- }
-
- /**
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function testPageActionsWhenOnUserPage() {
- $userPageHelper = $this->getMockBuilder(
\MediaWiki\Minerva\SkinUserPageHelper::class )
- ->disableOriginalConstructor()
- ->getMock();
-
- $userPageHelper->expects( $this->once() )
- ->method( 'isUserPage' )
- ->willReturn( true );
-
- $skin = $this->getSkin( Title::newFromText( 'User:Admin' ) );
- $skin->overWriteUserPageHelper( $userPageHelper );
-
- $this->assertFalse( $skin->isAllowedPageAction( 'talk' ) );
- }
-
- /**
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function testPageActionsWhenNotOnUserPage() {
- $userPageHelper = $this->getMockBuilder(
\MediaWiki\Minerva\SkinUserPageHelper::class )
- ->disableOriginalConstructor()
- ->getMock();
-
- $userPageHelper->expects( $this->once() )
- ->method( 'isUserPage' )
- ->willReturn( false );
-
- $skin = $this->getSkin( Title::newFromText( 'User:Admin' ) );
- $skin->overWriteUserPageHelper( $userPageHelper );
-
- $this->assertTrue( $skin->isAllowedPageAction( 'talk' ) );
- }
-
- public static function switchLanguagePageActionProvider() {
- return [
- [ true, false, true ],
- [ false, true, true ],
- [ false, false, false ],
- [ true, false, true ],
- ];
- }
-
- /**
- * The "switch-language" page action is allowed when: v2 of the page
action bar is enabled and
- * if the page has interlanguage links or if the
<code>$wgMinervaAlwaysShowLanguageButton</code>
- * configuration variable is set to truthy.
- *
- * @dataProvider switchLanguagePageActionProvider
- * @covers SkinMinerva::isAllowedPageAction
- */
- public function test_switch_language_page_action(
- $doesPageHaveLanguages,
- $minervaAlwaysShowLanguageButton,
- $expected
- ) {
- $this->skin->setDoesPageHaveLanguages( $doesPageHaveLanguages );
- $this->setMwGlobals( [
- 'wgMinervaAlwaysShowLanguageButton' =>
$minervaAlwaysShowLanguageButton,
- ] );
-
- $this->assertEquals( $expected,
$this->skin->isAllowedPageAction( 'switch-language' ) );
- }
-}
diff --git a/tests/phpunit/skins/SkinMinervaTest.php
b/tests/phpunit/skins/SkinMinervaTest.php
deleted file mode 100644
index 7970ed6..0000000
--- a/tests/phpunit/skins/SkinMinervaTest.php
+++ /dev/null
@@ -1,406 +0,0 @@
-<?php
-
-namespace Tests\MobileFrontend\Skins;
-
-use MediaWikiTestCase;
-use MobileUI;
-use MWTimestamp;
-use OutputPage;
-use QuickTemplate;
-use RequestContext;
-use SkinMinerva;
-use SpecialPage;
-use Title;
-use User;
-use Wikimedia\TestingAccessWrapper;
-
-class Template extends QuickTemplate {
- public function execute() {
- }
-}
-
-class EchoNotifUser {
- public function __construct( $echoLastUnreadNotificationTime,
$echoNotificationCount ) {
- $this->echoLastUnreadNotificationTime =
$echoLastUnreadNotificationTime;
- $this->echoNotificationCount = $echoNotificationCount;
- }
- public function getLastUnreadNotificationTime() {
- return $this->echoLastUnreadNotificationTime;
- }
- public function getNotificationCount() {
- return $this->echoNotificationCount;
- }
-}
-
-/**
- * @coversDefaultClass SkinMinerva
- * @group MobileFrontend
- */
-class SkinMinervaTest extends MediaWikiTestCase {
-
- /**
- * @covers ::addToBodyAttributes
- */
- public function testAddToBodyAttributes() {
- // The `class` attribute gets set to the "bodyClassName"
property by
- // default.
- $this->assertContains(
- 'no-js',
- $this->addToBodyAttributes( 'no-js', false )
- );
-
- $classes = $this->addToBodyAttributes( 'no-js', true );
-
- $this->assertContains( 'no-js', $classes );
- }
-
- private function addToBodyAttributes(
- $bodyClassName
- ) {
- $context = new RequestContext();
- $context->setTitle( Title::newFromText( 'Test' ) );
-
- $outputPage = $context->getOutput();
- $outputPage->setProperty( 'bodyClassName', $bodyClassName );
-
- $bodyAttrs = [ 'class' => '' ];
-
- $skin = new SkinMinerva();
- $skin->setContext( $context );
- $skin->addToBodyAttributes( $outputPage, $bodyAttrs );
-
- return explode( ' ', $bodyAttrs[ 'class' ] );
- }
-
- /**
- * @covers ::setContext
- * @covers ::setSkinOptions
- * @covers ::hasCategoryLinks
- */
- public function testHasCategoryLinksWhenOptionIsOff() {
- $outputPage = $this->getMockBuilder( OutputPage::class )
- ->disableOriginalConstructor()
- ->getMock();
- $outputPage->expects( $this->never() )
- ->method( 'getCategoryLinks' );
-
- $context = new RequestContext();
- $context->setTitle( Title::newFromText( 'Test' ) );
- $context->setOutput( $outputPage );
-
- $skin = new SkinMinerva();
- $skin->setContext( $context );
- $skin->setSkinOptions( [ SkinMinerva::OPTION_CATEGORIES =>
false ] );
-
- $skin = TestingAccessWrapper::newFromObject( $skin );
-
- $this->assertEquals( $skin->hasCategoryLinks(), false );
- }
-
- /**
- * @dataProvider provideHasCategoryLinks
- * @param array $categoryLinks
- * @param bool $expected
- * @covers ::setContext
- * @covers ::setSkinOptions
- * @covers::hasCategoryLinks
- */
- public function testHasCategoryLinks( array $categoryLinks, $expected )
{
- $outputPage = $this->getMockBuilder( OutputPage::class )
- ->disableOriginalConstructor()
- ->getMock();
- $outputPage->expects( $this->once() )
- ->method( 'getCategoryLinks' )
- ->will( $this->returnValue( $categoryLinks ) );
-
- $context = new RequestContext();
- $context->setTitle( Title::newFromText( 'Test' ) );
- $context->setOutput( $outputPage );
-
- $skin = new SkinMinerva();
- $skin->setContext( $context );
- $skin->setSkinOptions( [ SkinMinerva::OPTION_CATEGORIES => true
] );
-
- $skin = TestingAccessWrapper::newFromObject( $skin );
-
- $this->assertEquals( $skin->hasCategoryLinks(), $expected );
- }
-
- public function provideHasCategoryLinks() {
- 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
- ],
- ];
- }
-
- /**
- * Test whether the font changer module is correctly added to the list
context modules
- *
- * @covers ::getContextSpecificModules
- * @dataProvider provideGetContextSpecificModules
- * @param string $fontchangerValue whether font changer feature is
enabled
- * @param mixed $backToTopValue whether back to top feature is enabled
- * @param string $moduleName Module name that is being tested
- * @param bool $expected Whether the module is expected to be returned
by the function being tested
- */
- public function testGetContextSpecificModules( $fontchangerValue,
$backToTopValue,
- $moduleName, $expected
- ) {
- $skin = TestingAccessWrapper::newFromObject(
- $this->getMockBuilder( SkinMinerva::class )
- ->disableOriginalConstructor()
- ->setMethods( [ 'getTitle' ] )
- ->getMock()
- );
- $title = Title::newFromText( 'Test' );
- $skin->expects( $this->any() )
- ->method( 'getTitle' )
- ->will( $this->returnValue( $title ) );
-
- $skin->setSkinOptions( [
- 'fontChanger' => $fontchangerValue,
- 'backToTop' => $backToTopValue,
- ] );
-
- if ( $expected ) {
- $this->assertContains( $moduleName,
$skin->getContextSpecificModules() );
- } else {
- $this->assertNotContains( $moduleName,
$skin->getContextSpecificModules() );
- }
- }
-
- public function provideGetContextSpecificModules() {
- return [
- [ true, false, 'skins.minerva.fontchanger', true ],
- [ false, true, 'skins.minerva.fontchanger', false ],
- [ false, true, 'skins.minerva.backtotop', true ],
- [ false, false, 'skins.minerva.backtotop', false ],
- ];
- }
-
- /**
- * Test the notification user button
- *
- * @covers ::prepareUserButton
- * @dataProvider providePrepareUserButton
- * @param array|string $expectedSecondaryButtonData Expected test case
outcome
- * @param string $message Test message
- * @param Title $title
- * @param bool $useEcho Whether to use Extension:Echo
- * @param bool $isUserLoggedIn
- * @param string $newtalks New talk page messages for the current user
- * @param MWTimestamp|bool $echoLastUnreadNotificationTime Timestamp or
false
- * @param int|bool $echoNotificationCount
- * @param string|bool $echoSeenTime String in format TS_ISO_8601 or
false
- * @param string|bool $formattedEchoNotificationCount
- */
- public function testPrepareUserButton(
- $expectedSecondaryButtonData, $message, $title, $useEcho,
$isUserLoggedIn,
- $newtalks, $echoLastUnreadNotificationTime = false,
- $echoNotificationCount = false, $echoSeenTime = false,
- $formattedEchoNotificationCount = false
- ) {
- $user = $this->getMockBuilder( User::class )
- ->disableOriginalConstructor()
- ->setMethods( [ 'isLoggedIn' ] )
- ->getMock();
- $user->expects( $this->any() )
- ->method( 'isLoggedIn' )
- ->will( $this->returnValue( $isUserLoggedIn ) );
-
- $skin = TestingAccessWrapper::newFromObject(
- $this->getMockBuilder( SkinMinerva::class )
- ->disableOriginalConstructor()
- ->setMethods( [ 'getTitle', 'getUser',
'getNewtalks', 'useEcho',
-
'getEchoNotifUser', 'getEchoSeenTime',
-
'getFormattedEchoNotificationCount' ] )
- ->getMock()
- );
- $skin->expects( $this->any() )
- ->method( 'getTitle' )
- ->will( $this->returnValue( $title ) );
- $skin->expects( $this->any() )
- ->method( 'getUser' )
- ->will( $this->returnValue( $user ) );
- $skin->expects( $this->any() )
- ->method( 'getNewtalks' )
- ->will( $this->returnValue( $newtalks ) );
- $skin->expects( $this->any() )
- ->method( 'useEcho' )
- ->will( $this->returnValue( $useEcho ) );
- $skin->expects( $this->any() )
- ->method( 'getEchoNotifUser' )
- ->will( $this->returnValue(
- new EchoNotifUser(
- $echoLastUnreadNotificationTime,
$echoNotificationCount
- )
- ) );
- $skin->expects( $this->any() )
- ->method( 'getEchoSeenTime' )
- ->will( $this->returnValue( $echoSeenTime ) );
- $skin->expects( $this->any() )
- ->method( 'getFormattedEchoNotificationCount' )
- ->will( $this->returnValue(
$formattedEchoNotificationCount ) );
-
- $tpl = new Template();
- $skin->prepareUserButton( $tpl );
- $this->assertEquals(
- $expectedSecondaryButtonData,
- $tpl->get( 'secondaryButtonData' ),
- $message
- );
- }
-
- /**
- * Utility function that returns the expected secondary button data
given parameters
- * @param Title $title Page title
- * @param string $notificationsMsg
- * @param string $notificationsTitle
- * @param string $countLabel
- * @param bool $isZero
- * @param bool $hasUnseen
- * @return array
- */
- private function getSecondaryButtonExpectedResult(
- $title,
- $notificationsMsg,
- $notificationsTitle,
- $countLabel,
- $isZero,
- $hasUnseen
- ) {
- return [
- 'notificationIconClass' => MobileUI::iconClass(
'notifications' ),
- 'title' => $notificationsMsg,
- 'url' => SpecialPage::getTitleFor( $notificationsTitle )
- ->getLocalURL(
- [ 'returnto' =>
$title->getPrefixedText() ] ),
- 'notificationCount' => $countLabel,
- 'isNotificationCountZero' => $isZero,
- 'hasNotifications' => $hasUnseen,
- 'hasUnseenNotifications' => $hasUnseen
- ];
- }
-
- /**
- * Data provider for the test case testPrepareUserButton with Echo
enabled
- * @param Title @title Page title
- * @return array
- */
- private function providePrepareUserButtonEcho( Title $title ) {
- return [
- [ '', 'Echo, not logged in, no talk page alerts',
- $title, true, false, '' ],
- [ '', 'Echo, logged in, no talk page alerts',
- Title::newFromText( 'Special:Notifications' ),
true, true, '' ],
- [ '', 'Echo, logged in, talk page alert',
- Title::newFromText( 'Special:Notifications' ),
true, true,
- 'newtalks alert' ],
- [ $this->getSecondaryButtonExpectedResult(
- $title,
- 'Show my notifications',
- 'Notifications',
- '99+',
- false,
- true
- ), 'Echo, logged in, no talk page alerts, 110
notifications, ' +
- 'last un-read nofication time after last echo
seen time',
- $title, true, true, '',
- MWTimestamp::getInstance( strtotime(
'2017-05-11T21:23:20Z' ) ),
- 110, '2017-05-11T20:23:20Z', '99+' ],
- [ $this->getSecondaryButtonExpectedResult(
- $title,
- 'Show my notifications',
- 'Notifications',
- '3',
- false,
- false
- ), 'Echo, logged in, no talk page alerts, 3
notifications, ' +
- 'last un-read nofication time before last echo seen
time',
- $title, true, true, '',
- MWTimestamp::getInstance( strtotime(
'2017-05-11T21:23:20Z' ) ),
- 3, '2017-05-11T22:23:20Z', '3' ],
- [ $this->getSecondaryButtonExpectedResult(
- $title,
- 'Show my notifications',
- 'Notifications',
- '5',
- false,
- false
- ), 'Echo, logged in, no talk page alerts, 5
notifications, ' +
- 'no last un-read nofication time',
- $title, true, true, '', false, 5,
'2017-05-11T22:23:20Z', '5' ],
- [ $this->getSecondaryButtonExpectedResult(
- $title,
- 'Show my notifications',
- 'Notifications',
- '0',
- true,
- false
- ), 'Echo, logged in, no talk page alerts, 0
notifications, ' +
- 'no last echo seen time',
- $title, true, true, '',
- MWTimestamp::getInstance( strtotime(
'2017-05-11T21:23:20Z' ) ),
- 0, false, '0' ]
- ];
- }
-
- /**
- * Data provider for the test case testPrepareUserButton with Echo
disabled
- * @param Title @title Page title
- * @return array
- */
- private function providePrepareUserButtonNoEcho( Title $title ) {
- return [
- [ '', 'No Echo, not logged in, no talk page alerts',
- $title, false, false, '' ],
- [ '', 'No Echo, logged in, no talk page alerts',
- $title, false, true, '' ],
- [ $this->getSecondaryButtonExpectedResult(
- $title,
- 'You have new messages on your talk page',
- 'Mytalk',
- '',
- true,
- false
- ), 'No Echo, not logged in, talk page alert',
- $title, false, false, 'newtalks alert' ],
- ];
- }
-
- /**
- * Data provider for the test case testPrepareUserButton
- * @return array
- */
- public function providePrepareUserButton() {
- $title = Title::newFromText( 'Test' );
- return array_merge(
- $this->providePrepareUserButtonEcho( $title ),
- $this->providePrepareUserButtonNoEcho( $title )
- );
- }
-}
diff --git a/tests/phpunit/skins/SkinUserPageHelperTest.php
b/tests/phpunit/skins/SkinUserPageHelperTest.php
deleted file mode 100644
index 8edd6a6..0000000
--- a/tests/phpunit/skins/SkinUserPageHelperTest.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-use MediaWiki\Minerva\SkinUserPageHelper;
-
-/**
- * @group MobileFrontend
- * @coversDefaultClass MediaWiki\Minerva\SkinUserPageHelper
- */
-class SkinUserPageHelperTest extends MediaWikiTestCase {
-
- private function getContextMock( Title $title ) {
- $context = $this->getMock( IContextSource::class );
-
- $context->expects( $this->once() )
- ->method( 'getTitle' )
- ->willReturn( $title );
-
- return $context;
- }
-
- /**
- * @covers ::isUserPage
- * @covers ::fetchData
- * @covers ::__construct
- */
- public function testTitleNotInUserNamespace() {
- $title = Title::newFromText( 'Test Page', NS_MAIN );
-
- $helper = new SkinUserPageHelper( $this->getContextMock( $title
) );
- $this->assertEquals( false, $helper->isUserPage() );
- }
-
- /**
- * @covers ::isUserPage
- * @covers ::fetchData
- */
- public function testTitleisASubpage() {
- $title = Title::newFromText( 'User:TestUser/subpage', NS_USER );
-
- $helper = new SkinUserPageHelper( $this->getContextMock( $title
) );
- $this->assertEquals( false, $helper->isUserPage() );
- }
-
- /**
- * @covers ::fetchData
- */
- public function testTitleProcessingIsCached() {
- $titleMock = $this->getMockBuilder( Title::class )
- ->getMock();
- $titleMock->expects( $this->once() )
- ->method( 'inNamespace' )
- ->with( NS_USER )
- ->willReturn( true );
-
- $titleMock->expects( $this->once() )
- ->method( 'isSubpage' )
- ->willReturn( false );
-
- $titleMock->expects( $this->once() )
- ->method( 'getText' )
- ->willReturn( 'Test' );
-
- $helper = new SkinUserPageHelper( $this->getContextMock(
$titleMock ) );
- $helper->isUserPage();
- $helper->isUserPage();
- $helper->getPageUser();
- $helper->getPageUser();
- }
-
- /**
- * @covers ::fetchData
- * @covers ::getPageUser
- * @covers ::isUserPage
- */
- public function testGetPageUserWhenOnUserPage() {
- $testUser = $this->getTestUser()->getUser();
- $title = $testUser->getUserPage();
-
- $helper = new SkinUserPageHelper( $this->getContextMock( $title
) );
- $this->assertEquals( true, $helper->isUserPage() );
- $this->assertEquals( $testUser->getId(),
$helper->getPageUser()->getId() );
- }
-
- /**
- * @covers ::fetchData
- * @covers ::getPageUser
- * @covers ::isUserPage
- */
- public function testGetPageUserWhenOnUserPageReturnsCorrectUser() {
- $testUser = $this->getTestUser()->getUser();
- $testUserTitle = $testUser->getUserPage();
-
- $secondTestUser = $this->getTestSysop()->getUser();
- $secondTestUserTitle = $secondTestUser->getUserPage();
-
- $helper = new SkinUserPageHelper( $this->getContextMock(
$secondTestUserTitle ) );
- $this->assertEquals( true, $helper->isUserPage() );
- $this->assertNotEquals( $testUser->getId(),
$helper->getPageUser()->getId() );
- $this->assertNotEquals( $helper->getPageUser()->getUserPage(),
$testUserTitle );
- }
-
-}
--
To view, visit https://gerrit.wikimedia.org/r/365680
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I67760c9c475a31c7003e59ed5515ed93bfd77d18
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: wmf/1.30.0-wmf.9
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Thcipriani <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits