[TASK] Make WidgetRequestBuilderTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / WidgetRequestBuilder.php
index a858bd0..92c0f3c 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types=1);
 namespace TYPO3\CMS\Fluid\Core\Widget;
 
 /*
@@ -15,21 +16,23 @@ namespace TYPO3\CMS\Fluid\Core\Widget;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\RequestInterface;
+use TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder;
 
 /**
  * Builds the WidgetRequest if an AJAX widget is called.
  */
-class WidgetRequestBuilder extends \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder
+class WidgetRequestBuilder extends RequestBuilder
 {
     /**
-     * @var \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder
+     * @var AjaxWidgetContextHolder
      */
     private $ajaxWidgetContextHolder;
 
     /**
-     * @param \TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder $ajaxWidgetContextHolder
+     * @param AjaxWidgetContextHolder $ajaxWidgetContextHolder
      */
-    public function injectAjaxWidgetContextHolder(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder $ajaxWidgetContextHolder)
+    public function injectAjaxWidgetContextHolder(AjaxWidgetContextHolder $ajaxWidgetContextHolder)
     {
         $this->ajaxWidgetContextHolder = $ajaxWidgetContextHolder;
     }
@@ -37,11 +40,11 @@ class WidgetRequestBuilder extends \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder
     /**
      * Builds a widget request object from the raw HTTP information
      *
-     * @return \TYPO3\CMS\Fluid\Core\Widget\WidgetRequest The widget request as an object
+     * @return RequestInterface The widget request as an object
      */
-    public function build()
+    public function build(): RequestInterface
     {
-        $request = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class);
+        $request = $this->objectManager->get(WidgetRequest::class);
         $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
         $request->setBaseUri(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
         $request->setMethod($_SERVER['REQUEST_METHOD'] ?? null);
@@ -54,6 +57,13 @@ class WidgetRequestBuilder extends \TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder
         if (isset($rawGetArguments['action'])) {
             $request->setControllerActionName($rawGetArguments['action']);
         }
+        if (!isset($rawGetArguments['fluid-widget-id'])) {
+            // Low level test, WidgetRequestHandler returns false in canHandleRequest () if this is not set
+            throw new \InvalidArgumentException(
+                'No Fluid Widget ID was given.',
+                1521190675
+            );
+        }
         $widgetContext = $this->ajaxWidgetContextHolder->get($rawGetArguments['fluid-widget-id']);
         $request->setWidgetContext($widgetContext);
         return $request;