/**
  * @dataProvider settingHeadersDataProvider
  */
 public function testOperatingOnHeaders($replace, $headerValues)
 {
     $headersNum = count($headerValues);
     foreach ($headerValues as $value) {
         $this->object->setHeader(self::TEST_HEADER_NAME, $value, $replace);
     }
     $header = $this->object->getHeader(self::TEST_HEADER_NAME);
     if ($replace) {
         $this->assertEquals(1, count($this->object->getHeaders()));
         $this->assertEquals(1, count($header));
         $this->assertEquals(self::TEST_HEADER_VALUE2, $header[0]['value']);
     } else {
         $this->assertEquals($headersNum, count($this->object->getHeaders()));
         $this->assertEquals($headersNum, count($header));
         $i = 0;
         foreach ($headerValues as $value) {
             $this->assertEquals($value, $header[$i]['value']);
             $i++;
         }
     }
     // there is one additional header to be send, content-type
     $headersNum = $replace ? 2 : $headersNum + 1;
     $this->object->expects($this->exactly($headersNum))->method('sendHeader');
     $this->object->sendHeaders();
 }
 /**
  * @dataProvider cachingHeadersProvider
  */
 public function testCachingHeaders($varnishTTL, $clientTTL, $cachingPolicy, $expectedValue, $passExpectedValue)
 {
     $this->object->setCachePolicy($cachingPolicy);
     $this->object->setCacheValidity($varnishTTL, $clientTTL);
     $cacheControlValue = $this->object->getHeader('Cache-Control')[0]['value'];
     $passCacheControlValue = $this->object->getHeader('X-Pass-Cache-Control')[0]['value'];
     $this->assertEquals($expectedValue, $cacheControlValue, 'Cache-Control header should match the expected value');
     $this->assertEquals($passExpectedValue, $passCacheControlValue, 'X-Pass-Cache-Control header should match the expected value');
 }
 /**
  * This method sets all configured CORS related headers
  *
  * @param WikiaResponse $response response object to set headers to
  * @param bool $mergeExisting
  */
 public function setHeaders(WikiaResponse $response, $mergeExisting = true)
 {
     foreach ($this->allowValues as $headerName => $values) {
         if (!empty($values)) {
             $valuesToSet = $values;
             $headers = $response->getHeader($headerName);
             if (!empty($headers) && $mergeExisting) {
                 $response->removeHeader($headerName);
                 foreach ($headers as $header) {
                     $valuesToSet = array_merge($valuesToSet, explode(self::HEADER_DELIMETER, $header['value']));
                 }
             }
             $response->setHeader($headerName, implode(self::HEADER_DELIMETER, $valuesToSet));
         }
     }
     return $this;
 }