[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / components / testing_framework / core / Functional / Framework / Frontend / Response.php
1 <?php
2 namespace TYPO3\CMS\Components\TestingFramework\Core\Functional\Framework\Frontend;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Model of frontend response
19 */
20 class Response
21 {
22 const STATUS_Success = 'success';
23 const STATUS_Failure = 'failure';
24
25 /**
26 * @var string
27 */
28 protected $status;
29
30 /**
31 * @var NULL|string|array
32 */
33 protected $content;
34
35 /**
36 * @var string
37 */
38 protected $error;
39
40 /**
41 * @var ResponseContent
42 */
43 protected $responseSection;
44
45 /**
46 * @param string $status
47 * @param string $content
48 * @param string $error
49 */
50 public function __construct($status, $content, $error)
51 {
52 $this->status = $status;
53 $this->content = $content;
54 $this->error = $error;
55 }
56
57 /**
58 * @return string
59 */
60 public function getStatus()
61 {
62 return $this->status;
63 }
64
65 /**
66 * @return array|NULL|string
67 */
68 public function getContent()
69 {
70 return $this->content;
71 }
72
73 /**
74 * @return string
75 */
76 public function getError()
77 {
78 return $this->error;
79 }
80
81 /**
82 * @return ResponseContent
83 */
84 public function getResponseContent()
85 {
86 if (!isset($this->responseContent)) {
87 $this->responseContent = new ResponseContent($this);
88 }
89 return $this->responseContent;
90 }
91
92 /**
93 * @param mixed $sectionIdentifiers
94 * @return NULL|array|ResponseSection[]
95 */
96 public function getResponseSections(...$sectionIdentifiers)
97 {
98 if (empty($sectionIdentifiers)) {
99 $sectionIdentifiers = ['Default'];
100 }
101
102 $sections = [];
103 foreach ($sectionIdentifiers as $sectionIdentifier) {
104 $sections[] = $this->getResponseContent()->getSection($sectionIdentifier);
105 }
106
107 return $sections;
108 }
109 }