mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
754338fe48
This trait was using private fields from its host classes ($this->event, $this->language). It created a weird coupling situation where the host class uses the trait and the trait uses the host class. Effectively a circular dependency. Also, phan is complaining about it in I65ae6adc10941c05a2646e551b1baa829e4e8654 Change-Id: Ib2796b7ca62ecd7ece19583d7ca83e4252a5d878
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 ) );
|
|
}
|
|
}
|