Browse Source

More tests

master
J. King 4 years ago
parent
commit
befaa2f3e4
  1. 10
      lib/Date.php
  2. 9
      tests/cases/JSON/JSONTest.php
  3. 117
      tests/cases/JSON/entry.json

10
lib/Date.php

@ -25,7 +25,6 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
'Y-m-d\tH:i:s\z',
'Y-m-d\tH:i:sO',
'Y-m-d\tH:i:sP',
// space instead of T
'Y-m-d H:i:s.u\Z',
'Y-m-d H:i:s.u\z',
'Y-m-d H:i:s.uO',
@ -51,7 +50,6 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
'Y-m-d\tH:i:s \z',
'Y-m-d\tH:i:s O',
'Y-m-d\tH:i:s P',
// space instead of T and space before timezone offset
'Y-m-d H:i:s.u \Z',
'Y-m-d H:i:s.u \z',
'Y-m-d H:i:s.u O',
@ -70,15 +68,23 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
'Y-m-d H:i:s P',
// HTTP format (and similar)
'D, d M Y H:i:s.u \G\M\T',
'D, d M Y H:i:s.u \U\T\C',
'D, d M Y H:i:s.u \U\T',
'D, d M Y H:i:s.u \Z',
'D, d M Y H:i:s.u O',
'D, d M Y H:i:s.u P',
'D, d M Y H:i:s.u\Z',
'D, d M Y H:i:s.uO',
'D, d M Y H:i:s.uP',
'D, d M Y H:i:s \G\M\T',
'D, d M Y H:i:s \U\T\C',
'D, d M Y H:i:s \U\T',
'D, d M Y H:i:s \Z',
'D, d M Y H:i:s O',
'D, d M Y H:i:s P',
'D, d M Y H:i:s\Z',
'D, d M Y H:i:sO',
'D, d M Y H:i:sP',
// HTTP obsolete format
'D M j H:i:s.u Y',
'D M j H:i:s Y',

9
tests/cases/JSON/JSONTest.php

@ -40,6 +40,7 @@ use JKingWeb\Lax\Person\Person;
use JKingWeb\Lax\Category\Category;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
use JKingWeb\Lax\Date;
use JKingWeb\Lax\Feed;
use JKingWeb\Lax\Entry;
use JKingWeb\Lax\Text;
@ -119,8 +120,16 @@ class JSONTest extends \PHPUnit\Framework\TestCase {
foreach ($entry as $k => $v) {
if (in_array($k, ["link", "relatedLink", "banner"])) {
$e->$k = new Url($v);
} elseif (in_array($k, ["dateCreated", "dateModified"])) {
$e->$k = new Date($v, new \DateTimeZone("UTC"));
} elseif (in_array($k, ["title", "summary", "content"])) {
$e->$k = $this->makeText($v);
} elseif ($k === "people") {
$c = new PersonCollection;
foreach ($v as $m) {
$c[] = $this->makePerson($m);
}
$e->$k = $c;
} elseif ($k === "categories") {
$c = new CategoryCollection;
foreach ($v as $m) {

117
tests/cases/JSON/entry.json

@ -238,6 +238,76 @@
]
}
},
{
"description": "Entry dates",
"input": {
"version": "https://jsonfeed.org/version/1",
"items": [
{
"id": "1",
"date_published": "2020-03-03T21:12:42Z",
"date_modified": "2020-03-03T21:12:42Z"
}
]
},
"output": {
"format": "json",
"version": "1",
"entries": [
{
"id": "1",
"dateCreated": "2020-03-03T21:12:42Z",
"dateModified": "2020-03-03T21:12:42Z"
}
]
}
},
{
"description": "Entry URLs",
"input": {
"version": "https://jsonfeed.org/version/1",
"items": [
{
"id": "1",
"url": "http://example.com/",
"external_url": "http://example.org/"
}
]
},
"output": {
"format": "json",
"version": "1",
"entries": [
{
"id": "1",
"link": "http://example.com/",
"relatedLink": "http://example.org/"
}
]
}
},
{
"description": "Entry title",
"input": {
"version": "https://jsonfeed.org/version/1",
"items": [
{
"id": "1",
"title": "Example title"
}
]
},
"output": {
"format": "json",
"version": "1",
"entries": [
{
"id": "1",
"title": "Example title"
}
]
}
},
{
"description": "Entry summary",
"input": {
@ -360,5 +430,52 @@
}
]
}
},
{
"description": "Entry authors",
"input": {
"version": "https://jsonfeed.org/version/1",
"authors": [
{"name": "Jane Doe"},
{"name": "John Doe"}
],
"items": [
{
"id": 1,
"author": {"name": "John Doe"},
"authors": [{"name": "Jane Doe"}]
},
{
"id": 2,
"author": {"name": "John Doe"}
},
{
"id": 3,
"authors": [{"name": "Jane Doe"}]
},
{
"id": 4
},
{
"id": 5,
"authors": [{"NAME": "Jane Doe"}]
}
]
},
"output": {
"format": "json",
"version": "1",
"people": [
{"name": "Jane Doe", "role": "author"},
{"name": "John Doe", "role": "author"}
],
"entries": [
{"id": "1", "people": [{"name": "Jane Doe", "role": "author"}]},
{"id": "2", "people": [{"name": "John Doe", "role": "author"}]},
{"id": "3", "people": [{"name": "Jane Doe", "role": "author"}]},
{"id": "4", "people": [{"name": "Jane Doe", "role": "author"},{"name": "John Doe", "role": "author"}]},
{"id": "5", "people": [{"name": "Jane Doe", "role": "author"},{"name": "John Doe", "role": "author"}]}
]
}
}
]
Loading…
Cancel
Save