Example #1
0
 public function testPost()
 {
     $mock = new Horde_Http_Request_Mock();
     $mock->setResponse(new Horde_Http_Response_Mock('', fopen(__DIR__ . '/fixtures/AtomPublishingTest-created-entry.xml', 'r'), array('HTTP/1.1 201')));
     $httpClient = new Horde_Http_Client(array('request' => $mock));
     $entry = new Horde_Feed_Entry_Atom(null, $httpClient);
     // Give the entry its initial values.
     $entry->title = 'Entry 1';
     $entry->content = '1.1';
     $entry->content['type'] = 'text';
     // Do the initial post. The base feed URI is the same as the
     // POST URI, so just supply save() with that.
     $entry->save($this->uri);
     // $entry will be filled in with any elements returned by the
     // server (id, updated, link rel="edit", etc).
     $this->assertEquals('1', $entry->id(), 'Expected id to be 1');
     $this->assertEquals('Entry 1', $entry->title(), 'Expected title to be "Entry 1"');
     $this->assertEquals('1.1', $entry->content(), 'Expected content to be "1.1"');
     $this->assertEquals('text', $entry->content['type'], 'Expected content/type to be "text"');
     $this->assertEquals('2005-05-23T16:26:00-08:00', $entry->updated(), 'Expected updated date of 2005-05-23T16:26:00-08:00');
     $this->assertEquals('http://example.com/Feed/1/1/', $entry->link('edit'), 'Expected edit URI of http://example.com/Feed/1/1/');
 }
Example #2
0
    die('An error occurred authenticating: ' . $e->getMessage() . "\n");
}
$auth = null;
foreach (explode("\n", $response->getBody()) as $line) {
    $param = explode('=', $line);
    if ($param[0] == 'Auth') {
        $auth = $param[1];
    }
}
if (empty($auth)) {
    throw new Horde_Feed_Exception('Missing authentication token in the response!');
}
/* The base feed URI is the same as the POST URI, so just supply the
 * Horde_Feed_Entry_Atom object with that. */
$entry = new Horde_Feed_Entry_Atom();
/* Give the entry its initial values. */
$entry->{'atom:title'} = 'Entry 1';
$entry->{'atom:title'}['type'] = 'text';
$entry->{'atom:content'} = '1.1';
$entry->{'atom:content'}['type'] = 'text';
/* Do the initial post. */
try {
    $entry->save($blogUri, array('Authorization' => 'GoogleLogin auth=' . $auth));
} catch (Horde_Feed_Exception $e) {
    die('An error occurred posting: ' . $e->getMessage() . "\n");
}
/* $entry will be filled in with any elements returned by the
 * server (id, updated, link rel="edit", etc). */
echo "new id is: {$entry->id()}\n";
echo "entry last updated at: {$entry->updated()}\n";
echo "edit the entry at: {$entry->edit()}\n";