/**
* Tests S3
*
* @param string $error
* @return boolean
*/
function test(&$error)
{
if (!parent::test($error)) {
return false;
}
$string = 'test_s3_' . md5(time());
if (!$this->_init($error)) {
return false;
}
$this->_set_error_handler();
$buckets = @$this->_s3->listBuckets();
if ($buckets === false) {
$error = sprintf('Unable to list buckets (%s).', $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
if (!in_array($this->_config['bucket'], (array) $buckets)) {
$error = sprintf('Bucket doesn\'t exist: %s.', $this->_config['bucket']);
$this->_restore_error_handler();
return false;
}
if (!@$this->_s3->putObjectString($string, $this->_config['bucket'], $string, S3::ACL_PUBLIC_READ)) {
$error = sprintf('Unable to put object (%s).', $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
if (!($object = @$this->_s3->getObject($this->_config['bucket'], $string))) {
$error = sprintf('Unable to get object (%s).', $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
if ($object->body != $string) {
$error = 'Objects are not equal.';
@$this->_s3->deleteObject($this->_config['bucket'], $string);
$this->_restore_error_handler();
return false;
}
if (!@$this->_s3->deleteObject($this->_config['bucket'], $string)) {
$error = sprintf('Unable to delete object (%s).', $this->_get_last_error());
$this->_restore_error_handler();
return false;
}
$this->_restore_error_handler();
return true;
}