Debian Codegraph @

extensions/Echo/tests/phpunit/Formatters/EchoPresentationModelSectionTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Test\Formatters;
4
5 use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
6 use MediaWiki\Extension\Notifications\Model\Event;
7 use MediaWikiIntegrationTestCase;
8
9 /**
10 * @covers \MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection
11 * @group Database
12 */
13 class EchoPresentationModelSectionTest extends MediaWikiIntegrationTestCase {
14
15 public function testGetTruncatedSectionTitle_short() {
16 $lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' );
17 $section = new EchoPresentationModelSection(
18 $this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
19 $this->getTestUser()->getUser(),
20 $lang
21 );
22
23 $this->assertEquals( $lang->embedBidi( 'asdf' ), $section->getTruncatedSectionTitle() );
24 }
25
26 public function testGetTruncatedSectionTitle_long() {
27 $lang = $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' );
28 $section = new EchoPresentationModelSection(
29 $this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => str_repeat( 'a', 100 ) ] ) ] ),
30 $this->getTestUser()->getUser(),
31 $lang
32 );
33
34 $this->assertEquals(
35 $lang->embedBidi( str_repeat( 'a', 50 ) . '...' ),
36 $section->getTruncatedSectionTitle()
37 );
38 }
39
40 public function testGetTitleWithSection() {
41 $page = $this->getExistingTestPage();
42 $section = new EchoPresentationModelSection(
43 $this->makeEvent( [
44 'event_page_id' => $page->getId(),
45 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ),
46 ] ),
47 $this->getTestUser()->getUser(),
48 $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
49 );
50
51 $titleWithSection = $section->getTitleWithSection();
52
53 $this->assertEquals( 'asdf', $titleWithSection->getFragment() );
54 $this->assertEquals( $page->getTitle()->getPrefixedText(), $titleWithSection->getPrefixedText() );
55 }
56
57 public function testExists_no() {
58 $section = new EchoPresentationModelSection(
59 $this->makeEvent(),
60 $this->getTestUser()->getUser(),
61 $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
62 );
63
64 $this->assertFalse( $section->exists() );
65 }
66
67 public function testExists_yes() {
68 $section = new EchoPresentationModelSection(
69 $this->makeEvent( [ 'event_extra' => serialize( [ 'section-title' => 'asdf' ] ) ] ),
70 $this->getTestUser()->getUser(),
71 $this->getServiceContainer()->getLanguageFactory()->getLanguage( 'en' )
72 );
73
74 $this->assertTrue( $section->exists() );
75 }
76
77 private function makeEvent( $config = [] ) {
78 $agent = $this->getTestSysop()->getUser();
79 return Event::newFromRow( (object)array_merge( [
80 'event_id' => 12,
81 'event_type' => 'welcome',
82 'event_variant' => '1',
83 'event_page_id' => 1,
84 'event_deleted' => 0,
85 'event_agent_id' => $agent->getId(),
86 'event_extra' => '',
87 ], $config ) );
88 }
89 }