Skip to content

Commit

Permalink
Added a true test framework where it's configurable based on the URL …
Browse files Browse the repository at this point in the history
…so code does not need to be hacked. The Event class was updated a bit for the code changes that will come into effect in the coming days.

Modified   lib/document.php
* destroy: Added debugging to extract the error response if there is a problem.
* findById: Converted all of the XML data to string or int types to prevent possible errors.

Modified   lib/event.php
* findAll: Removed the default $web_id variable because that will be optional.  Converted all of the XML data types to strings or int explicityly in case of problems.

Added      test/test.php, test/destroy.php, test/event.php, test/test_include.php, test/upload.php
* Deprecated and removed.

Modified   test/index.html
* Replaced the links with documentation for the new test.php file.

Deleted    test/show.php
* Command-line option-like file.  Whatever parameters are passed in it takes to execute a different section of code.  Now the project is finally easily configurable.
  • Loading branch information
bmatzelle committed Oct 11, 2009
1 parent 79118d5 commit 2f027af
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 219 deletions.
23 changes: 10 additions & 13 deletions lib/document.php
Expand Up @@ -86,18 +86,15 @@ public static function destroy($webId)
$url = self::paramsToUrl('documents', $post_params, $webId);
$ch = self::curlRequest();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // only if expecting response
curl_setopt($ch, CURLOPT_URL, $url);

$xml_string = curl_exec($ch);
if(!$xml_string) {
throw new Vuzit_ClientException('CURL load failed: "' . curl_error($ch) . '"');
}

$info = curl_getinfo($ch);
if($info['http_code'] != 200) {
// TODO: You should be checking the code and message and returning
// them!
throw new Vuzit_ClientException("HTTP error " . $info['http_code']);
$xml = @simplexml_load_string($xml_string);
throw new Vuzit_ClientException((string)$xml->msg, (int)$xml->code);
}
curl_close($ch);
}
Expand Down Expand Up @@ -144,15 +141,15 @@ public static function findById($webId)
}

$result = new Vuzit_Document();
$result->id = $xml->web_id;
$result->id = (string)$xml->web_id;

if($xml->title) {
$result->title = $xml->title;
$result->subject = $xml->subject;
$result->pageCount = $xml->page_count;
$result->pageWidth = $xml->width;
$result->pageHeight = $xml->height;
$result->fileSize = $xml->file_size;
$result->title = (string)$xml->title;
$result->subject = (string)$xml->subject;
$result->pageCount = (int)$xml->page_count;
$result->pageWidth = (int)$xml->width;
$result->pageHeight = (int)$xml->height;
$result->fileSize = (int)$xml->file_size;
}

return $result;
Expand Down
22 changes: 9 additions & 13 deletions lib/event.php
Expand Up @@ -91,10 +91,10 @@ public function getZoom() {
/*
Loads an array of events. It throws a <Vuzit_ClientException> on failure.
*/
public static function findAll($web_id, $options = null)
public static function findAll($options = null)
{
$method = "show";
$options_default = array("id" => $web_id,
$options_default = array("id" => null,
"value" => null,
"e" => null,
"m" => "find",
Expand All @@ -105,6 +105,7 @@ public static function findAll($web_id, $options = null)
$options = array_merge($options_default, $options);
}

$web_id = array_key_exists("id", $options) ? $options["id"] : null;
$post_params = self::postParams($method, $options, $web_id);

$ch = self::curlRequest();
Expand All @@ -119,11 +120,6 @@ public static function findAll($web_id, $options = null)
if(!$xml_string) {
throw new Vuzit_ClientException('CURL load failed: "' . curl_error($ch) . '"');
}
// TODO: This needs to be re-added some time in the future by looking at the
// error codes. I would add it but they aren't documented.
//if($info['http_code'] != 200) {
// throw new Vuzit_ClientException("HTTP error " . $info['http_code']);
//}

// Prevent the warnings if the XML is malformed
$xml = @simplexml_load_string($xml_string);
Expand All @@ -145,12 +141,12 @@ public static function findAll($web_id, $options = null)
foreach($xml->event as $node)
{
$event = new Vuzit_Event();
$event->web_id = $node->web_id;
$event->event = $node->event;
$event->remoteHost = $node->remote_host;
$event->referer = $node->referer;
$event->userAgent = $node->user_agent;
$event->valueType = $node->value;
$event->web_id = (string)$node->web_id;
$event->event = (string)$node->event;
$event->remoteHost = (string)$node->remote_host;
$event->referer = (string)$node->referer;
$event->userAgent = (string)$node->user_agent;
$event->valueType = (string)$node->value;
$event->requestedAt = (int)$node->requested;
$event->page = $node->page != null ? (int)$node->page : -1;
$event->zoom = $node->zoom != null ? (int)$node->zoom : -1;
Expand Down
40 changes: 0 additions & 40 deletions test/destroy.php

This file was deleted.

2 changes: 1 addition & 1 deletion test/errors.php
@@ -1,5 +1,5 @@
<?php
require_once 'test_include.php';
require_once '../lib/vuzit.php';

$exception = null;

Expand Down
50 changes: 0 additions & 50 deletions test/event.php

This file was deleted.

60 changes: 51 additions & 9 deletions test/index.html
Expand Up @@ -3,18 +3,60 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Vuzit Basic Viewer Example</title>
<link href="http://vuzit.com/stylesheets/Vuzit-2.5.css" rel="Stylesheet" type="text/css" />
<script src="http://vuzit.com/javascripts/Vuzit-2.5.js" type="text/javascript"></script>

<title>VuzitPHP Test Page</title>
<body onload="">
<h1>Tests</h1>
<ul>
<li><a href="upload.php">Upload</a></li>
<li><a href="show.php?id=1h36">Show</a></li>
<li><a href="errors.php">Errors</a></li>
<li><a href="event.php">Event</a></li>
<li><a href="destroy.php">Destroy</a></li>
<li>
<a href="test.php">test.php</a>
<ul>
<li>To run this you have to create a URL to test.php like so: test.php?puk=abc&amp;prk=123&amp;c=load</li>
</ul>
</li>
<li>
Sub-commands:
<ul>
<li>upload</li>
<li>delete</li>
<li>load</li>
<li>event</li>
</ul>
</li>
<li>
Global parameters:
<ul>
<li>puk - Public key (REQUIRED)</li>
<li>prk - Private key (REQUIRED)</li>
</ul>
</li>
<li>
Upload parameters:
<ul>
<li>path - Path to the file to upload (REQUIRED)</li>
<li>download_pdf - Set to "1" for true or "0" for false</li>
<li>download_document - Set to "1" for true or "0" for false</li>
</ul>
</li>
<li>
Load parameters:
<ul>
<li>id - Document web ID (REQUIRED)</li>
</ul>
</li>
<li>
Delete parameters:
<ul>
<li>id - Document web ID (REQUIRED)</li>
</ul>
</li>
<li>
Event parameters:
<ul>
<li>e - Event type to load</li>
<li>id - Document id to load</li>
<li>v - Value type to load</li>
</ul>
</li>
</body>
</html>

47 changes: 0 additions & 47 deletions test/show.php

This file was deleted.

0 comments on commit 2f027af

Please sign in to comment.