Overview

Packages

  • Jyxo_Beholder
  • Jyxo_Charset
  • Jyxo_Color
  • Jyxo_Css
  • Jyxo_ErrorHandling
  • Jyxo_FirePhp
  • Jyxo_Gettext
    • Parser
  • Jyxo_Html
  • Jyxo_Input
    • Chain
    • Filter
    • Validator
  • Jyxo_Mail
    • Email
    • Parser
    • Sender
  • Jyxo_Rpc
    • Json
    • Xml
  • Jyxo_Shell
  • Jyxo_SpamFilter
  • Jyxo_Spl
  • Jyxo_String
  • Jyxo_Svn
  • Jyxo_Time
  • Jyxo_Timer
  • Jyxo_Webdav
  • Jyxo_XmlReader
  • PHP

Classes

  • Jyxo_Beholder_Executor
  • Jyxo_Beholder_Result
  • Jyxo_Beholder_TestCase
  • Jyxo_Beholder_TestCase_FileSystem
  • Jyxo_Beholder_TestCase_HttpResponse
  • Jyxo_Beholder_TestCase_Imap
  • Jyxo_Beholder_TestCase_JsonRpc
  • Jyxo_Beholder_TestCase_Memcached
  • Jyxo_Beholder_TestCase_Mysql
  • Jyxo_Beholder_TestCase_Pgsql
  • Jyxo_Beholder_TestCase_PhpExtension
  • Jyxo_Beholder_TestCase_PhpVersion
  • Jyxo_Beholder_TestCase_PhpZend
  • Jyxo_Beholder_TestCase_Smtp
  • Jyxo_Beholder_TestCase_Webdav
  • Jyxo_Beholder_TestCase_XmlRpc
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: /**
 15:  * Tests WebDAV availability.
 16:  *
 17:  * @category Jyxo
 18:  * @package Jyxo_Beholder
 19:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 20:  * @license https://github.com/jyxo/php/blob/master/license.txt
 21:  * @author Jaroslav HanslĂ­k
 22:  */
 23: class Jyxo_Beholder_TestCase_Webdav extends Jyxo_Beholder_TestCase
 24: {
 25:     /**
 26:      * Server hostname.
 27:      *
 28:      * @var string
 29:      */
 30:     private $server;
 31: 
 32:     /**
 33:      * Tested directory.
 34:      *
 35:      * @var string
 36:      */
 37:     private $dir;
 38: 
 39:     /**
 40:      * Connection options.
 41:      *
 42:      * @var array
 43:      */
 44:     private $options;
 45: 
 46:     /**
 47:      * Constructor.
 48:      *
 49:      * @param string $description Test description
 50:      * @param string $server Server hostname
 51:      * @param string $dir Tested directory
 52:      * @param array $options Connection options
 53:      */
 54:     public function __construct($description, $server, $dir = '', array $options = array())
 55:     {
 56:         parent::__construct($description);
 57: 
 58:         $this->server = (string) $server;
 59:         $this->dir = (string) $dir;
 60:         $this->options = $options;
 61:     }
 62: 
 63:     /**
 64:      * Performs the test.
 65:      *
 66:      * @return Jyxo_Beholder_Result
 67:      */
 68:     public function run()
 69:     {
 70:         // The http extension is required
 71:         if (!extension_loaded('http')) {
 72:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::NOT_APPLICABLE, 'Extension http missing');
 73:         }
 74: 
 75:         // The Jyxo_Webdav_Client class is required
 76:         if (!class_exists('Jyxo_Webdav_Client')) {
 77:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::NOT_APPLICABLE, 'Class Jyxo_Webdav_Client missing');
 78:         }
 79: 
 80:         $random = md5(uniqid(time(), true));
 81:         $dir = trim($this->dir, '/');
 82:         if (!empty($dir)) {
 83:             $dir = '/' . $dir;
 84:         }
 85:         $path = $dir . '/beholder-' . $random . '.txt';
 86:         $content = $random;
 87: 
 88:         // Status label
 89:         $serverUrl = $this->server;
 90:         if ('http://' !== substr($this->server, 0, 7)) {
 91:             $serverUrl = 'http://' . $serverUrl;
 92:         }
 93:         $parsed = parse_url($serverUrl);
 94:         $ip = $parsed['host'];
 95:         $port = !empty($parsed['port']) ? $parsed['port'] : 80;
 96:         $description = (false !== filter_var($ip, FILTER_VALIDATE_IP) ? gethostbyaddr($ip) : $ip) . ':' . $port . $dir;
 97: 
 98:         try {
 99:             $webdav = new Jyxo_Webdav_Client(array($serverUrl));
100:             foreach ($this->options as $name => $value) {
101:                 $webdav->setOption($name, $value);
102:             }
103: 
104:             // Writing
105:             if (!$webdav->put($path, $content)) {
106:                 return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Write error %s', $description));
107:             }
108: 
109:             // Reading
110:             $readContent = $webdav->get($path);
111:             if (strlen($readContent) !== strlen($content)) {
112:                 return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Read error %s', $description));
113:             }
114: 
115:             // Deleting
116:             if (!$webdav->unlink($path)) {
117:                 return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Delete error %s', $description));
118:             }
119: 
120:         } catch (Jyxo_Webdav_FileNotExistException $e) {
121:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Read error %s', $description));
122:         } catch (Jyxo_Webdav_Exception $e) {
123:             return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Error %s', $description));
124:         }
125: 
126:         // OK
127:         return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::SUCCESS, $description);
128:     }
129: }
130: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0