method = $method; $this->contents = $contents; $this->content_type = $content_type; } function getMethod() { return $this->method; } function writeHeadersTo(&$socket) { if($this->method == 'DELETE') return; $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); $socket->write("Content-Type: " . $this->get_content_type() . "\r\n"); } function writeTo(&$socket) { $socket->write($this->_encode()); } function asUrlRequest() { return ''; } function &_encode() { return $this->contents; } function &get_content_type() { return $this->content_type; } function getAll() { return array(); } function clear() { } } class AtomTestCase extends WebTestCase { var $feed = false; var $entry = false; function AtomTestCase($label = false) { $this->WebTestCase($label); } function reset() { $this->feed = false; $this->entry = false; } function &get_feed() { if(!$this->feed) { $contents = $this->getBrowser()->getContent(); $tmpname = tempnam('/tmp','wp-app'); $tmpfile = fopen($tmpname, 'w'); fwrite($tmpfile, $this->getBrowser()->getContent()); fclose($tmpfile); $parser = new AtomParser(); $parser->FILE = $tmpname; if($parser->parse()) { $this->feed = $parser->feed; } @unlink($tmpname); } return $this->feed; } function &get_first_entry() { if(!$this->entry) { $feed = $this->get_feed(); if(count($feed->entries) > 0) $this->entry = $feed->entries[0]; } return $this->entry; } function get($url, $parameters = false) { $this->reset(); return parent::get($url, $parameters); } function post($url, $contents, $content_type = 'application/atom+xml') { $this->reset(); if (! is_object($url)) { $url = new SimpleUrl($url); } if ($this->getBrowser()->getUrl()) { $url = $url->makeAbsolute($this->getBrowser()->getUrl()); } return $this->_failOnError($this->getBrowser()->_load($url, new AtomEncoding('POST', $contents, $content_type))); } function put($url, $contents, $content_type = 'application/atom+xml') { $this->reset(); if (! is_object($url)) { $url = new SimpleUrl($url); } if ($this->getBrowser()->getUrl()) { $url = $url->makeAbsolute($this->getBrowser()->getUrl()); } return $this->_failOnError($this->getBrowser()->_load($url, new AtomEncoding('PUT', $contents, $content_type))); } function delete($url) { $this->reset(); if (! is_object($url)) { $url = new SimpleUrl($url); } if ($this->getBrowser()->getUrl()) { $url = $url->makeAbsolute($this->getBrowser()->getUrl()); } return $this->_failOnError($this->getBrowser()->_fetch($url, new AtomEncoding('DELETE'))); } function assertFeed() { return $this->assertTrue($this->get_feed()); } function assertEntry() { return $this->assertTrue($this->get_first_entry()); } function assertTitle($ctype, $text, $message = '%s') { $type = $this->get_first_entry()->title[0]; $title = $this->get_first_entry()->title[1]; return $this->assert( new TextExpectation($text), $title, $message) && $this->assert( new TextExpectation($ctype), $type, $message); } function assertSummary($ctype, $text, $message = '%s') { $type = $this->get_first_entry()->summary[0]; $title = $this->get_first_entry()->summary[1]; return $this->assert( new TextExpectation($text), $title, $message) && $this->assert( new TextExpectation($ctype), $type, $message); } function assertContent($ctype, $text, $message = '%s') { $type = $this->get_first_entry()->content[0]; $title = $this->get_first_entry()->content[1]; return $this->assert( new TextExpectation($text), $title, $message) && $this->assert( new TextExpectation($ctype), $type, $message); } function assertDraft($message = '%s') { return $this->assertEqual('yes',$this->get_first_entry()->draft,$message); } function assertNotDraft($message = '%s') { $draft = isset($this->get_first_entry()->draft) ? $this->get_first_entry()->draft : 'no'; return $this->assertEqual('no',$draft,$message); } } ?>