Make WordPress Core


Ignore:
Timestamp:
09/26/2020 06:18:53 PM (6 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support the minProperties and maxProperties JSON Schema keywords.

Props yakimun.
Fixes #51023.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php

    r49008 r49053  
    838838
    839839        /**
     840         * @ticket 51023
     841         */
     842        public function test_object_min_properties() {
     843                $schema = array(
     844                        'type'          => 'object',
     845                        'minProperties' => 1,
     846                );
     847
     848                $this->assertTrue(
     849                        rest_validate_value_from_schema(
     850                                array(
     851                                        'propA' => 'a',
     852                                        'propB' => 'b',
     853                                ),
     854                                $schema
     855                        )
     856                );
     857                $this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) );
     858                $this->assertWPError( rest_validate_value_from_schema( array(), $schema ) );
     859                $this->assertWPError( rest_validate_value_from_schema( '', $schema ) );
     860        }
     861
     862        /**
     863         * @ticket 51023
     864         */
     865        public function test_object_max_properties() {
     866                $schema = array(
     867                        'type'          => 'object',
     868                        'maxProperties' => 2,
     869                );
     870
     871                $this->assertTrue( rest_validate_value_from_schema( array( 'propA' => 'a' ), $schema ) );
     872                $this->assertTrue(
     873                        rest_validate_value_from_schema(
     874                                array(
     875                                        'propA' => 'a',
     876                                        'propB' => 'b',
     877                                ),
     878                                $schema
     879                        )
     880                );
     881                $this->assertWPError(
     882                        rest_validate_value_from_schema(
     883                                array(
     884                                        'propA' => 'a',
     885                                        'propB' => 'b',
     886                                        'propC' => 'c',
     887                                ),
     888                                $schema
     889                        )
     890                );
     891                $this->assertWPError( rest_validate_value_from_schema( 'foobar', $schema ) );
     892        }
     893
     894        /**
    840895         * @ticket 44949
    841896         */
Note: See TracChangeset for help on using the changeset viewer.