mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
967a0b54e9
Not all tools require these to be absolute, full qualified class names. But some do. This does make the code more compatible with all kinds of tools. Change-Id: Ie7f9d9469b7a48b2fe908d3428fca9ec0120f855
98 lines
2.6 KiB
PHP
98 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Database
|
|
*/
|
|
class EchoPresentationModelSectionTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @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 ) );
|
|
}
|
|
}
|