<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* JsonLD utility test class
*/
class JsonLDTest extends TestCase
-{
+{
public function testFetchElementArrayNotFound()
{
$object = [];
$data = JsonLD::fetchElementArray($object, 'field');
- $this->assertNull($data);
+ self::assertNull($data);
}
public function testFetchElementArrayFoundEmptyArray()
$object = ['field' => []];
$data = JsonLD::fetchElementArray($object, 'field');
- $this->assertSame([[]], $data);
+ self::assertSame([[]], $data);
}
public function testFetchElementArrayFoundID()
$object = ['field' => ['value1', ['@id' => 'value2'], ['@id' => 'value3']]];
$data = JsonLD::fetchElementArray($object, 'field', '@id');
- $this->assertSame(['value1', 'value2', 'value3'], $data);
+ self::assertSame(['value1', 'value2', 'value3'], $data);
}
public function testFetchElementArrayFoundID2()
'value3', ['@id' => 'value4', 'subfield42' => 'value42']]];
$data = JsonLD::fetchElementArray($object, 'field', '@id');
- $this->assertSame(['value3', 'value4'], $data);
+ self::assertSame(['value3', 'value4'], $data);
}
+
public function testFetchElementArrayFoundArrays()
{
$object = ['field' => [['subfield11' => 'value11', 'subfield12' => 'value12'],
['subfield21' => 'value21', 'subfield22' => 'value22']];
$data = JsonLD::fetchElementArray($object, 'field');
- $this->assertSame($expect, $data);
+ self::assertSame($expect, $data);
+ }
+
+ public function testFetchElementArrayTypeValue()
+ {
+ $object = ['field' => [['subfield11' => 'value11', 'subfield12' => 'value12'],
+ ['subfield21' => 'value21', 'subfield22' => 'value22']]];
+
+ $expect = [['subfield11' => 'value11', 'subfield12' => 'value12']];
+
+ $data = JsonLD::fetchElementArray($object, 'field', null, 'subfield11', 'value11');
+ self::assertSame($expect, $data);
}
public function testFetchElementNotFound()
$object = [];
$data = JsonLD::fetchElement($object, 'field');
- $this->assertNull($data);
+ self::assertNull($data);
}
public function testFetchElementFound()
$object = ['field' => 'value'];
$data = JsonLD::fetchElement($object, 'field');
- $this->assertSame('value', $data);
+ self::assertSame('value', $data);
}
public function testFetchElementFoundEmptyString()
$object = ['field' => ''];
$data = JsonLD::fetchElement($object, 'field');
- $this->assertSame('', $data);
+ self::assertSame('', $data);
}
public function testFetchElementKeyFoundEmptyArray()
$object = ['field' => ['content' => []]];
$data = JsonLD::fetchElement($object, 'field', 'content');
- $this->assertSame([], $data);
+ self::assertSame([], $data);
}
public function testFetchElementFoundID()
$object = ['field' => ['field2' => 'value2', '@id' => 'value', 'field3' => 'value3']];
$data = JsonLD::fetchElement($object, 'field');
- $this->assertSame('value', $data);
+ self::assertSame('value', $data);
}
public function testFetchElementType()
$object = ['source' => ['content' => 'body', 'mediaType' => 'text/bbcode']];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/bbcode');
- $this->assertSame('body', $data);
+ self::assertSame('body', $data);
}
public function testFetchElementTypeValueNotFound()
$object = ['source' => ['content' => 'body', 'mediaType' => 'text/html']];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/bbcode');
- $this->assertNull($data);
+ self::assertNull($data);
}
public function testFetchElementTypeNotFound()
$object = ['source' => ['content' => 'body', 'mediaType' => 'text/html']];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType2', 'text/html');
- $this->assertNull($data);
+ self::assertNull($data);
}
public function testFetchElementKeyWithoutType()
$object = ['source' => ['content' => 'body', 'mediaType' => 'text/bbcode']];
$data = JsonLD::fetchElement($object, 'source', 'content');
- $this->assertSame('body', $data);
+ self::assertSame('body', $data);
}
public function testFetchElementTypeArray()
['content' => 'body', 'mediaType' => 'text/bbcode']]];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/bbcode');
- $this->assertSame('body', $data);
+ self::assertSame('body', $data);
}
public function testFetchElementTypeValueArrayNotFound()
['content' => 'body', 'mediaType' => 'text/bbcode']]];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/markdown');
- $this->assertNull($data);
+ self::assertNull($data);
}
public function testFetchElementTypeArrayNotFound()
['content' => 'body', 'mediaType' => 'text/bbcode']]];
$data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType2', 'text/bbcode');
- $this->assertNull($data);
+ self::assertNull($data);
}
}