aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiMessageTest.php
diff options
context:
space:
mode:
authorBrad Jorsch <bjorsch@wikimedia.org>2015-07-02 12:21:58 -0400
committerBrad Jorsch <bjorsch@wikimedia.org>2015-07-07 15:56:47 -0400
commit7782819d647bd23eb9680736806213fe3600833f (patch)
tree6df6dd41a0343373dea68d77a017e800dbec7021 /tests/phpunit/includes/api/ApiMessageTest.php
parent0f87becd685558b6243c4ee001d232b0fd9c5c51 (diff)
downloadmediawikicore-7782819d647bd23eb9680736806213fe3600833f.tar.gz
mediawikicore-7782819d647bd23eb9680736806213fe3600833f.zip
Improve serialization of Message, Title
This allows them to be stored in the session, for example. Note that properly serializing a Message requires that all its parameters be serializable as well; we don't attempt to account for that here. Change-Id: I3a42a2a883e8eef900eeb02355fc3b064411f642
Diffstat (limited to 'tests/phpunit/includes/api/ApiMessageTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiMessageTest.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php
index 6c3ce60d18df..08a984eb25c3 100644
--- a/tests/phpunit/includes/api/ApiMessageTest.php
+++ b/tests/phpunit/includes/api/ApiMessageTest.php
@@ -14,9 +14,13 @@ class ApiMessageTest extends MediaWikiTestCase {
$msg = TestingAccessWrapper::newFromObject( $msg );
$msg2 = TestingAccessWrapper::newFromObject( $msg2 );
- foreach ( array( 'interface', 'useDatabase', 'title' ) as $key ) {
- $this->assertSame( $msg->$key, $msg2->$key, $key );
- }
+ $this->assertSame( $msg->interface, $msg2->interface, 'interface' );
+ $this->assertSame( $msg->useDatabase, $msg2->useDatabase, 'useDatabase' );
+ $this->assertSame(
+ $msg->title ? $msg->title->getFullText() : null,
+ $msg2->title ? $msg2->title->getFullText() : null,
+ 'title'
+ );
}
/**
@@ -30,6 +34,11 @@ class ApiMessageTest extends MediaWikiTestCase {
$this->assertEquals( 'code', $msg2->getApiCode() );
$this->assertEquals( array( 'data' ), $msg2->getApiData() );
+ $msg2 = unserialize( serialize( $msg2 ) );
+ $this->compareMessages( $msg, $msg2 );
+ $this->assertEquals( 'code', $msg2->getApiCode() );
+ $this->assertEquals( array( 'data' ), $msg2->getApiData() );
+
$msg = new Message( array( 'foo', 'bar' ), array( 'baz' ) );
$msg2 = new ApiMessage( array( array( 'foo', 'bar' ), 'baz' ), 'code', array( 'data' ) );
$this->compareMessages( $msg, $msg2 );
@@ -63,6 +72,11 @@ class ApiMessageTest extends MediaWikiTestCase {
$this->assertEquals( 'code', $msg2->getApiCode() );
$this->assertEquals( array( 'data' ), $msg2->getApiData() );
+ $msg2 = unserialize( serialize( $msg2 ) );
+ $this->compareMessages( $msg, $msg2 );
+ $this->assertEquals( 'code', $msg2->getApiCode() );
+ $this->assertEquals( array( 'data' ), $msg2->getApiData() );
+
$msg = new RawMessage( 'foo', array( 'baz' ) );
$msg2 = new ApiRawMessage( array( 'foo', 'baz' ), 'code', array( 'data' ) );
$this->compareMessages( $msg, $msg2 );