[
[ 'key', [] ],
'',
],
'withText' => [
[ 'key', [ 'a' ] ],
'a'
],
'withScalarParam' => [
[ 'key', [ new ScalarParam( ParamType::BITRATE, 100 ) ] ],
'100'
],
];
}
/** @dataProvider provideConstruct */
public function testSerialize( $args, $_ ) {
[ $key, $input ] = $args;
$codec = new JsonCodec;
$obj = new MessageValue( $key, $input );
$serialized = $codec->serialize( $obj );
$newObj = $codec->deserialize( $serialized );
// XXX: would be nice to have a proper ::equals() method.
$this->assertEquals( $obj->dump(), $newObj->dump() );
}
/** @dataProvider provideConstruct */
public function testConstruct( $args, $expected ) {
[ $key, $input ] = $args;
$mv = new MessageValue( $key, $input );
$this->assertSame( $expected, $mv->dump() );
}
/** @dataProvider provideConstruct */
public function testNew( $args, $expected ) {
[ $key, $input ] = $args;
$mv = MessageValue::new( $key, $input );
$this->assertSame( $expected, $mv->dump() );
}
public function testGetKey() {
$mv = new MessageValue( 'key' );
$this->assertSame( 'key', $mv->getKey() );
}
public function testGetParams() {
$mv = new MessageValue( 'key', [ 'a', 'b' ] );
$this->assertEquals( [
new ScalarParam( ParamType::TEXT, 'a' ),
new ScalarParam( ParamType::TEXT, 'b' ),
], $mv->getParams() );
}
public function testParams() {
$mv = new MessageValue( 'key' );
$mv->params( 1, 'x' );
$mv2 = $mv->params( new ScalarParam( ParamType::BITRATE, 100 ) );
$this->assertSame(
'1x100',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testTextParamsOfType() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->textParamsOfType( ParamType::BITRATE, 1, 2 );
$this->assertSame( '' .
'12' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testListParamsOfType() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->listParamsOfType( ListType::COMMA, [ 'a' ], [ 'b', 'c' ] );
$this->assertSame( '' .
'a
' .
'bc
' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testTextParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->textParams( 'a', 'b', new MessageValue( 'key2' ) );
$this->assertSame( '' .
'a' .
'b' .
'' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testNumParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->numParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testLongDurationParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->longDurationParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testShortDurationParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->shortDurationParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testExpiryParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->expiryParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testDateTimeParams() {
$mv = new MessageValue( 'key' );
$ts = '1617158201';
$mv2 = $mv->dateTimeParams( $ts );
$this->assertSame( '' .
"$ts" .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testDateParams() {
$mv = new MessageValue( 'key' );
$ts = '1617158201';
$mv2 = $mv->dateParams( $ts );
$this->assertSame( '' .
"$ts" .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testTimeParams() {
$mv = new MessageValue( 'key' );
$ts = '1617158201';
$mv2 = $mv->timeParams( $ts );
$this->assertSame( '' .
"" .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testUserGroupParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->userGroupParams( 'bot' );
$this->assertSame( '' .
"bot" .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testSizeParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->sizeParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testBitrateParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->bitrateParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testRawParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->rawParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testPlaintextParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->plaintextParams( 1, 2 );
$this->assertSame( '' .
'1' .
'2' .
'',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testCommaListParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->commaListParams( [ 'a', 'b' ] );
$this->assertSame( '' .
'' .
'ab' .
'
',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testSemicolonListParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->semicolonListParams( [ 'a', 'b' ] );
$this->assertSame( '' .
'' .
'ab' .
'
',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testPipeListParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->pipeListParams( [ 'a', 'b' ] );
$this->assertSame( '' .
'' .
'ab' .
'
',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
public function testTextListParams() {
$mv = new MessageValue( 'key' );
$mv2 = $mv->textListParams( [ 'a', 'b' ] );
$this->assertSame( '' .
'' .
'ab' .
'
',
$mv->dump() );
$this->assertSame( $mv, $mv2 );
}
}