File indexing completed on 2024-12-22 03:47:06

0001 <?php
0002 /*
0003     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0004 
0005     SPDX-License-Identifier: MIT
0006 */
0007 
0008 require_once('../src/server/shared/product.php');
0009 require_once('../src/server/shared/schemaentry.php');
0010 require_once('../src/server/shared/schemaentryelement.php');
0011 
0012 class SchemaEntryElementTest extends PHPUnit\Framework\TestCase
0013 {
0014     public static function dataColumnName_data()
0015     {
0016         return [
0017             'normal' => [ 'foo', 'col_data_entry_foo' ],
0018             'dot' => [ 'my.value', 'col_data_entry_my_value' ]
0019         ];
0020     }
0021 
0022     /** @dataProvider dataColumnName_data */
0023     public function testDataTableName($input, $output)
0024     {
0025         $p = new Product;
0026         $p->name = 'org.kde.TestProduct';
0027         $se = new SchemaEntry($p);
0028         $se->name = 'entry';
0029         $see = new SchemaEntryElement($se);
0030         $see->name = $input;
0031         $this->assertEquals($output, $see->dataColumnName());
0032     }
0033 
0034     public static function invalidJson_data()
0035     {
0036         return [
0037             'empty' => [ '{}' ],
0038             'empty name' => [ '{ "name": "", "type": "string" }' ],
0039             'empty type' => [ '{ "name": "foo", "type": "" }' ],
0040             'invalid type' => [ '{ "name": "foo", "type": "bla" }' ],
0041             'invalid name' => [ '{ "name": " foo ", "type": "string" }' ],
0042             'invalid name 2' => [ '{ "name": "1foo ", "type": "string" }' ]
0043         ];
0044     }
0045 
0046     /**
0047      * @dataProvider invalidJson_data
0048      */
0049     public function testInvalidJson($input)
0050     {
0051         $this->expectException(RESTException::class);
0052         $this->expectExceptionCode(400);
0053         $p = new Product;
0054         $se = new SchemaEntry($p);
0055         SchemaEntryElement::fromJson(json_decode('[ ' . $input . ' ]'), $se);
0056     }
0057 }