Beispiel #1
0
 public function checkSlug($validator, $values)
 {
     if (!empty($values['slug'])) {
         $values['slug'] = dmString::urlize($values['slug'], true);
         $existingPageName = dmDb::query('DmPageTranslation t')->where('t.lang = ? AND t.slug = ?', array($this->object->lang, $values['slug']))->select('t.name')->fetchValue();
         if ($existingPageName) {
             $error = new sfValidatorError($validator, dm::getI18n()->__('The page "%1%" uses this slug', array('%1%' => $existingPageName)));
             // throw an error bound to the password field
             throw new sfValidatorErrorSchema($validator, array('slug' => $error));
         }
     }
     return $values;
 }
Beispiel #2
0
<?php

require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$t = new lime_test(59);
$t->comment('iconv available : ' . function_exists('iconv'));
$t->is(dmString::slugify(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected);
$t->is(dmString::slugify("fonctionnalité"), $expected = "fonctionnalite", $expected);
$t->is(dmString::urlize(" phrâse avèc dés accënts "), $expected = "phrase-avec-des-accents", $expected);
$t->is(dmString::urlize("fonctionnalité"), $expected = "fonctionnalite", $expected);
$t->is(dmString::slugify("an-url.htm"), $expected = "an-url-htm", $expected);
$t->is(dmString::slugify("an-url.html"), $expected = "an-url-html", $expected);
$t->is(dmString::urlize("an-url.htm"), $expected = "an-url.htm", $expected);
$t->is(dmString::urlize("an-url.html"), $expected = "an-url.html", $expected);
$hexTests = array(array('ffffff', 'FFFFFF'), array('#ffffff', 'FFFFFF'), array('#0Cd4fe', '0CD4FE'), array('aaa', null), array('fffff', null), array('fffxff', null));
foreach ($hexTests as $hexTest) {
    $t->is(dmString::hexColor($hexTest[0]), $hexTest[1], 'dmString::hexColor(' . $hexTest[0] . ') = ' . (null === $hexTest[1] ? 'NULL' : $hexTest[1]));
}
$t->is(dmString::lcfirst('TEST'), 'tEST', 'lcfirst test');
$t->is(dmString::lcfirst('another test'), 'another test', 'lcfirst test');
// ::retrieveOptFromString()
$t->diag('::retrieveOptFromString()');
// Empty string
$t->diag('  ::retrieveOptFromString() empty string');
$string = '';
$opt = array('aa' => 'bb');
$originalOpt = $opt;
$t->is_deeply(dmString::retrieveOptFromString($string, $opt), null, '::retrieveOptFromString() with an empty string returns null');
$t->is_deeply($opt, $originalOpt, '::retrieveOptFromString() with an empty string does not modify opt');
$t->is_deeply($string, '', '::retrieveOptFromString() with an empty string does not modify string');