Jamie (Bear) Murphy 5a78c2af89 Update PHP.mjs
2025-05-13 22:32:32 +01:00

81 lines
2.3 KiB
JavaScript
Raw Blame History

/**
* PHP tests.
*
* @author Jarmo van Lenthe
*
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "PHP Deserialize empty array",
input: "a:0:{}",
expectedOutput: "{}",
recipeConfig: [
{
op: "PHP Deserialize",
args: [true],
},
],
},
{
name: "PHP Deserialize integer",
input: "i:10;",
expectedOutput: "10",
recipeConfig: [
{
op: "PHP Deserialize",
args: [true],
},
],
},
{
name: "PHP Deserialize string",
input: "s:17:\"PHP Serialization\";",
expectedOutput: "\"PHP Serialization\"",
recipeConfig: [
{
op: "PHP Deserialize",
args: [true],
},
],
},
{
name: "PHP Deserialize array (JSON)",
input: "a:2:{s:1:\"a\";i:10;i:0;a:1:{s:2:\"ab\";b:1;}}",
expectedOutput: '{"0":{"ab":true},"a":10}',
recipeConfig: [
{
op: "PHP Deserialize",
args: [true],
},
],
},
{
name: "PHP Deserialize array (non-JSON)",
input: "a:2:{s:1:\"a\";i:10;i:0;a:1:{s:2:\"ab\";b:1;}}",
expectedOutput: '{0:{"ab":true},"a":10}',
recipeConfig: [
{
op: "PHP Deserialize",
args: [false],
},
],
},
{
name: "PHP Deserialize array with object and reference",
input: 'a:1:{s:6:"navbar";O:18:"APP\View\Menu\Item":3:{s:7:"<22>*<2A>name";s:16:"Secondary Navbar";s:11:"<22>*<2A>children";a:1:{s:9:"View Cart";O:18:"APP\View\Menu\Item":2:{s:7:"<22>*<2A>name";s:9:"View Cart";s:9:"<22>*<2A>parent";r:2;}}s:9:"<22>*<2A>parent";N;}}',
// eslint-disable-next-line no-useless-escape
expectedOutput: '{"navbar":{"__className":"APP\\View\\Menu\\Item","<22>*<2A>name":"Secondary Navbar","<22>*<2A>children":{"View Cart":{"__className":"APP\\View\\Menu\\Item","<22>*<2A>name":"View Cart","<22>*<2A>parent":"Secondary Navbar"}},"<22>*<2A>parent":null}}',
recipeConfig: [
{
op: "PHP Deserialize",
args: [false],
},
],
}
]);