Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • FileSystem
  • HttpResponse
  • Imap
  • JsonRpc
  • Memcached
  • Mysql
  • Pgsql
  • PhpExtension
  • PhpVersion
  • PhpZend
  • Smtp
  • Webdav
  • XmlRpc
  • Overview
  • Namespace
  • 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: namespace Jyxo\Beholder\TestCase;
 15: 
 16: /**
 17:  * Tests WebDAV availability.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\Beholder
 21:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 22:  * @license https://github.com/jyxo/php/blob/master/license.txt
 23:  * @author Jaroslav HanslĂ­k
 24:  */
 25: class Webdav extends \Jyxo\Beholder\TestCase
 26: {
 27:     /**
 28:      * Server hostname.
 29:      *
 30:      * @var string
 31:      */
 32:     private $server;
 33: 
 34:     /**
 35:      * Tested directory.
 36:      *
 37:      * @var string
 38:      */
 39:     private $dir;
 40: 
 41:     /**
 42:      * Connection options.
 43:      *
 44:      * @var array
 45:      */
 46:     private $options;
 47: 
 48:     /**
 49:      * Constructor.
 50:      *
 51:      * @param string $description Test description
 52:      * @param string $server Server hostname
 53:      * @param string $dir Tested directory
 54:      * @param array $options Connection options
 55:      */
 56:     public function __construct($description, $server, $dir = '', array $options = array())
 57:     {
 58:         parent::__construct($description);
 59: 
 60:         $this->server = (string) $server;
 61:         $this->dir = (string) $dir;
 62:         $this->options = $options;
 63:     }
 64: 
 65:     /**
 66:      * Performs the test.
 67:      *
 68:      * @return \Jyxo\Beholder\Result
 69:      */
 70:     public function run()
 71:     {
 72:         // The http extension is required
 73:         if (!extension_loaded('http')) {
 74:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension http missing');
 75:         }
 76: 
 77:         // The \Jyxo\Webdav\Client class is required
 78:         if (!class_exists('\Jyxo\Webdav\Client')) {
 79:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Class \Jyxo\Webdav\Client missing');
 80:         }
 81: 
 82:         $random = md5(uniqid(time(), true));
 83:         $dir = trim($this->dir, '/');
 84:         if (!empty($dir)) {
 85:             $dir = '/' . $dir;
 86:         }
 87:         $path = $dir . '/beholder-' . $random . '.txt';
 88:         $content = $random;
 89: 
 90:         // Status label
 91:         $serverUrl = $this->server;
 92:         if ('http://' !== substr($this->server, 0, 7)) {
 93:             $serverUrl = 'http://' . $serverUrl;
 94:         }
 95:         $parsed = parse_url($serverUrl);
 96:         $ip = $parsed['host'];
 97:         $port = !empty($parsed['port']) ? $parsed['port'] : 80;
 98:         $description = (false !== filter_var($ip, FILTER_VALIDATE_IP) ? gethostbyaddr($ip) : $ip) . ':' . $port . $dir;
 99: 
100:         try {
101:             $webdav = new \Jyxo\Webdav\Client(array($serverUrl));
102:             foreach ($this->options as $name => $value) {
103:                 $webdav->setOption($name, $value);
104:             }
105: 
106:             // Writing
107:             if (!$webdav->put($path, $content)) {
108:                 return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Write error %s', $description));
109:             }
110: 
111:             // Reading
112:             $readContent = $webdav->get($path);
113:             if (strlen($readContent) !== strlen($content)) {
114:                 return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Read error %s', $description));
115:             }
116: 
117:             // Deleting
118:             if (!$webdav->unlink($path)) {
119:                 return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Delete error %s', $description));
120:             }
121: 
122:         } catch (\Jyxo\Webdav\FileNotExistException $e) {
123:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Read error %s', $description));
124:         } catch (\Jyxo\Webdav\Exception $e) {
125:             return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Error %s', $description));
126:         }
127: 
128:         // OK
129:         return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description);
130:     }
131: }
132: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0