setAuth() public method

public setAuth ( $user, $password = '', $type = 'basic' )
 private function getXML($query, $mal = true, $account = null)
 {
     if ($mal) {
         $client = new Client();
         if (empty($account)) {
             $client->setAuth(ConnectDetails::$mal_username, ConnectDetails::$mal_password);
         } else {
             $client->setAuth($account["username"], $account["password"]);
         }
         $response = $client->request('GET', $this->mal_base_url . '' . $query);
         try {
             $xml = simplexml_load_string($response->html());
             return $xml;
         } catch (Exception $e) {
             $e->getMessage();
         }
     }
     return null;
 }
 public function testUsesAuth()
 {
     $guzzle = $this->getGuzzle();
     $client = new Client();
     $client->setClient($guzzle);
     $client->setAuth('me', '**');
     $crawler = $client->request('GET', 'http://www.example.com/');
     $request = $this->historyPlugin->getLastRequest();
     $this->assertEquals('me', $request->getUsername());
     $this->assertEquals('**', $request->getPassword());
 }
Beispiel #3
0
 public function testRestart()
 {
     $client = new Client();
     $client->setHeader('X-Test', 'test');
     $client->setAuth('foo', 'bar');
     $headersReflectionProperty = new \ReflectionProperty('Goutte\\Client', 'headers');
     $headersReflectionProperty->setAccessible(true);
     $this->assertEquals(array('X-Test' => 'test'), $headersReflectionProperty->getValue($client));
     $authReflectionProperty = new \ReflectionProperty('Goutte\\Client', 'auth');
     $authReflectionProperty->setAccessible(true);
     $this->assertEquals(array('foo', 'bar', 'basic'), $authReflectionProperty->getValue($client));
     $client->restart();
     $this->assertEquals([], $headersReflectionProperty->getValue($client));
     $this->assertNull($authReflectionProperty->getValue($client));
 }
Beispiel #4
0
 public function testResetsAuth()
 {
     $guzzle = $this->getGuzzle();
     $client = new Client();
     $client->setClient($guzzle);
     $client->setAuth('me', '**');
     $client->resetAuth();
     $crawler = $client->request('GET', 'http://www.example.com/');
     $request = $this->history->getLastRequest();
     $this->assertNull($request->getConfig()->get('auth')[0]);
     $this->assertNull($request->getConfig()->get('auth')[1]);
 }
Beispiel #5
0
 public function testResetsAuth()
 {
     $guzzle = $this->getGuzzle();
     $client = new Client();
     $client->setClient($guzzle);
     $client->setAuth('me', '**');
     $client->resetAuth();
     $client->request('GET', 'http://www.example.com/');
     $request = end($this->history)['request'];
     $this->assertEquals('', $request->getHeaderLine('authorization'));
 }