2019-04-05 20:50:03 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Event;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2019-04-05 20:50:03 +00:00
|
|
|
/**
|
2022-11-01 22:01:23 +00:00
|
|
|
* @covers \MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection
|
2019-04-05 20:50:03 +00:00
|
|
|
* @group Database
|
|
|
|
*/
|
2021-10-11 22:42:10 +00:00
|
|
|
class EchoPresentationModelSectionTest extends MediaWikiIntegrationTestCase {
|
2019-04-05 20:50:03 +00:00
|
|
|
|
|
|
|
public function testGetTruncatedSectionTitle_short() {
|
2022-12-28 19:19:01 +00:00
|
|
|
$lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' );
|
2019-04-05 20:50:03 +00:00
|
|
|
$section = new EchoPresentationModelSection(
|
|
|
|
$this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
|
|
|
|
$this->getTestUser()->getUser(),
|
|
|
|
$lang
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $lang->embedBidi( 'asdf' ), $section->getTruncatedSectionTitle() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTruncatedSectionTitle_long() {
|
2022-12-28 19:19:01 +00:00
|
|
|
$lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' );
|
2019-04-05 20:50:03 +00:00
|
|
|
$section = new EchoPresentationModelSection(
|
|
|
|
$this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => str_repeat( 'a', 100 ) ] ) ] ),
|
|
|
|
$this->getTestUser()->getUser(),
|
|
|
|
$lang
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$lang->embedBidi( str_repeat( 'a', 50 ) . '...' ),
|
|
|
|
$section->getTruncatedSectionTitle()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTitleWithSection() {
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
$section = new EchoPresentationModelSection(
|
|
|
|
$this->makeEvent( [
|
|
|
|
'event_page_id' => $page->getId(),
|
|
|
|
'event_extra' => serialize( [ 'section-title' => 'asdf' ] ),
|
|
|
|
] ),
|
|
|
|
$this->getTestUser()->getUser(),
|
2022-12-28 19:19:01 +00:00
|
|
|
$this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
|
2019-04-05 20:50:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$titleWithSection = $section->getTitleWithSection();
|
|
|
|
|
|
|
|
$this->assertEquals( 'asdf', $titleWithSection->getFragment() );
|
|
|
|
$this->assertEquals( $page->getTitle()->getPrefixedText(), $titleWithSection->getPrefixedText() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExists_no() {
|
|
|
|
$section = new EchoPresentationModelSection(
|
|
|
|
$this->makeEvent(),
|
|
|
|
$this->getTestUser()->getUser(),
|
2022-12-28 19:19:01 +00:00
|
|
|
$this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
|
2019-04-05 20:50:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertFalse( $section->exists() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExists_yes() {
|
|
|
|
$section = new EchoPresentationModelSection(
|
|
|
|
$this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
|
|
|
|
$this->getTestUser()->getUser(),
|
2022-12-28 19:19:01 +00:00
|
|
|
$this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
|
2019-04-05 20:50:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue( $section->exists() );
|
|
|
|
}
|
|
|
|
|
|
|
|
private function makeEvent( $config = [] ) {
|
|
|
|
$agent = $this->getTestSysop()->getUser();
|
2022-11-02 21:34:17 +00:00
|
|
|
return Event::newFromRow( (object)array_merge( [
|
2019-04-05 20:50:03 +00:00
|
|
|
'event_id' => 12,
|
|
|
|
'event_type' => 'welcome',
|
|
|
|
'event_variant' => '1',
|
|
|
|
'event_page_id' => 1,
|
|
|
|
'event_deleted' => 0,
|
|
|
|
'event_agent_id' => $agent->getId(),
|
|
|
|
'event_extra' => '',
|
|
|
|
], $config ) );
|
|
|
|
}
|
|
|
|
}
|