public function testShowVolumeType()
 {
     $type = $this->blockStorage->showVolumeType($this->volumeTypeId);
     $this->assertTrue($this->blockStorage->isSuccess());
     $this->assertTrue(isset($type['volume_type']));
     $this->assertEquals($this->volumeTypeId, $type['volume_type']['id']);
 }
	protected function _connect($host, $port) {
		$this->sendMsg("Creating ftp connection");
		$sock = ftp_connect(Networking::encodeIDNA($host), $port, $this->timeout);
		if (!$sock) {
			$this->pushError('_connect', 'ftp connect failed');
			return false;
		}
		else {
			$this->connected = true;
			return $sock;
		}
	}
	/**
	 * Set ftp host
	 */
	public function setServer($host, $port = 21, $reconnect = true) {
		if(!is_int($port)) {
	        $this->verbose = true;
    	    $this->sendMsg("Incorrect port syntax");
			return false;
		}
		else {
			$ip = @gethostbyname(Networking::encodeIDNA($host));
	        $dns = @gethostbyaddr($host);
	        if(!$ip) {
				$ip = $host;
			}
	        if(!$dns) {
				$dns = $host;
			}
			if(ip2long($ip) === -1) {
				$this->sendMsg("Wrong host name/address '{$host}'");
				return false;
			}
	        $this->host = $ip;
	        $this->fullhost = $dns;
	        $this->port = $port;
	        $this->dataport = $port-1;
		}
		$this->sendMsg("Host '{$this->fullhost}({$this->host}):{$this->port}'");
		if($reconnect && $this->connected) {
			$this->sendMsg("Reconnecting");
			if(!$this->quit(self::FORCE)) {
				return false;
			}
			if(!$this->connect()) {
				return false;
			}
		}
		return true;
	}
	private function connect() {
		if ($this->host == '') {
			// ToDo : Replace with Exception or something...
			trigger_error('Class HTTP::connect() : host property not set !', E_ERROR);
		}
		if (!$this->use_proxy) {
			$this->socket = fsockopen(
				Networking::encodeIDNA($this->host),
				$this->port,
				$errno,
				$errstr,
				$this->timeout
			);
		}
		else {
			$this->socket = fsockopen(
				Networking::encodeIDNA($this->proxy_host),
				$this->proxy_port,
				$errno,
				$errstr,
				$this->timeout
			);
		}
		$this->errstr  = $errstr;
		$this->connected = ($this->socket == true);
		return $this->connected;
	}
	/**
	 * Attempts to open a connection to the sql server.
	 *
	 * The host can be either a host name or an IP address. Passing the null value or the
	 * string "localhost" to this parameter, the local host is assumed. If successful,
	 * the the function will return an object representing the connection to the database,
	 * or null on failure. The port and socket parameters are used in conjunction with the
	 * host parameter to further control how to connect to the database server. The port
	 * parameter specifies the port number to attempt to connect to the MySQL server on,
	 * while the socket parameter specifies the socket or named pipe that should be used.
	 * If you specify a port and a socket, only the port will be used.
	 * Throws a DatabaseException if opening the connection fails.
	 *
	 * If one of the parameters host, username, port are null, default data will be used:
	 * Host: localhost<br>
	 * Username: root<br>
	 * Password: <empty><br>
	 * Port: 3306<br>
	 *
	 * Note: The database will not be selected! You have to call ExtMySQL::selectDB() before you can
	 * work with the database.
	 *
	 * The charset is set to UTF-8 after connecting.
	 *
	 * @param string Host
	 * @param string Username
	 * @param string Passwort
	 * @param int Port
	 * @param string Socket
	 * @throws DatabaseException
	 */
	public function connect($username = null, $password = null, $host = null, $port = null, $socket = null) {
		$this->username = $username === null ? 'root' : $username;
		$this->password = $password === null ? '' : $password;
		$this->host = $host === null ? 'localhost' : $host;
		$this->port = ($port === null && $this->socket == null) ? '3306' : $port;
		$this->socket = $port === null ? $socket : null;

		$host = $this->host;
		if (Numbers::isNatural($this->port)) {
			$this->host += ":{$this->port}";
		}
		elseif ($this->socket !== null) {
			$this->host += ":{$this->socket}";
		}
		$this->connection = mysql_connect(
			Networking::encodeIDNA($host),
			$this->username,
			$this->password
		);

		if ($this->hasConnection() == false) {
			throw new DatabaseException(
				'Could not connect to database! Pleasy try again later or check the database settings!'
			);
		}
		else {
			$this->setCharset('utf8');
		}
	}
	protected function _data_prepare($mode = FTPClient::ASCII) {
		if(!$this->_settype($mode)) {
			return false;
		}
		if($this->passive) {
			if(!$this->_exec("PASV", "pasv")) {
				$this->_data_close();
				return false;
			}
			if(!$this->_checkCode()) {
				$this->_data_close();
				return false;
			}
			$msg = preg_replace(
				"~^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".self::CRLF."$~",
				"\\1",
				$this->_message
			);
			$ip_port = explode(",", $msg);
			$this->datahost = $ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
			$this->dataport = (((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
			$this->sendMsg("Connecting to ".$this->datahost.":".$this->dataport);
			$this->ftp_data_sock = @fsockopen(
				Networking::encodeIDNA($this->datahost),
				$this->dataport,
				$errno,
				$errstr,
				$this->timeout
			);
			if(!$this->ftp_data_sock) {
				$this->pushError(
					"_data_prepare",
					"fsockopen fails (host: {$this->datahost})",
					"{$errstr} ({$errno})"
				);
				$this->_data_close();
				return false;
			}
		}
		else {
			$this->sendMsg("Only passive connections available!");
			return false;
		}
		return true;
	}
	/**
	 * Connect to the POP3 server
	 * @access public
	 * @param string $host
	 * @param integer $port
	 * @param integer $tval
	 * @return boolean
	 */
	public function Connect($host, $port = false, $tval = 30) {
		//  Are we already connected?
		if ($this->connected) {
			return true;
		}

		/*
		 On Windows this will raise a PHP Warning error if the hostname doesn't exist.
		 Rather than supress it with @fsockopen, let's capture it cleanly instead
		 */

		set_error_handler(array(&$this, 'catchWarning'));

		//  Connect to the POP3 server
		$this->pop_conn = fsockopen(
			Networking::encodeIDNA($host), //  POP3 Host
			$port, //  Port #
			$errno, //  Error Number
			$errstr, //  Error Message
			$tval //  Timeout (seconds)
		);

		//  Restore the error handler
		restore_error_handler();

		//  Does the Error Log now contain anything?
		if ($this->error && $this->do_debug >= 1) {
			$this->displayErrors();
		}

		//  Did we connect?
		if ($this->pop_conn == false) {
			//  It would appear not...
			$this->error = array(
				'error' => "Failed to connect to server $host on port $port",
				'errno' => $errno,
				'errstr' => $errstr
			);

			if ($this->do_debug >= 1) {
				$this->displayErrors();
			}

			return false;
		}

		//  Increase the stream time-out
		stream_set_timeout($this->pop_conn, $tval, 0);
		//  Does not work on Windows
		if (System::getOS() != System::WINDOWS) {
			socket_set_timeout($this->pop_conn, $tval, 0);
		}

		//  Get the POP3 server response
		$pop3_response = $this->getResponse();

		//  Check for the +OK
		if ($this->checkResponse($pop3_response)) {
			//  The connection is established and the POP3 server is talking
			$this->connected = true;
			return true;
		}

	}
	/**
	 * Connect to the server specified on the port specified.
	 * If the port is not specified use the default SMTP_PORT.
	 * If tval is specified then a connection will try and be
	 * established with the server for that number of seconds.
	 * If tval is not specified the default is 30 seconds to
	 * try on the connection.
	 *
	 * SMTP CODE SUCCESS: 220
	 * SMTP CODE FAILURE: 421
	 * @access public
	 * @return bool
	 */
	public function Connect($host, $port = 0, $tval = 30) {
		// set the error val to null so there is no confusion
		$this->error = null;

		// make sure we are __not__ connected
		if ($this->connected()) {
			// already connected, generate error
			$this->error = array("error" => "Already connected to a server");
			return false;
		}

		if (empty($port)) {
			$port = $this->SMTP_PORT;
		}

		// connect to the smtp server
		$this->smtp_conn = @fsockopen(
			Networking::encodeIDNA($host), // the host of the server
			$port, // the port to use
			$errno, // error number if any
			$errstr, // error message if any
			$tval // give up after ? secs
		);
		// verify we connected properly
		if (empty($this->smtp_conn)) {
			$this->error = array(
				"error" => "Failed to connect to server",
				"errno" => $errno,
				"errstr" => $errstr
			);
			if ($this->do_debug >= 1) {
				echo "SMTP -> ERROR: ".$this->error["error"].": $errstr ($errno)".$this->CRLF.'<br />';
			}
			return false;
		}

		// SMTP server can take longer to respond, give longer timeout for first read
		// Windows does not have support for this timeout function
		if (System::getOS() != System::WINDOWS) {
			socket_set_timeout($this->smtp_conn, $tval, 0);
		}

		// get any announcement
		$announce = $this->get_lines();

		if ($this->do_debug >= 2) {
			echo "SMTP -> FROM SERVER:".$announce.$this->CRLF.'<br />';
		}

		return true;
	}