/**
  * Iterate over all sets of data and test the rewriting
  *
  * @param string $testDataSet The dataset to test against
  *
  * @return boolean
  * @throws \Exception
  */
 public function assertionEngine($testDataSet)
 {
     // Do we know this dataset?
     $this->assertArrayHasKey($testDataSet, $this->rewriteDataSets);
     // Get our dataset
     $dataSet = $this->rewriteDataSets[$testDataSet];
     // We will get the rules into our module by ways of the volatile rewrites
     $this->mockRequestContext->setModuleVar(ModuleVars::VOLATILE_REWRITES, $dataSet['rules']);
     // No iterate over the map which is combined with the rules in the dataset
     foreach ($dataSet['map'] as $input => $desiredOutput) {
         // We will provide the crucial information by way of server vars
         $this->mockRequestContext->setServerVar(ServerVars::X_REQUEST_URI, $input);
         // Start the processing
         $this->rewriteModule->process($this->request, $this->response, $this->mockRequestContext, ModuleHooks::REQUEST_POST);
         // If we got a redirect we have to test differently
         if (isset($dataSet['redirect'])) {
             try {
                 // Has the header location been set at all?
                 // If we did not match any redirect condition and will set it to the input so we get some output
                 if (!$this->response->hasHeader(Protocol::HEADER_LOCATION)) {
                     $this->response->addHeader(Protocol::HEADER_LOCATION, $input);
                 }
                 // Asserting that the header location was set correctly
                 $this->assertSame($desiredOutput, $this->response->getHeader(Protocol::HEADER_LOCATION));
                 // If we got a custom status code we have to check for it
                 if (isset($dataSet['redirectAs'])) {
                     $this->assertSame($dataSet['redirectAs'], (int) $this->response->getStatusCode());
                 }
             } catch (\Exception $e) {
                 // Do not forget to reset the response object we are using!!
                 $this->response = new HttpResponse();
                 $this->response->init();
                 // Re-throw the exception
                 throw $e;
             }
         } else {
             // Now check if we got the same thing here
             $this->assertSame($desiredOutput, $this->mockRequestContext->getServerVar(ServerVars::X_REQUEST_URI));
         }
     }
     // Still here? Then we are successful
     return true;
 }
 /**
  * Tests the fillContextBackreferences() method
  *
  * @return void
  */
 public function testFillContextBackreferences()
 {
     // Get the objects we need
     $rewriteModule = new MockRewriteModule();
     $request = new HttpRequest();
     $response = new HttpResponse();
     $mockRequestContext = new MockRequestContext();
     $mockRequestContext->setServerVar(ServerVars::DOCUMENT_ROOT, $this->documentRoot);
     // Do the thing
     $mockRequestContext->setEnvVar(EnvVars::HTTPS, 'test');
     $rewriteModule->setRequestContext($mockRequestContext);
     $rewriteModule->fillContextBackreferences();
     $this->assertEquals('test', $rewriteModule->getServerBackreferences()['$' . EnvVars::HTTPS]);
 }
 /**
  * Test for the correct setup of the SCRIPT_FILENAME server var after call to populateRequestContext
  *
  * @param string  $requestUri             The request URI teh context population is based on
  * @param boolean $isValidPath            Whether or not the script filename actually exists
  * @param string  $expectedScriptFilename The expected value of the SCRIPT_FILENAME server var
  *
  * @return void
  *
  * @dataProvider populateRequestContextScriptFilenameDataProvider
  */
 public function testPopulateRequestContextScriptFilename($requestUri, $isValidPath, $expectedScriptFilename = '')
 {
     // get a mock server context
     $serverContext = $this->getMock('\\AppserverIo\\Server\\Interfaces\\ServerContextInterface');
     $serverContext->expects($this->atLeast(1))->method('getServerConfig')->will($this->returnValue($this->getMock('\\AppserverIo\\Server\\Interfaces\\ServerConfigurationInterface')));
     $this->module->init($serverContext);
     // get a mock request context and prepare it with our request URI
     $requestContext = new MockRequestContext();
     $requestContext->setServerVar(ServerVars::X_REQUEST_URI, $requestUri);
     $requestContext->setServerVar(ServerVars::DOCUMENT_ROOT, $this->documentRoot);
     // populate the request context and test for the population result
     $this->module->populateRequestContext($requestContext);
     if ($isValidPath) {
         $this->assertTrue($requestContext->hasServerVar(ServerVars::SCRIPT_FILENAME), 'Server var SCRIPT_FILENAME has not been set');
         $this->assertSame($this->documentRoot . $expectedScriptFilename, $requestContext->getServerVar(ServerVars::SCRIPT_FILENAME));
     } else {
         $this->assertFalse($requestContext->hasServerVar(ServerVars::SCRIPT_FILENAME), 'Server var SCRIPT_FILENAME has falsely been set');
     }
 }