| @@ 59-82 (lines=24) @@ | ||
| 56 | * @expectedException Sensorario\Resources\Exceptions\NotAllowedKeyException |
|
| 57 | * @expectedExceptionMessageRegExp #Key `.*::.*` is not allowed# |
|
| 58 | */ |
|
| 59 | public function testNotAllowedFieldThroghRuntimeException() |
|
| 60 | { |
|
| 61 | $configurator = new Configurator( |
|
| 62 | 'empty_resource', |
|
| 63 | new Container([ |
|
| 64 | 'resources' => [ |
|
| 65 | 'empty_resource' => [ |
|
| 66 | 'constraints' => [ |
|
| 67 | 'allowedValues' => [ |
|
| 68 | 'name', |
|
| 69 | 'surname', |
|
| 70 | ], |
|
| 71 | ], |
|
| 72 | ], |
|
| 73 | ], |
|
| 74 | ]) |
|
| 75 | ); |
|
| 76 | ||
| 77 | $resource = Resource::box([ |
|
| 78 | 'name' => 'Simone', |
|
| 79 | 'surname' => 'Gentili', |
|
| 80 | 'not allowed' => 'foo', |
|
| 81 | ], $configurator); |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * @expectedException Sensorario\Resources\Exceptions\PropertyException |
|
| @@ 525-552 (lines=28) @@ | ||
| 522 | * @expectedException Sensorario\Resources\Exceptions\UnexpectedValueException |
|
| 523 | * @expectedExceptionMessageRegExp #Value `.*` is not allowed for key `.*`. Allowed values are:# |
|
| 524 | */ |
|
| 525 | public function testAllowedValues() |
|
| 526 | { |
|
| 527 | $configurator = new Configurator( |
|
| 528 | 'foo', |
|
| 529 | new Container([ |
|
| 530 | 'resources' => [ |
|
| 531 | 'foo' => [ |
|
| 532 | 'constraints' => [ |
|
| 533 | 'allowed' => [ 'user_type' ], |
|
| 534 | 'allowedValues' => [ |
|
| 535 | 'user_type' => [ |
|
| 536 | 4, |
|
| 537 | 7, |
|
| 538 | ], |
|
| 539 | ], |
|
| 540 | ], |
|
| 541 | ], |
|
| 542 | ], |
|
| 543 | ]) |
|
| 544 | ); |
|
| 545 | ||
| 546 | $properties = [ 'user_type' => 3 ]; |
|
| 547 | ||
| 548 | Resource::box( |
|
| 549 | $properties, |
|
| 550 | $configurator |
|
| 551 | ); |
|
| 552 | } |
|
| 553 | ||
| 554 | public function testRewriteRulesWithCondition() |
|
| 555 | { |
|
| @@ 611-638 (lines=28) @@ | ||
| 608 | * @expectedException Sensorario\Resources\Exceptions\OutOfRangeException |
|
| 609 | * @expectedExceptionMessageRegExp #Value `.*` is out of range: `.*`.# |
|
| 610 | */ |
|
| 611 | public function testAcceptRangeOfValues() |
|
| 612 | { |
|
| 613 | $configurator = new Configurator( |
|
| 614 | 'foo', |
|
| 615 | new Container([ |
|
| 616 | 'resources' => [ |
|
| 617 | 'foo' => [ |
|
| 618 | 'constraints' => [ |
|
| 619 | 'allowedRanges' => [ |
|
| 620 | 'age' => [ |
|
| 621 | 'more_than' => 3, |
|
| 622 | 'less_than' => 42, |
|
| 623 | ], |
|
| 624 | ], |
|
| 625 | 'allowed' => [ |
|
| 626 | 'age' |
|
| 627 | ], |
|
| 628 | ], |
|
| 629 | ], |
|
| 630 | ], |
|
| 631 | ]) |
|
| 632 | ); |
|
| 633 | ||
| 634 | Resource::box( |
|
| 635 | [ 'age' => 2 ], |
|
| 636 | $configurator |
|
| 637 | ); |
|
| 638 | } |
|
| 639 | ||
| 640 | public function testAllResourcesInheritGlobalAllowingConfiguration() |
|
| 641 | { |
|
| @@ 899-924 (lines=26) @@ | ||
| 896 | * @expectedException \Sensorario\Resources\Exceptions\InvalidCustomValidatorException |
|
| 897 | * @expectedExceptionMessage Oops! `custom-validator` custom validator is not available. Only email is. |
|
| 898 | */ |
|
| 899 | public function testDenyCustomValidatorDifferentFromEmail() |
|
| 900 | { |
|
| 901 | $configurator = new Configurator( |
|
| 902 | 'foo', |
|
| 903 | new Container([ |
|
| 904 | 'resources' => [ |
|
| 905 | 'foo' => [ |
|
| 906 | 'constraints' => [ |
|
| 907 | 'allowed' => [ |
|
| 908 | 'property_name', |
|
| 909 | ], |
|
| 910 | 'rules' => [ |
|
| 911 | 'property_name' => [ |
|
| 912 | 'custom-validator' => 'foo', |
|
| 913 | ] |
|
| 914 | ] |
|
| 915 | ], |
|
| 916 | ], |
|
| 917 | ] |
|
| 918 | ]) |
|
| 919 | ); |
|
| 920 | ||
| 921 | Resource::box([ |
|
| 922 | 'property_name' => '42', |
|
| 923 | ], $configurator); |
|
| 924 | } |
|
| 925 | ||
| 926 | } |
|
| 927 | ||