Exemple #1
0
 public function executeValidateUrl()
 {
     $myValidator = new sfUrlValidator();
     $myValidator->initialize($this->getContext(), array());
     $value = urldecode($this->getRequestParameter('value'));
     if (!$myValidator->execute($value, $error)) {
         exit(UtilsHelper::Localize('system.frontend.Validate_url_error'));
     }
     exit("ok");
 }
Exemple #2
0
 public function executeValidateUrl()
 {
     $myValidator = new sfUrlValidator();
     $myValidator->initialize($this->getContext(), array());
     if (!$myValidator->execute(urldecode($this->getRequestParameter('value')), $error)) {
         exit('you must enter a valid url');
     }
     exit("ok");
 }
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
require_once $_test_dir . '/../../../../test/unit/sfContextMock.class.php';
$t = new lime_test(12);
$context = sfContext::getInstance();
$v = new sfUrlValidator($context);
// ->execute()
$t->diag('->execute()');
$validUrls = array('http://www.google.com', 'https://google.com/', 'http://www.symfony-project.com/', 'ftp://www.symfony-project.com/file.tgz');
$invalidUrls = array('google.com', 'http:/google.com');
$v->initialize($context);
foreach ($validUrls as $value) {
    $error = null;
    $t->ok($v->execute($value, $error), sprintf('->execute() returns true for a valid URL "%s"', $value));
    $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true');
}
foreach ($invalidUrls as $value) {
    $error = null;
    $t->ok(!$v->execute($value, $error), sprintf('->execute() returns false for an invalid URL "%s"', $value));
    $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false');
}