diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/HmacSerializerTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/HmacSerializerTest.php | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/HmacSerializerTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/HmacSerializerTest.php new file mode 100644 index 00000000..98c302a6 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/HmacSerializerTest.php @@ -0,0 +1,132 @@ +<?php + +namespace SMW\Tests\Utils; + +use SMW\Utils\HmacSerializer; + +/** + * @covers \SMW\Utils\HmacSerializer + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class HmacSerializerTest extends \PHPUnit_Framework_TestCase { + + public function testEncodeWithDifferentKey() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $this->assertNotSame( + $instance->encode( $data, 'abc' ), + $instance->encode( $data, 'def' ) + ); + } + + public function testUDecodeUsingAnObject() { + + $this->assertFalse( + HmacSerializer::decode( $this ) + ); + } + + public function testRoundtripEncodeDecode() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $this->assertEquals( + $data, + $instance->decode( $instance->encode( $data, 'def' ), 'def' ) + ); + } + + public function testRoundtripEncodeDecodeWithDifferentKey() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $result = $instance->decode( + $instance->encode( $data, 'def' ), + 'abc' + ); + + $this->assertNotEquals( + $data, + $result + ); + + $this->assertFalse( + $result + ); + } + + public function testSeralizeWithDifferentKey() { + + $data = [ 'Foo' ]; + + $this->assertNotSame( + HmacSerializer::serialize( $data, 'abc' ), + HmacSerializer::serialize( $data, 'def' ) + ); + } + + public function testUnseralizeUsingAnObject() { + + $this->assertFalse( + HmacSerializer::unserialize( $this ) + ); + } + + public function testRoundtripSerializeDeserialize() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $this->assertEquals( + $data, + $instance->unserialize( $instance->serialize( $data, 'def' ), 'def' ) + ); + } + + public function testRoundtripCompressUncompress() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $this->assertEquals( + $data, + $instance->uncompress( $instance->compress( $data, 'def' ), 'def' ) + ); + } + + public function testRoundtripSerializeDeserializeWithDifferentKey() { + + $instance = new HmacSerializer(); + + $data = [ 'Foo' ]; + + $result = $instance->unserialize( + $instance->serialize( $data, 'def' ), + 'abc' + ); + + $this->assertNotEquals( + $data, + $result + ); + + $this->assertFalse( + $result + ); + } + +} |