/** * Test that we have all the custom rules we need loaded up */ public function testCustomRules() { $val = new Validate(); $rules = $val->getCustomRules(); $this->assertArrayHasKey('dir', $rules); $this->assertArrayHasKey('file', $rules); $this->assertArrayHasKey('readable', $rules); $this->assertArrayHasKey('writable', $rules); }
/** * (non-PHPdoc) * * @see \mithra62\Validate\RuleInterface::validate() * @ignore * */ public function validate($field, $input, array $params = array()) { try { if ($input == '' || empty($params['0'])) { return false; } $params = $params['0']; if (empty($params['ftp_hostname']) || empty($params['ftp_password']) || empty($params['ftp_username']) || empty($params['ftp_port'])) { return false; } $filesystem = new Remote(Ftp::getRemoteClient($params)); if (!$filesystem->getAdapter()->listContents()) { return false; } $filesystem->getAdapter()->disconnect(); return true; } catch (\Exception $e) { return false; } } } $rule = new Connect(); \JaegerApp\Validate::addrule($rule->getName(), array($rule, 'validate'), $rule->getErrorMessage());
/** * Tests that a directory can be determined true */ public function testRuleSuccess() { $val = new Validate(); $val->rule('rcf_container_exists', 'connection_field', $this->getRcfCreds())->val(array('connection_field' => 'Foo')); $this->assertFALSE($val->hasErrors()); }
/** * Tests that a directory can be determined true */ public function testRuleSuccess() { $val = new Validate(); $val->rule('ftp_writable', 'connection_field', $this->getFtpCreds())->val(array('connection_field' => 'Foo')); $this->assertFALSE($val->hasErrors()); }
/** * Sets up and returns all the objects we'll use * * @return \Pimple\Container */ public function getServices() { $this->container = parent::getServices(); $this->container['db'] = function ($c) { $db = new Db(); $db->setCredentials($this->getDbConfig()); $type = 'mysqli'; if (class_exists('Pdo')) { $type = 'pdo'; } $db->setAccessType($type); return $db; }; $this->container['encrypt'] = function ($c) { $encrypt = new Encrypt(); $new_key = $c['platform']->getEncryptionKey(); $encrypt->setKey($new_key); return $encrypt; }; $this->container['lang'] = function ($c) { $lang = new Language(); if (is_array($this->getLangPath())) { foreach ($this->getLangPath() as $path) { $lang->init($path); } } elseif ($this->getLangPath() != '') { $lang->init($this->getLangPath()); } return $lang; }; $this->container['validate'] = function ($c) { $validate = new Validate(); $validate->setRegex($this->container['regex']); return $validate; }; $this->container['files'] = function ($c) { $file = new Files(); return $file; }; $this->container['errors'] = function ($c) { $errors = new Errors(); $errors->setValidation($c['validate']); return $errors; }; $this->container['license'] = function ($c) { $license = new License(); return $license; }; $this->container['email'] = function ($c) { $email = new Email(); $email->setView($c['view']); $email->setLang($c['lang']); return $email; }; $this->container['view'] = function ($c) { $view = new View(); $helpers = array('file_size' => function ($text) { return $this->container['view_helpers']->m62FileSize($text, false); }, 'lang' => function ($text) { return $this->container['view_helpers']->m62Lang($text); }, 'date_time' => function ($text, $html = true) { return $this->container['view_helpers']->m62DateTime($text, false); }, 'relative_time' => function ($date) { return $this->container['view_helpers']->m62RelativeDateTime($date); }, 'encode' => function ($text) { return $this->container['view_helpers']->m62Encode($text); }, 'decode' => function ($text) { return $this->container['view_helpers']->m62Decode($text); }); $view->addHelper('m62', $helpers); return $view; }; $this->container['regex'] = function ($c) { $regex = new Regex(); return $regex; }; $this->container['shell'] = function ($c) { $shell = new Shell(); return $shell; }; $this->container['console'] = function ($c) { $console = new Console(); $console->setLang($c['lang']); return $console; }; return $this->container; }
/** * Tests that a directory can be determined true */ public function testRuleSuccess() { $val = new Validate(); $val->rule('dropbox_connect', 'connection_field', $this->getDropboxCreds())->val(array('connection_field' => 'Foo')); $this->assertFALSE($val->hasErrors()); }
/** * Tests that a directory can be determined true */ public function testRuleSuccess() { $val = new Validate(); $val->rule('gcs_bucket_readable', 'connection_field', $this->getGcsCreds())->val(array('connection_field' => 'Foo')); $this->assertFALSE($val->hasErrors()); }