6 class ApiMessageTest
extends MediaWikiTestCase
{
8 private function compareMessages( $msg, $msg2 ) {
9 $this->assertSame( $msg->getKey(), $msg2->getKey(), 'getKey' );
10 $this->assertSame( $msg->getKeysToTry(), $msg2->getKeysToTry(), 'getKeysToTry' );
11 $this->assertSame( $msg->getParams(), $msg2->getParams(), 'getParams' );
12 $this->assertSame( $msg->getFormat(), $msg2->getFormat(), 'getFormat' );
13 $this->assertSame( $msg->getLanguage(), $msg2->getLanguage(), 'getLanguage' );
15 $msg = TestingAccessWrapper
::newFromObject( $msg );
16 $msg2 = TestingAccessWrapper
::newFromObject( $msg2 );
17 $this->assertSame( $msg->interface, $msg2->interface, 'interface' );
18 $this->assertSame( $msg->useDatabase
, $msg2->useDatabase
, 'useDatabase' );
20 $msg->title ?
$msg->title
->getFullText() : null,
21 $msg2->title ?
$msg2->title
->getFullText() : null,
29 public function testApiMessage() {
30 $msg = new Message( array( 'foo', 'bar' ), array( 'baz' ) );
31 $msg->inLanguage( 'de' )->title( Title
::newMainPage() );
32 $msg2 = new ApiMessage( $msg, 'code', array( 'data' ) );
33 $this->compareMessages( $msg, $msg2 );
34 $this->assertEquals( 'code', $msg2->getApiCode() );
35 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
37 $msg2 = unserialize( serialize( $msg2 ) );
38 $this->compareMessages( $msg, $msg2 );
39 $this->assertEquals( 'code', $msg2->getApiCode() );
40 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
42 $msg = new Message( array( 'foo', 'bar' ), array( 'baz' ) );
43 $msg2 = new ApiMessage( array( array( 'foo', 'bar' ), 'baz' ), 'code', array( 'data' ) );
44 $this->compareMessages( $msg, $msg2 );
45 $this->assertEquals( 'code', $msg2->getApiCode() );
46 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
48 $msg = new Message( 'foo' );
49 $msg2 = new ApiMessage( 'foo' );
50 $this->compareMessages( $msg, $msg2 );
51 $this->assertEquals( 'foo', $msg2->getApiCode() );
52 $this->assertEquals( array(), $msg2->getApiData() );
54 $msg2->setApiCode( 'code', array( 'data' ) );
55 $this->assertEquals( 'code', $msg2->getApiCode() );
56 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
57 $msg2->setApiCode( null );
58 $this->assertEquals( 'foo', $msg2->getApiCode() );
59 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
60 $msg2->setApiData( array( 'data2' ) );
61 $this->assertEquals( array( 'data2' ), $msg2->getApiData() );
65 * @covers ApiRawMessage
67 public function testApiRawMessage() {
68 $msg = new RawMessage( 'foo', array( 'baz' ) );
69 $msg->inLanguage( 'de' )->title( Title
::newMainPage() );
70 $msg2 = new ApiRawMessage( $msg, 'code', array( 'data' ) );
71 $this->compareMessages( $msg, $msg2 );
72 $this->assertEquals( 'code', $msg2->getApiCode() );
73 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
75 $msg2 = unserialize( serialize( $msg2 ) );
76 $this->compareMessages( $msg, $msg2 );
77 $this->assertEquals( 'code', $msg2->getApiCode() );
78 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
80 $msg = new RawMessage( 'foo', array( 'baz' ) );
81 $msg2 = new ApiRawMessage( array( 'foo', 'baz' ), 'code', array( 'data' ) );
82 $this->compareMessages( $msg, $msg2 );
83 $this->assertEquals( 'code', $msg2->getApiCode() );
84 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
86 $msg = new RawMessage( 'foo' );
87 $msg2 = new ApiRawMessage( 'foo', 'code', array( 'data' ) );
88 $this->compareMessages( $msg, $msg2 );
89 $this->assertEquals( 'code', $msg2->getApiCode() );
90 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
92 $msg2->setApiCode( 'code', array( 'data' ) );
93 $this->assertEquals( 'code', $msg2->getApiCode() );
94 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
95 $msg2->setApiCode( null );
96 $this->assertEquals( 'foo', $msg2->getApiCode() );
97 $this->assertEquals( array( 'data' ), $msg2->getApiData() );
98 $msg2->setApiData( array( 'data2' ) );
99 $this->assertEquals( array( 'data2' ), $msg2->getApiData() );
103 * @covers ApiMessage::create
105 public function testApiMessageCreate() {
106 $this->assertInstanceOf( 'ApiMessage', ApiMessage
::create( new Message( 'mainpage' ) ) );
107 $this->assertInstanceOf( 'ApiRawMessage', ApiMessage
::create( new RawMessage( 'mainpage' ) ) );
108 $this->assertInstanceOf( 'ApiMessage', ApiMessage
::create( 'mainpage' ) );
110 $msg = new ApiMessage( 'mainpage' );
111 $this->assertSame( $msg, ApiMessage
::create( $msg ) );
113 $msg = new ApiRawMessage( 'mainpage' );
114 $this->assertSame( $msg, ApiMessage
::create( $msg ) );