public function testCookiesAreNotAddedWhenParamIsSet()
 {
     $jar = new ArrayCookieJar();
     $plugin = new CookiePlugin($jar);
     $jar->add(new Cookie(array('domain' => 'example.com', 'path' => '/', 'name' => 'test', 'value' => 'hi', 'expires' => time() + 3600)));
     $client = new Client('http://example.com');
     $client->getEventDispatcher()->addSubscriber($plugin);
     // Ensure that it is normally added
     $request = $client->get();
     $request->setResponse(new Response(200), true);
     $request->send();
     $this->assertEquals('hi', $request->getCookie('test'));
     // Now ensure that it is not added
     $request = $client->get();
     $request->getParams()->set('cookies.disable', true);
     $request->setResponse(new Response(200), true);
     $request->send();
     $this->assertNull($request->getCookie('test'));
 }
 public function testRemoveExistingCookieIfEmpty()
 {
     // Add a cookie that should not be affected
     $a = new Cookie(array('name' => 'foo', 'value' => 'nope', 'domain' => 'foo.com', 'path' => '/abc'));
     $this->jar->add($a);
     $data = array('name' => 'foo', 'value' => 'bar', 'domain' => 'foo.com', 'path' => '/');
     $b = new Cookie($data);
     $this->assertTrue($this->jar->add($b));
     $this->assertEquals(2, count($this->jar));
     // Try to re-set the same cookie with no value: assert that cookie is not added
     $data['value'] = null;
     $this->assertFalse($this->jar->add(new Cookie($data)));
     // assert that original cookie has been deleted
     $cookies = $this->jar->all('foo.com');
     $this->assertTrue(in_array($a, $cookies, true));
     $this->assertFalse(in_array($b, $cookies, true));
     $this->assertEquals(1, count($this->jar));
 }
 /**
  * @expectedException \Guzzle\Plugin\Cookie\Exception\InvalidCookieException
  * @expectedExceptionMessage The cookie name must not contain invalid characters: abc:@123
  */
 public function testThrowsExceptionWithStrictMode()
 {
     $a = new ArrayCookieJar();
     $a->setStrictMode(true);
     $a->add(new Cookie(array('name' => 'abc:@123', 'value' => 'foo', 'domain' => 'bar')));
 }
 /**
  * Send data
  *
  * @param \SimpleXMLElement $data Data
  *
  * @access public
  * @return RedirectResponse
  */
 public function sendData($data)
 {
     $implementation = new \DOMImplementation();
     $dtd = $implementation->createDocumentType('paymentService', '-//WorldPay//DTD WorldPay PaymentService v1//EN', 'http://dtd.worldpay.com/paymentService_v1.dtd');
     $document = $implementation->createDocument(null, '', $dtd);
     $document->encoding = 'utf-8';
     $node = $document->importNode(dom_import_simplexml($data), true);
     $document->appendChild($node);
     $authorisation = base64_encode($this->getMerchant() . ':' . $this->getPassword());
     $headers = array('Authorization' => 'Basic ' . $authorisation, 'Content-Type' => 'text/xml; charset=utf-8');
     $cookieJar = new ArrayCookieJar();
     $redirectCookie = $this->getRedirectCookie();
     if (!empty($redirectCookie)) {
         $url = parse_url($this->getEndpoint());
         $cookieJar->add(new Cookie(array('domain' => $url['host'], 'name' => 'machine', 'path' => '/', 'value' => $redirectCookie)));
     }
     $this->cookiePlugin = new CookiePlugin($cookieJar);
     $this->httpClient->addSubscriber($this->cookiePlugin);
     $xml = $document->saveXML();
     $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $xml)->send();
     return $this->response = new RedirectResponse($this, $httpResponse->getBody());
 }