Merge "mediawiki.api: Remove console warning for legacy token type"
[mediawiki.git] / tests / phpunit / includes / language / Message / MessageFormatterFactoryTest.php
blob77d58a6c409b6fb30b54117f981a93f6dee93697
1 <?php
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
19 * @file
20 * @since 1.42
23 namespace MediaWiki\Tests\Message;
25 use MediaWiki\Message\Message;
26 use MediaWiki\Message\MessageFormatterFactory;
27 use MediaWiki\Message\TextFormatter;
28 use MediaWikiIntegrationTestCase;
30 /**
31 * @covers \MediaWiki\Message\MessageFormatterFactory
33 class MessageFormatterFactoryTest extends MediaWikiIntegrationTestCase {
35 public function testGetTextFormatter() {
36 $factoryMock = new MessageFormatterFactory( Message::FORMAT_TEXT );
37 $langCodeMock = 'en';
38 $formatterMock = $factoryMock->getTextFormatter( $langCodeMock );
39 $this->assertInstanceOf( TextFormatter::class, $formatterMock );
40 $this->assertSame( $langCodeMock, $formatterMock->getLangCode() );
43 public function testGetTextFormatterReturnsSameInstanceForSameLangCode() {
44 $factoryMock = new MessageFormatterFactory();
45 $langCodeMock = 'en';
46 $formatterMock1 = $factoryMock->getTextFormatter( $langCodeMock );
47 $formatterMock2 = $factoryMock->getTextFormatter( $langCodeMock );
48 $this->assertSame( $formatterMock1, $formatterMock2 );
51 public function testGetTextFormatterReturnsDifferentInstancesForDifferentLangCodes() {
52 $factoryMock = new MessageFormatterFactory( Message::FORMAT_PLAIN );
53 $langCodeMock1 = 'en';
54 $langCodeMock2 = 'fr';
55 $formatterMock1 = $factoryMock->getTextFormatter( $langCodeMock1 );
56 $formatterMock2 = $factoryMock->getTextFormatter( $langCodeMock2 );
57 $this->assertNotSame( $formatterMock1, $formatterMock2 );
60 public function testGetTextFormatterWithDifferentFormats() {
61 $factoryMock1 = new MessageFormatterFactory( Message::FORMAT_TEXT );
62 $factoryMock2 = new MessageFormatterFactory( Message::FORMAT_PLAIN );
63 $langCodeMock = 'en';
64 $formatterMock1 = $factoryMock1->getTextFormatter( $langCodeMock );
65 $formatterMock2 = $factoryMock2->getTextFormatter( $langCodeMock );
66 $this->assertNotSame( $formatterMock1, $formatterMock2 );