1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<?php
/*
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ML\JsonLD\Test;
use ML\JsonLD\LanguageTaggedString;
use ML\JsonLD\TypedValue;
/**
* Test LanguageTaggedString and TypedValue
*
* @author Markus Lanthaler <mail@markus-lanthaler.com>
*/
class ValueTest extends \PHPUnit\Framework\TestCase
{
/**
* Tests LanguageTaggedString
*/
public function testLanguageTaggedString()
{
$string1 = new LanguageTaggedString('', '');
$this->assertSame('', $string1->getValue(), 'string1 value');
$this->assertSame('', $string1->getLanguage(), 'string1 language');
$string2 = new LanguageTaggedString('wert', 'de');
$this->assertSame('wert', $string2->getValue(), 'string2 value');
$this->assertSame('de', $string2->getLanguage(), 'string2 language');
$string3 = new LanguageTaggedString('value', 'en');
$this->assertSame('value', $string3->getValue(), 'string3 value');
$this->assertSame('en', $string3->getLanguage(), 'string3 language');
}
/**
* Tests LanguageTaggedString with an invalid value
*/
public function testLanguageTaggedStringInvalidValue()
{
$this->expectException('InvalidArgumentException');
$string1 = new LanguageTaggedString('value', 'language');
$string1->setValue(1);
}
/**
* Tests LanguageTaggedString with an invalid language
*/
public function testLanguageTaggedStringInvalidLanguage()
{
$this->expectException('InvalidArgumentException');
$string1 = new LanguageTaggedString('value', 'language');
$string1->setLanguage(null);
}
/**
* Tests TypedValue
*/
public function testTypedValue()
{
$value1 = new TypedValue('', '');
$this->assertSame('', $value1->getValue(), 'string1 value');
$this->assertSame('', $value1->getType(), 'string1 type');
$value2 = new TypedValue('wert', 'http://example.com/type1');
$this->assertSame('wert', $value2->getValue(), 'string2 value');
$this->assertSame('http://example.com/type1', $value2->getType(), 'string2 type');
$value3 = new TypedValue('value', 'http://example.com/type2');
$this->assertSame('value', $value3->getValue(), 'string3 value');
$this->assertSame('http://example.com/type2', $value3->getType(), 'string3 type');
}
/**
* Tests TypedValue with an invalid value
*/
public function testTypedValueInvalidValue()
{
$this->expectException('InvalidArgumentException');
$value1 = new LanguageTaggedString('value', 'language');
$value1->setValue(1);
}
/**
* Tests TypedValue with an invalid type
*/
public function testTypedValueInvalidLanguage()
{
$this->expectException('InvalidArgumentException');
$value1 = new TypedValue('value', 'http://example.com/type');
$value1->setType(1);
}
/**
* Tests TypedValue with an invalid type
*/
public function testEquals()
{
$string1a = new LanguageTaggedString('value', 'en');
$string1b = new LanguageTaggedString('value', 'en');
$string2 = new LanguageTaggedString('value', 'de');
$string3 = new LanguageTaggedString('wert', 'en');
$this->assertTrue($string1a->equals($string1b), 's1a == s1b?');
$this->assertFalse($string1a->equals($string2), 's1a == s2?');
$this->assertFalse($string1a->equals($string3), 's1a == s3?');
$this->assertFalse($string1b->equals($string2), 's1b == s2?');
$this->assertFalse($string1b->equals($string3), 's1b == s3?');
$this->assertFalse($string2->equals($string3), 's2 == s3?');
$typed1a = new TypedValue('value', 'http://example.com/type1');
$typed1b = new TypedValue('value', 'http://example.com/type1');
$typed2 = new TypedValue('value', 'http://example.com/type2');
$typed3 = new TypedValue('wert', 'http://example.com/type1');
$this->assertTrue($typed1a->equals($typed1b), 't1a == t1b?');
$this->assertFalse($typed1a->equals($typed2), 't1a == t2?');
$this->assertFalse($typed1a->equals($typed3), 't1a == t3?');
$this->assertFalse($typed1b->equals($typed2), 't1b == t2?');
$this->assertFalse($typed1b->equals($typed3), 't1b == t3?');
$this->assertFalse($typed2->equals($typed3), 't2 == t3?');
$string4 = new LanguageTaggedString('', '');
$typed4 = new TypedValue('', '');
$this->assertFalse($string4->equals($typed4), 's4 == t4');
$this->assertFalse($typed4->equals($string4), 's4 == t4');
}
}
|