ILIAS  release_7 Revision v7.30-3-g800a261c036
PostDataFromServerRequestTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../../../libs/composer/vendor/autoload.php");
6
7use \ILIAS\UI\Implementation\Component\Input\Container\Form\PostDataFromServerRequest;
8
9use Psr\Http\Message\ServerRequestInterface;
10use PHPUnit\Framework\TestCase;
11
12class PostDataFromServerRequestTest extends TestCase
13{
14 public function setUp() : void
15 {
16 $request = \Mockery::mock(ServerRequestInterface::class);
17 $request->shouldReceive("getParsedBody")->andReturn(["foo" => "bar"]);
18 $this->post_data = new PostDataFromServerRequest($request);
19 }
20
21
22 public function test_get_success()
23 {
24 $this->assertEquals("bar", $this->post_data->get("foo"));
25 }
26
27
28 public function test_get_fail()
29 {
30 $raised = false;
31 try {
32 $this->post_data->get("baz");
33 } catch (\LogicException $e) {
34 $raised = true;
35 }
36 $this->assertTrue($raised, "Logic exception was raised.");
37 }
38
39
40 public function test_getOr_match()
41 {
42 $this->assertEquals("bar", $this->post_data->getOr("foo", "baz"));
43 }
44
45
46 public function test_getOr_no_match()
47 {
48 $this->assertEquals("blaw", $this->post_data->getOr("baz", "blaw"));
49 }
50}
An exception for terminatinating execution or to throw for unit testing.
Implements interaction of input element with post data from psr-7 server request.