00001 <?php
00015 class ApiQueryMessageGroupsTest extends ApiTestCase {
00016
00017 protected function setUp() {
00018 parent::setUp();
00019
00020 global $wgHooks;
00021 $this->setMwGlobals( array(
00022 'wgHooks' => $wgHooks,
00023 'wgTranslateCC' => array(),
00024 'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00025 'wgTranslateWorkflowStates' => false,
00026 'wgTranslateGroupFiles' => array(),
00027 'wgEnablePageTranslation' => false,
00028 'wgTranslateTranslationServices' => array(),
00029 ) );
00030 $wgHooks['TranslatePostInitGroups'] = array( array( $this, 'getTestGroups' ) );
00031 MessageGroups::clearCache();
00032 MessageIndexRebuildJob::newJob()->run();
00033 }
00034
00035 public function getTestGroups( &$list ) {
00036 $exampleMessageGroup = new WikiMessageGroup( 'theid', 'thesource' );
00037 $exampleMessageGroup->setLabel( 'thelabel' );
00038 $exampleMessageGroup->setNamespace( 5 );
00039 $list['theid'] = $exampleMessageGroup;
00040
00041 $anotherExampleMessageGroup = new WikiMessageGroup( 'anotherid', 'thesource' );
00042 $anotherExampleMessageGroup->setLabel( 'thelabel' );
00043 $anotherExampleMessageGroup->setNamespace( 5 );
00044 $list['anotherid'] = $anotherExampleMessageGroup;
00045
00046 return false;
00047 }
00048
00049 public function testAPIAccuracy() {
00050 list( $data ) = $this->doApiRequest(
00051 array(
00052 'action' => 'query',
00053 'meta' => 'messagegroups',
00054 'mgprop' => 'id|label|class|namespace|exists',
00055 )
00056 );
00057
00058
00059 $this->assertCount( 1, $data );
00060 $this->assertArrayHasKey( 'query', $data );
00061 $this->assertCount( 1, $data['query'] );
00062 $this->assertArrayHasKey( 'messagegroups', $data['query'] );
00063
00064
00065 $items = $data['query']['messagegroups'];
00066
00067
00068 foreach ( $items as $index => $group ) {
00069 if ( $group['id'][0] === '!' ) {
00070 unset( $items[$index] );
00071 }
00072 }
00073
00074
00075 $items = array_values( $items );
00076
00077 $this->assertCount( 2, $items, 'Only the two groups specified are in the api' );
00078 $this->assertStringEndsWith( 'id', $items[0]['id'] );
00079 $this->assertStringEndsWith( 'id', $items[1]['id'] );
00080 $this->assertSame( $items[0]['label'], 'thelabel' );
00081 $this->assertSame( $items[1]['label'], 'thelabel' );
00082 $this->assertSame( $items[0]['exists'], true );
00083 $this->assertSame( $items[1]['exists'], true );
00084 $this->assertSame( $items[0]['namespace'], 5 );
00085 $this->assertSame( $items[1]['namespace'], 5 );
00086 $this->assertSame( $items[0]['class'], 'WikiMessageGroup' );
00087 $this->assertSame( $items[1]['class'], 'WikiMessageGroup' );
00088 }
00089
00090 public function testAPIFilterAccuracy() {
00091 $ids = array( 'MadeUpGroup' );
00092 $ids += array_keys( MessageGroups::getAllGroups() );
00093
00094 foreach ( $ids as $id ) {
00095 list( $data ) = $this->doApiRequest(
00096 array(
00097 'action' => 'query',
00098 'meta' => 'messagegroups',
00099 'mgprop' => 'id|label|class|namespace|exists',
00100 'mgfilter' => $id
00101 )
00102 );
00103
00104 if ( $id === 'MadeUpGroup' ) {
00105
00106 $this->assertCount( 1, $data );
00107 $this->assertArrayHasKey( 'query', $data );
00108 $this->assertCount( 1, $data['query'] );
00109 $this->assertArrayHasKey( 'messagegroups', $data['query'] );
00110 $this->assertCount( 0, $data['query']['messagegroups'] );
00111 continue;
00112 }
00113
00114
00115 $this->assertCount( 1, $data );
00116 $this->assertArrayHasKey( 'query', $data );
00117 $this->assertCount( 1, $data['query'] );
00118 $this->assertArrayHasKey( 'messagegroups', $data['query'] );
00119 $this->assertCount( 1, $data['query']['messagegroups'] );
00120
00121
00122 $item = $data['query']['messagegroups'][0];
00123 $this->assertCount( 5, $item );
00124
00125 $this->assertSame( $item['id'], $id );
00126 $this->assertSame( $item['label'], 'thelabel' );
00127 $this->assertSame( $item['exists'], true );
00128 $this->assertStringEndsWith( 'id', $item['id'] );
00129 $this->assertSame( $item['namespace'], 5 );
00130 $this->assertSame( $item['class'], 'WikiMessageGroup' );
00131 }
00132 }
00133
00134 public function testBadProperty() {
00135 list( $data ) = $this->doApiRequest(
00136 array(
00137 'action' => 'query',
00138 'meta' => 'messagegroups',
00139 'mgprop' => 'madeupproperty'
00140 )
00141 );
00142
00143 $this->assertCount( 2, $data );
00144
00145 $this->assertArrayHasKey( 'query', $data );
00146 $this->assertCount( 1, $data['query'] );
00147 $this->assertArrayHasKey( 'messagegroups', $data['query'] );
00148
00149
00150
00151
00152 $this->assertArrayHasKey( 'warnings', $data );
00153 $this->assertCount( 1, $data['warnings'] );
00154 $this->assertArrayHasKey( 'messagegroups', $data['warnings'] );
00155 $this->assertCount( 1, $data['warnings']['messagegroups'] );
00156 $this->assertArrayHasKey( '*', $data['warnings']['messagegroups'] );
00157 }
00158 }