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 
0011 class SchemaEntryTest extends PHPUnit\Framework\TestCase
0012 {
0013     public function dataTableName_data()
0014     {
0015         return [
0016             'normal' => [ 'foo', 'pd2_org_kde_testproduct__foo' ],
0017             'dot' => [ 'my.value', 'pd2_org_kde_testproduct__my_value' ],
0018             'uppercase' => [ 'UPPER', 'pd2_org_kde_testproduct__upper' ]
0019         ];
0020     }
0021 
0022     /** @dataProvider dataTableName_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 = $input;
0029         $this->assertEquals($output, $se->dataTableName());
0030     }
0031 
0032     public function invalidJson_data()
0033     {
0034         return [
0035             'empty' => [ '{}' ],
0036             'empty name' => [ '{ "name": "", "type": "scalar", "aggregationType": "none" }' ],
0037             'empty type' => [ '{ "name": "foo", "type": "", "aggregationType": "none" }' ],
0038             'invalid type' => [ '{ "name": "foo", "type": "bla", "aggregationType": "none" }' ],
0039             'invalid name' => [ '{ "name": " foo ", "type": "scalar", "aggregationType": "none" }' ],
0040             'invalid name 2' => [ '{ "name": "1foo ", "type": "scalar", "aggregationType": "none" }' ]
0041         ];
0042     }
0043 
0044     /**
0045      * @dataProvider invalidJson_data
0046      */
0047     public function testInvalidJson($input)
0048     {
0049         $this->expectException(RESTException::class);
0050         $this->expectExceptionCode(400);
0051         $p = new Product;
0052         $se = SchemaEntry::fromJson(json_decode('[ ' . $input . ' ]'), $p);
0053     }
0054 }
0055