2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
|
2017-07-14 23:56:16 +00:00
|
|
|
namespace Tests\MediaWiki\Minerva;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2017-07-12 15:12:40 +00:00
|
|
|
use MediaWikiTestCase;
|
|
|
|
use OutputPage;
|
|
|
|
use RequestContext;
|
|
|
|
use SkinMinerva;
|
|
|
|
use Title;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
2018-04-15 23:12:19 +00:00
|
|
|
// phpcs:ignore MediaWiki.Files.ClassMatchesFilename.NotMatch
|
2017-07-12 15:12:40 +00:00
|
|
|
class EchoNotifUser {
|
Fix seen notifications appearing as unseen on mobile
Important note: Make sure to distinguish unseen from unread
One way to reproduce minerva and non-minerva notification inconsistencies:
- Have all your alerts and notices seen. This is displayed with grayed out
number on vector skin or no number at all, if you have (marked as) read.
- Generate new alert or notice (one is enough) in your preferred way.
- You can check minerva and non-minerva at this step. Both should be in sync.
But don't perform any additional action.
- Open the notification popup in some non-minerva skin (I have tried with
vector and monobook), marking it as seen.
- Check the notification icon in minerva. At this point, you should see
notification displayed as unseen.
The reason bug appeared in the first place is that alert/notice timestamps
were mixed up when seen time is obtained. We get seen time from
EchoSeenTime class, where we get smaller of the two timestamps,
using PHP method `min()`. See I27109ee6a248. Then, we get last unread
notification timestamp (which can be either alert or notice), and compare
that to seen time. That leads to the situation when you have only one of
alerts or notices with unread items, smaller timestamp is used for seen,
and most recent for unread, at which point we compare timestamps for
two separate things.
Previous behavior of getting seen timestamps (using max instead of min) would
probably solve the problem, but some other inconsistencies might arrise.
This should prevent any weird and unpredictable behavior to happen.
Bug: T183076
Change-Id: I20bbd6c590086b1c3eccf82983aad59eb3144a7a
2018-01-10 16:26:29 +00:00
|
|
|
public function __construct(
|
|
|
|
$lastUnreadAlertTime, $lastUnreadMessageTime, $echoNotificationCount
|
|
|
|
) {
|
|
|
|
$this->lastUnreadAlertTime = $lastUnreadAlertTime;
|
|
|
|
$this->lastUnreadMessageTime = $lastUnreadMessageTime;
|
2017-07-12 15:12:40 +00:00
|
|
|
$this->echoNotificationCount = $echoNotificationCount;
|
|
|
|
}
|
Fix seen notifications appearing as unseen on mobile
Important note: Make sure to distinguish unseen from unread
One way to reproduce minerva and non-minerva notification inconsistencies:
- Have all your alerts and notices seen. This is displayed with grayed out
number on vector skin or no number at all, if you have (marked as) read.
- Generate new alert or notice (one is enough) in your preferred way.
- You can check minerva and non-minerva at this step. Both should be in sync.
But don't perform any additional action.
- Open the notification popup in some non-minerva skin (I have tried with
vector and monobook), marking it as seen.
- Check the notification icon in minerva. At this point, you should see
notification displayed as unseen.
The reason bug appeared in the first place is that alert/notice timestamps
were mixed up when seen time is obtained. We get seen time from
EchoSeenTime class, where we get smaller of the two timestamps,
using PHP method `min()`. See I27109ee6a248. Then, we get last unread
notification timestamp (which can be either alert or notice), and compare
that to seen time. That leads to the situation when you have only one of
alerts or notices with unread items, smaller timestamp is used for seen,
and most recent for unread, at which point we compare timestamps for
two separate things.
Previous behavior of getting seen timestamps (using max instead of min) would
probably solve the problem, but some other inconsistencies might arrise.
This should prevent any weird and unpredictable behavior to happen.
Bug: T183076
Change-Id: I20bbd6c590086b1c3eccf82983aad59eb3144a7a
2018-01-10 16:26:29 +00:00
|
|
|
public function getLastUnreadAlertTime() {
|
|
|
|
return $this->lastUnreadAlertTime;
|
|
|
|
}
|
|
|
|
public function getLastUnreadMessageTime() {
|
|
|
|
return $this->lastUnreadMessageTime;
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
public function getNotificationCount() {
|
|
|
|
return $this->echoNotificationCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-17 20:34:47 +00:00
|
|
|
* @coversDefaultClass SkinMinerva
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
class SkinMinervaTest extends MediaWikiTestCase {
|
2018-09-26 23:03:20 +00:00
|
|
|
const OPTIONS_MODULE = 'skins.minerva.options';
|
2017-07-12 15:12:40 +00:00
|
|
|
|
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();
|
|
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
|
|
|
$this->assertEquals( $skin->hasCategoryLinks(), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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' )
|
|
|
|
->will( $this->returnValue( $categoryLinks ) );
|
|
|
|
|
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();
|
|
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
|
|
|
|
$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 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
|
|
|
|
*/
|
2019-04-10 21:43:50 +00:00
|
|
|
public function testGetContextSpecificModules( $backToTopValue, $moduleName, $expected ) {
|
|
|
|
$this->overrideSkinOptions( [
|
2019-07-30 00:24:23 +00:00
|
|
|
SkinOptions::TALK_AT_TOP => false,
|
|
|
|
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
|
|
|
|
SkinOptions::TOOLBAR_SUBMENU => false,
|
2019-08-22 20:31:31 +00:00
|
|
|
SkinOptions::MAIN_MENU_EXPANDED => false,
|
|
|
|
SkinOptions::PERSONAL_MENU => false,
|
2019-04-10 21:43:50 +00:00
|
|
|
'backToTop' => $backToTopValue,
|
2019-03-29 21:31:09 +00:00
|
|
|
] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
2017-07-12 15:12:40 +00:00
|
|
|
$title = Title::newFromText( 'Test' );
|
2017-07-17 19:34:45 +00:00
|
|
|
$testContext = RequestContext::getMain();
|
|
|
|
$testContext->setTitle( $title );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2017-07-17 19:49:49 +00:00
|
|
|
$skin->setContext( $testContext );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
if ( $expected ) {
|
|
|
|
$this->assertContains( $moduleName, $skin->getContextSpecificModules() );
|
|
|
|
} else {
|
|
|
|
$this->assertNotContains( $moduleName, $skin->getContextSpecificModules() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetContextSpecificModules() {
|
|
|
|
return [
|
2018-09-26 23:03:20 +00:00
|
|
|
[ true, self::OPTIONS_MODULE, true ],
|
|
|
|
[ false, self::OPTIONS_MODULE, false ],
|
2017-07-12 15:12:40 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|