mediawiki-extensions-Echo/tests/phpunit/formatters/PresentationModelSectionTest.php
Alexander Vorwerk 449f82faa3 MediaWikiTestCase -> MediaWikiIntegrationTestCase
MediaWikiTestCase has been renamed to MediaWikiIntegrationTestCase in 1.34.

Bug: T293043
Change-Id: I68efac2c458748fa3ab16c4c652bd2c4af9cbb75
2021-10-12 00:42:10 +02:00

98 lines
2.6 KiB
PHP

<?php
/**
* @group Database
*/
class EchoPresentationModelSectionTest extends MediaWikiIntegrationTestCase {
/**
* @covers \EchoPresentationModelSection::getTruncatedSectionTitle
*/
public function testGetTruncatedSectionTitle_short() {
$lang = Language::factory( 'en' );
$section = new EchoPresentationModelSection(
$this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
$this->getTestUser()->getUser(),
$lang
);
$this->assertEquals( $lang->embedBidi( 'asdf' ), $section->getTruncatedSectionTitle() );
}
/**
* @covers \EchoPresentationModelSection::getTruncatedSectionTitle
*/
public function testGetTruncatedSectionTitle_long() {
$lang = Language::factory( 'en' );
$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()
);
}
/**
* @covers \EchoPresentationModelSection::getTitleWithSection
*/
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(),
Language::factory( 'en' )
);
$titleWithSection = $section->getTitleWithSection();
$this->assertEquals( 'asdf', $titleWithSection->getFragment() );
$this->assertEquals( $page->getTitle()->getPrefixedText(), $titleWithSection->getPrefixedText() );
}
/**
* @covers \EchoPresentationModelSection::exists
*/
public function testExists_no() {
$section = new EchoPresentationModelSection(
$this->makeEvent(),
$this->getTestUser()->getUser(),
Language::factory( 'en' )
);
$this->assertFalse( $section->exists() );
}
/**
* @covers \EchoPresentationModelSection::exists
*/
public function testExists_yes() {
$section = new EchoPresentationModelSection(
$this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
$this->getTestUser()->getUser(),
Language::factory( 'en' )
);
$this->assertTrue( $section->exists() );
}
private function makeEvent( $config = [] ) {
$agent = $this->getTestSysop()->getUser();
return EchoEvent::newFromRow( (object)array_merge( [
'event_id' => 12,
'event_type' => 'welcome',
'event_variant' => '1',
'event_page_id' => 1,
'event_deleted' => 0,
'event_agent_id' => $agent->getId(),
'event_extra' => '',
], $config ) );
}
}