Esempio n. 1
0
 public function testOauth()
 {
     global $keys;
     // We can only do oauth if secret is present
     if (empty($keys->secret)) {
         $this->markTestSkipped('testOauth: Missing oAuth secret');
     }
     // oAuth test messes with trello object, create a new one for testing here
     $trello = new Trello($keys->key, $keys->secret);
     // Get an authorize URL (or true if we're already auth'd)
     $authorizeUrl = $trello->authorize(array('scope' => array('read' => true, 'write' => true, 'account' => true), 'redirect_uri' => 'http://127.0.0.1:23456', 'name' => 'php-trello Testing', 'expiration' => '1hour'), true);
     // Need to get authorized
     if ($authorizeUrl !== true) {
         $server = stream_socket_server('tcp://127.0.0.1:23456', $errno, $errmsg);
         if (!$server) {
             $this->markTestIncomplete("testOauth: Could not create a socket at 127.0.0.1:23456: {$errmsg}");
         }
         // Fire off the browser
         `xdg-open "{$authorizeUrl}" >/dev/null 2>&1 &`;
         //echo "Waiting for authorization from Trello...\n";
         $client = @stream_socket_accept($server, -1);
         if (!$client) {
             $this->markTestIncomplete('testOauth: Failed to receive Trello response.');
         }
         $query = fgets($client, 1024);
         // Received a response, let's send back a message
         $msg = "Please close this browser window and return to the test to continue.";
         fputs($client, "HTTP/1.1 200 OK\r\n");
         fputs($client, "Connection: close\r\n");
         fputs($client, "Content-Type: text/html; charset=UTF-8\r\n");
         fputs($client, "Content-Length: " . strlen($msg) . "\r\n\r\n");
         fputs($client, $msg);
         fclose($client);
         // Wait to continue the test until the browser returns.
         //readline("Press [Enter] to continue...");
         // Lets parse the query and pull out the oauth stuff
         if (!preg_match('~GET (.*?) HTTP~', $query, $match)) {
             $this->markTestIncomplete('testOauth: Could not read response from Trello.');
         }
         // Parse the query portion of the URL into the GET variable
         parse_str(parse_url($match[1], PHP_URL_QUERY), $_GET);
         $this->assertTrue(self::$trello->authorize());
     }
 }