3 use Wikimedia\ObjectFactory
;
4 use Wikimedia\TestingAccessWrapper
;
9 class MessageTest
extends MediaWikiLangTestCase
{
11 protected function setUp() {
14 $this->setMwGlobals( [
15 'wgForceUIMsgAsContentMsg' => [],
17 $this->setUserLang( 'en' );
21 * @covers Message::__construct
22 * @dataProvider provideConstructor
24 public function testConstructor( $expectedLang, $key, $params, $language ) {
25 $message = new Message( $key, $params, $language );
27 $this->assertSame( $key, $message->getKey() );
28 $this->assertSame( $params, $message->getParams() );
29 $this->assertSame( $expectedLang->getCode(), $message->getLanguage()->getCode() );
31 $messageSpecifier = $this->getMockForAbstractClass( MessageSpecifier
::class );
32 $messageSpecifier->expects( $this->any() )
33 ->method( 'getKey' )->will( $this->returnValue( $key ) );
34 $messageSpecifier->expects( $this->any() )
35 ->method( 'getParams' )->will( $this->returnValue( $params ) );
36 $message = new Message( $messageSpecifier, [], $language );
38 $this->assertSame( $key, $message->getKey() );
39 $this->assertSame( $params, $message->getParams() );
40 $this->assertSame( $expectedLang->getCode(), $message->getLanguage()->getCode() );
43 public static function provideConstructor() {
44 $langDe = Language
::factory( 'de' );
45 $langEn = Language
::factory( 'en' );
48 [ $langDe, 'foo', [], $langDe ],
49 [ $langDe, 'foo', [ 'bar' ], $langDe ],
50 [ $langEn, 'foo', [ 'bar' ], null ]
54 public static function provideConstructorParams() {
81 [ Message
::rawParam( 'baz' ) ],
82 [ Message
::rawParam( 'baz' ) ],
85 [ Message
::rawParam( 'baz' ), 'foo' ],
86 [ Message
::rawParam( 'baz' ), 'foo' ],
89 [ Message
::rawParam( 'baz' ) ],
90 [ [ Message
::rawParam( 'baz' ) ] ],
93 [ Message
::rawParam( 'baz' ), 'foo' ],
94 [ [ Message
::rawParam( 'baz' ), 'foo' ] ],
97 // Test handling of erroneous input, to detect if it changes
99 [ [ 'baz', 'foo' ], 'hhh' ],
100 [ [ 'baz', 'foo' ], 'hhh' ],
103 [ [ 'baz', 'foo' ], 'hhh', [ 'ahahahahha' ] ],
104 [ [ 'baz', 'foo' ], 'hhh', [ 'ahahahahha' ] ],
107 [ [ 'baz', 'foo' ], [ 'ahahahahha' ] ],
108 [ [ 'baz', 'foo' ], [ 'ahahahahha' ] ],
111 [ [ 'baz' ], [ 'ahahahahha' ] ],
112 [ [ 'baz' ], [ 'ahahahahha' ] ],
118 * @covers Message::__construct
119 * @covers Message::getParams
120 * @dataProvider provideConstructorParams
122 public function testConstructorParams( $expected, $args ) {
123 $msg = new Message( 'imasomething' );
125 $returned = call_user_func_array( [ $msg, 'params' ], $args );
127 $this->assertSame( $msg, $returned );
128 $this->assertSame( $expected, $msg->getParams() );
131 public static function provideConstructorLanguage() {
133 [ 'foo', [ 'bar' ], 'en' ],
134 [ 'foo', [ 'bar' ], 'de' ]
139 * @covers Message::__construct
140 * @covers Message::getLanguage
141 * @dataProvider provideConstructorLanguage
143 public function testConstructorLanguage( $key, $params, $languageCode ) {
144 $language = Language
::factory( $languageCode );
145 $message = new Message( $key, $params, $language );
147 $this->assertEquals( $language, $message->getLanguage() );
150 public static function provideKeys() {
154 'expected' => [ 'mainpage' ],
157 'key' => [ 'mainpage' ],
158 'expected' => [ 'mainpage' ],
161 'key' => [ 'mainpage-foo', 'mainpage-bar', 'mainpage' ],
162 'expected' => [ 'mainpage-foo', 'mainpage-bar', 'mainpage' ],
167 'exception' => 'InvalidArgumentException',
172 'exception' => 'InvalidArgumentException',
177 'exception' => 'InvalidArgumentException',
183 * @covers Message::__construct
184 * @covers Message::getKey
185 * @covers Message::isMultiKey
186 * @covers Message::getKeysToTry
187 * @dataProvider provideKeys
189 public function testKeys( $key, $expected, $exception = null ) {
191 $this->setExpectedException( $exception );
194 $msg = new Message( $key );
195 $this->assertContains( $msg->getKey(), $expected );
196 $this->assertSame( $expected, $msg->getKeysToTry() );
197 $this->assertSame( count( $expected ) > 1, $msg->isMultiKey() );
201 * @covers ::wfMessage
203 public function testWfMessage() {
204 $this->assertInstanceOf( Message
::class, wfMessage( 'mainpage' ) );
205 $this->assertInstanceOf( Message
::class, wfMessage( 'i-dont-exist-evar' ) );
209 * @covers Message::newFromKey
211 public function testNewFromKey() {
212 $this->assertInstanceOf( Message
::class, Message
::newFromKey( 'mainpage' ) );
213 $this->assertInstanceOf( Message
::class, Message
::newFromKey( 'i-dont-exist-evar' ) );
217 * @covers ::wfMessage
218 * @covers Message::__construct
220 public function testWfMessageParams() {
221 $this->assertSame( 'Return to $1.', wfMessage( 'returnto' )->text() );
222 $this->assertSame( 'Return to $1.', wfMessage( 'returnto', [] )->text() );
225 wfMessage( 'returnto', Message
::numParam( 1024 ) )->text()
229 wfMessage( 'returnto', [ Message
::numParam( 1024 ) ] )->text()
232 'You have foo (bar).',
233 wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text()
236 'You have foo (bar).',
237 wfMessage( 'youhavenewmessages', [ 'foo', 'bar' ] )->text()
240 'You have 1,024 (bar).',
242 'youhavenewmessages',
243 Message
::numParam( 1024 ), 'bar'
247 'You have foo (2,048).',
249 'youhavenewmessages',
250 'foo', Message
::numParam( 2048 )
254 'You have 1,024 (2,048).',
256 'youhavenewmessages',
257 [ Message
::numParam( 1024 ), Message
::numParam( 2048 ) ]
263 * @covers Message::exists
265 public function testExists() {
266 $this->assertTrue( wfMessage( 'mainpage' )->exists() );
267 $this->assertTrue( wfMessage( 'mainpage' )->params( [] )->exists() );
268 $this->assertTrue( wfMessage( 'mainpage' )->rawParams( 'foo', 123 )->exists() );
269 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->exists() );
270 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->params( [] )->exists() );
271 $this->assertFalse( wfMessage( 'i-dont-exist-evar' )->rawParams( 'foo', 123 )->exists() );
275 * @covers Message::__construct
276 * @covers Message::text
277 * @covers Message::plain
278 * @covers Message::escaped
279 * @covers Message::toString
281 public function testToStringKey() {
282 $this->assertSame( 'Main Page', wfMessage( 'mainpage' )->text() );
283 $this->assertSame( '⧼i-dont-exist-evar⧽', wfMessage( 'i-dont-exist-evar' )->text() );
284 $this->assertSame( '⧼i<dont>exist-evar⧽', wfMessage( 'i<dont>exist-evar' )->text() );
285 $this->assertSame( '⧼i-dont-exist-evar⧽', wfMessage( 'i-dont-exist-evar' )->plain() );
286 $this->assertSame( '⧼i<dont>exist-evar⧽', wfMessage( 'i<dont>exist-evar' )->plain() );
287 $this->assertSame( '⧼i-dont-exist-evar⧽', wfMessage( 'i-dont-exist-evar' )->escaped() );
289 '⧼i<dont>exist-evar⧽',
290 wfMessage( 'i<dont>exist-evar' )->escaped()
294 public static function provideToString() {
296 // key, transformation, transformed, transformed implicitly
297 [ 'mainpage', 'plain', 'Main Page', 'Main Page' ],
298 [ 'i-dont-exist-evar', 'plain', '⧼i-dont-exist-evar⧽', '⧼i-dont-exist-evar⧽' ],
299 [ 'i-dont-exist-evar', 'escaped', '⧼i-dont-exist-evar⧽', '⧼i-dont-exist-evar⧽' ],
300 [ 'script>alert(1)</script', 'escaped', '⧼script>alert(1)</script⧽',
301 '⧼script>alert(1)</script⧽' ],
302 [ 'script>alert(1)</script', 'plain', '⧼script>alert(1)</script⧽',
303 '⧼script>alert(1)</script⧽' ],
308 * @covers Message::toString
309 * @covers Message::__toString
310 * @dataProvider provideToString
312 public function testToString( $key, $format, $expect, $expectImplicit ) {
313 $msg = new Message( $key );
314 $this->assertSame( $expect, $msg->$format() );
315 $this->assertSame( $expect, $msg->toString(), 'toString is unaffected by previous call' );
316 $this->assertSame( $expectImplicit, $msg->__toString() );
317 $this->assertSame( $expect, $msg->toString(), 'toString is unaffected by __toString' );
320 public static function provideToString_raw() {
322 [ '<span>foo</span>', 'parse', '<span>foo</span>', '<span>foo</span>' ],
323 [ '<span>foo</span>', 'escaped', '<span>foo</span>',
324 '<span>foo</span>' ],
325 [ '<span>foo</span>', 'plain', '<span>foo</span>', '<span>foo</span>' ],
326 [ '<script>alert(1)</script>', 'parse', '<script>alert(1)</script>',
327 '<script>alert(1)</script>' ],
328 [ '<script>alert(1)</script>', 'escaped', '<script>alert(1)</script>',
329 '<script>alert(1)</script>' ],
330 [ '<script>alert(1)</script>', 'plain', '<script>alert(1)</script>',
331 '<script>alert(1)</script>' ],
336 * @covers Message::toString
337 * @covers Message::__toString
338 * @dataProvider provideToString_raw
340 public function testToString_raw( $message, $format, $expect, $expectImplicit ) {
341 // make the message behave like RawMessage and use the key as-is
342 $msg = $this->getMockBuilder( Message
::class )->setMethods( [ 'fetchMessage' ] )
343 ->disableOriginalConstructor()
345 $msg->expects( $this->any() )->method( 'fetchMessage' )->willReturn( $message );
346 /** @var Message $msg */
347 $this->assertSame( $expect, $msg->$format() );
348 $this->assertSame( $expect, $msg->toString(), 'toString is unaffected by previous call' );
349 $this->assertSame( $expectImplicit, $msg->__toString() );
350 $this->assertSame( $expect, $msg->toString(), 'toString is unaffected by __toString' );
354 * @covers Message::inLanguage
356 public function testInLanguage() {
357 $this->assertSame( 'Main Page', wfMessage( 'mainpage' )->inLanguage( 'en' )->text() );
358 $this->assertSame( 'Заглавная страница',
359 wfMessage( 'mainpage' )->inLanguage( 'ru' )->text() );
361 // NOTE: make sure internal caching of the message text is reset appropriately
362 $msg = wfMessage( 'mainpage' );
363 $this->assertSame( 'Main Page', $msg->inLanguage( Language
::factory( 'en' ) )->text() );
365 'Заглавная страница',
366 $msg->inLanguage( Language
::factory( 'ru' ) )->text()
371 * @covers Message::rawParam
372 * @covers Message::rawParams
374 public function testRawParams() {
376 '(Заглавная страница)',
377 wfMessage( 'parentheses', 'Заглавная страница' )->plain()
380 '(Заглавная страница $1)',
381 wfMessage( 'parentheses', 'Заглавная страница $1' )->plain()
384 '(Заглавная страница)',
385 wfMessage( 'parentheses' )->rawParams( 'Заглавная страница' )->plain()
388 '(Заглавная страница $1)',
389 wfMessage( 'parentheses' )->rawParams( 'Заглавная страница $1' )->plain()
394 * @covers RawMessage::__construct
395 * @covers RawMessage::fetchMessage
397 public function testRawMessage() {
398 $msg = new RawMessage( 'example &' );
399 $this->assertSame( 'example &', $msg->plain() );
400 $this->assertSame( 'example &', $msg->escaped() );
403 public function testRawHtmlInMsg() {
404 global $wgParserConf;
405 $this->setMwGlobals( 'wgRawHtml', true );
406 // We have to reset the core hook registration.
407 // to register the html hook
408 MessageCache
::destroyInstance();
409 $this->setMwGlobals( 'wgParser',
410 ObjectFactory
::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
413 $msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
414 $txt = '<span class="error"><html> tags cannot be' .
415 ' used outside of normal pages.</span>';
416 $this->assertSame( $txt, $msg->parse() );
420 * @covers Message::params
421 * @covers Message::toString
422 * @covers Message::replaceParameters
424 public function testReplaceManyParams() {
425 $msg = new RawMessage( '$1$2$3$4$5$6$7$8$9$10$11$12' );
426 // One less than above has placeholders
427 $params = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' ];
430 $msg->params( $params )->plain(),
431 'Params > 9 are replaced correctly'
434 $msg = new RawMessage( 'Params$*' );
435 $params = [ 'ab', 'bc', 'cd' ];
437 'Params: ab, bc, cd',
438 $msg->params( $params )->text()
443 * @covers Message::numParam
444 * @covers Message::numParams
446 public function testNumParams() {
447 $lang = Language
::factory( 'en' );
448 $msg = new RawMessage( '$1' );
451 $lang->formatNum( 123456.789 ),
452 $msg->inLanguage( $lang )->numParams( 123456.789 )->plain(),
453 'numParams is handled correctly'
458 * @covers Message::durationParam
459 * @covers Message::durationParams
461 public function testDurationParams() {
462 $lang = Language
::factory( 'en' );
463 $msg = new RawMessage( '$1' );
466 $lang->formatDuration( 1234 ),
467 $msg->inLanguage( $lang )->durationParams( 1234 )->plain(),
468 'durationParams is handled correctly'
473 * FIXME: This should not need database, but Language#formatExpiry does (T57912)
474 * @covers Message::expiryParam
475 * @covers Message::expiryParams
477 public function testExpiryParams() {
478 $lang = Language
::factory( 'en' );
479 $msg = new RawMessage( '$1' );
482 $lang->formatExpiry( wfTimestampNow() ),
483 $msg->inLanguage( $lang )->expiryParams( wfTimestampNow() )->plain(),
484 'expiryParams is handled correctly'
489 * @covers Message::timeperiodParam
490 * @covers Message::timeperiodParams
492 public function testTimeperiodParams() {
493 $lang = Language
::factory( 'en' );
494 $msg = new RawMessage( '$1' );
497 $lang->formatTimePeriod( 1234 ),
498 $msg->inLanguage( $lang )->timeperiodParams( 1234 )->plain(),
499 'timeperiodParams is handled correctly'
504 * @covers Message::sizeParam
505 * @covers Message::sizeParams
507 public function testSizeParams() {
508 $lang = Language
::factory( 'en' );
509 $msg = new RawMessage( '$1' );
512 $lang->formatSize( 123456 ),
513 $msg->inLanguage( $lang )->sizeParams( 123456 )->plain(),
514 'sizeParams is handled correctly'
519 * @covers Message::bitrateParam
520 * @covers Message::bitrateParams
522 public function testBitrateParams() {
523 $lang = Language
::factory( 'en' );
524 $msg = new RawMessage( '$1' );
527 $lang->formatBitrate( 123456 ),
528 $msg->inLanguage( $lang )->bitrateParams( 123456 )->plain(),
529 'bitrateParams is handled correctly'
533 public static function providePlaintextParams() {
536 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
542 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
547 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
552 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
557 "<p>one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;\n</p>",
564 * @covers Message::plaintextParam
565 * @covers Message::plaintextParams
566 * @covers Message::formatPlaintext
567 * @covers Message::toString
568 * @covers Message::parse
569 * @covers Message::parseAsBlock
570 * @dataProvider providePlaintextParams
572 public function testPlaintextParams( $expect, $format ) {
573 $lang = Language
::factory( 'en' );
575 $msg = new RawMessage( '$1 $2' );
578 '<div>foo</div> [[Bar]] {{Baz}} <',
582 $msg->inLanguage( $lang )->plaintextParams( $params )->$format(),
583 "Fail formatting for $format"
587 public static function provideListParam() {
588 $lang = Language
::factory( 'de' );
589 $msg1 = new Message( 'mainpage', [], $lang );
590 $msg2 = new RawMessage( "''link''", [], $lang );
593 'Simple comma list' => [
600 'Simple semicolon list' => [
607 'Simple pipe list' => [
614 'Simple text list' => [
628 'List with all "before" params, ->text()' => [
629 [ "''link''", Message
::numParam( 12345678 ) ],
632 '\'\'link\'\'; 12,345,678'
635 'List with all "before" params, ->parse()' => [
636 [ "''link''", Message
::numParam( 12345678 ) ],
639 '<i>link</i>; 12,345,678'
642 'List with all "after" params, ->text()' => [
643 [ $msg1, $msg2, Message
::rawParam( '[[foo]]' ) ],
646 'Main Page; \'\'link\'\'; [[foo]]'
649 'List with all "after" params, ->parse()' => [
650 [ $msg1, $msg2, Message
::rawParam( '[[foo]]' ) ],
653 'Main Page; <i>link</i>; [[foo]]'
656 'List with both "before" and "after" params, ->text()' => [
657 [ $msg1, $msg2, Message
::rawParam( '[[foo]]' ), "''link''", Message
::numParam( 12345678 ) ],
660 'Main Page; \'\'link\'\'; [[foo]]; \'\'link\'\'; 12,345,678'
663 'List with both "before" and "after" params, ->parse()' => [
664 [ $msg1, $msg2, Message
::rawParam( '[[foo]]' ), "''link''", Message
::numParam( 12345678 ) ],
667 'Main Page; <i>link</i>; [[foo]]; <i>link</i>; 12,345,678'
673 * @covers Message::listParam
674 * @covers Message::extractParam
675 * @covers Message::formatListParam
676 * @dataProvider provideListParam
678 public function testListParam( $list, $type, $format, $expect ) {
679 $lang = Language
::factory( 'en' );
681 $msg = new RawMessage( '$1' );
682 $msg->params( [ Message
::listParam( $list, $type ) ] );
685 $msg->inLanguage( $lang )->$format()
690 * @covers Message::extractParam
692 public function testMessageAsParam() {
693 $this->setMwGlobals( [
694 'wgScript' => '/wiki/index.php',
695 'wgArticlePath' => '/wiki/$1',
698 $msg = new Message( 'returnto', [
699 new Message( 'apihelp-link', [
700 'foo', new Message( 'mainpage', [], Language
::factory( 'en' ) )
701 ], Language
::factory( 'de' ) )
702 ], Language
::factory( 'es' ) );
705 'Volver a [[Special:ApiHelp/foo|Página principal]].',
707 'Process with ->text()'
710 '<p>Volver a <a href="/wiki/Special:ApiHelp/foo" title="Special:ApiHelp/foo">Página '
711 . "principal</a>.\n</p>",
712 $msg->parseAsBlock(),
713 'Process with ->parseAsBlock()'
717 public static function provideParser() {
720 "''&'' <x><!-- x -->",
725 "''&'' <x><!-- x -->",
729 '<i>&</i> <x>',
734 "<p><i>&</i> <x>\n</p>",
741 * @covers Message::text
742 * @covers Message::parse
743 * @covers Message::parseAsBlock
744 * @covers Message::toString
745 * @covers Message::transformText
746 * @covers Message::parseText
747 * @dataProvider provideParser
749 public function testParser( $expect, $format ) {
750 $msg = new RawMessage( "''&'' <x><!-- x -->" );
753 $msg->inLanguage( 'en' )->$format()
758 * @covers Message::inContentLanguage
760 public function testInContentLanguage() {
761 $this->setUserLang( 'fr' );
763 // NOTE: make sure internal caching of the message text is reset appropriately
764 $msg = wfMessage( 'mainpage' );
765 $this->assertSame( 'Hauptseite', $msg->inLanguage( 'de' )->plain(), "inLanguage( 'de' )" );
766 $this->assertSame( 'Main Page', $msg->inContentLanguage()->plain(), "inContentLanguage()" );
767 $this->assertSame( 'Accueil', $msg->inLanguage( 'fr' )->plain(), "inLanguage( 'fr' )" );
771 * @covers Message::inContentLanguage
773 public function testInContentLanguageOverride() {
774 $this->setMwGlobals( [
775 'wgForceUIMsgAsContentMsg' => [ 'mainpage' ],
777 $this->setUserLang( 'fr' );
779 // NOTE: make sure internal caching of the message text is reset appropriately.
780 // NOTE: wgForceUIMsgAsContentMsg forces the messages *current* language to be used.
781 $msg = wfMessage( 'mainpage' );
784 $msg->inContentLanguage()->plain(),
785 'inContentLanguage() with ForceUIMsg override enabled'
787 $this->assertSame( 'Main Page', $msg->inLanguage( 'en' )->plain(), "inLanguage( 'en' )" );
790 $msg->inContentLanguage()->plain(),
791 'inContentLanguage() with ForceUIMsg override enabled'
793 $this->assertSame( 'Hauptseite', $msg->inLanguage( 'de' )->plain(), "inLanguage( 'de' )" );
797 * @expectedException MWException
798 * @covers Message::inLanguage
800 public function testInLanguageThrows() {
801 wfMessage( 'foo' )->inLanguage( 123 );
805 * @covers Message::serialize
806 * @covers Message::unserialize
808 public function testSerialization() {
809 $msg = new Message( 'parentheses' );
810 $msg->rawParams( '<a>foo</a>' );
811 $msg->title( Title
::newFromText( 'Testing' ) );
812 $this->assertSame( '(<a>foo</a>)', $msg->parse(), 'Sanity check' );
813 $msg = unserialize( serialize( $msg ) );
814 $this->assertSame( '(<a>foo</a>)', $msg->parse() );
815 $title = TestingAccessWrapper
::newFromObject( $msg )->title
;
816 $this->assertInstanceOf( Title
::class, $title );
817 $this->assertSame( 'Testing', $title->getFullText() );
819 $msg = new Message( 'mainpage' );
820 $msg->inLanguage( 'de' );
821 $this->assertSame( 'Hauptseite', $msg->plain(), 'Sanity check' );
822 $msg = unserialize( serialize( $msg ) );
823 $this->assertSame( 'Hauptseite', $msg->plain() );
827 * @covers Message::newFromSpecifier
828 * @dataProvider provideNewFromSpecifier
830 public function testNewFromSpecifier( $value, $expectedText ) {
831 $message = Message
::newFromSpecifier( $value );
832 $this->assertInstanceOf( Message
::class, $message );
833 if ( $value instanceof Message
) {
834 $this->assertInstanceOf( get_class( $value ), $message );
835 $this->assertEquals( $value, $message );
837 $this->assertSame( $expectedText, $message->text() );
840 public function provideNewFromSpecifier() {
841 $messageSpecifier = $this->getMockForAbstractClass( MessageSpecifier
::class );
842 $messageSpecifier->expects( $this->any() )->method( 'getKey' )->willReturn( 'mainpage' );
843 $messageSpecifier->expects( $this->any() )->method( 'getParams' )->willReturn( [] );
846 'string' => [ 'mainpage', 'Main Page' ],
847 'array' => [ [ 'youhavenewmessages', 'foo', 'bar' ], 'You have foo (bar).' ],
848 'Message' => [ new Message( 'youhavenewmessages', [ 'foo', 'bar' ] ), 'You have foo (bar).' ],
849 'RawMessage' => [ new RawMessage( 'foo ($1)', [ 'bar' ] ), 'foo (bar)' ],
850 'ApiMessage' => [ new ApiMessage( [ 'mainpage' ], 'code', [ 'data' ] ), 'Main Page' ],
851 'MessageSpecifier' => [ $messageSpecifier, 'Main Page' ],
852 'nested RawMessage' => [ [ new RawMessage( 'foo ($1)', [ 'bar' ] ) ], 'foo (bar)' ],