$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('#foo_year option')->getNodes()), 12, '->render() renders a select tag for the 10 years around the current one');
$t->is(count($css->matchAll('#foo_month option')->getNodes()), 13, '->render() renders a select tag for the 12 months in a year');
$t->is(count($css->matchAll('#foo_day option')->getNodes()), 32, '->render() renders a select tag for the 31 days in a month');
$t->is(count($css->matchAll('#foo_hour option')->getNodes()), 25, '->render() renders a select tag for the 24 hours in a day');
$t->is(count($css->matchAll('#foo_minute option')->getNodes()), 61, '->render() renders a select tag for the 60 minutes in an hour');
$t->is(count($css->matchAll('#foo_second option')->getNodes()), 61, '->render() renders a select tag for the 60 seconds in a minute');
// date and time format option
$t->diag('date and time format option');
$t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '/', '->render() renders 3 selects with a default / as a format');
$t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '#^/#', '->render() renders 3 selects with a default / as a format');
$t->is($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, ':', '->render() renders 3 selects with a default : as a format');
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, ':', '->render() renders 3 selects with a default : as a format');
$t->diag('change date and time format option');
$w->setOption('date', array('format' => '%month%-%day%-%year%'));
$w->setOption('time', array('format' => '%hour%!%minute%!%second%', 'with_seconds' => true));
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#foo_day')->getNode()->nextSibling->nodeValue, '-', '__construct() can change the default format');
$t->like($css->matchSingle('#foo_month')->getNode()->nextSibling->nodeValue, '/^-/', '__construct() can change the default format');
$t->is($css->matchSingle('#foo_hour')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format');
$t->is($css->matchSingle('#foo_minute')->getNode()->nextSibling->nodeValue, '!', '__construct() can change the default format');
// with_time option
$t->diag('with_time option');
$w = new sfWidgetFormDateTime(array('with_time' => false));
$dom->loadHTML($w->render('foo', '2005-10-15 12:30:35'));
$css = new sfDomCssSelector($dom);
$t->is(count($css->matchAll('#foo_hour')->getNodes()), 0, '->render() does not render the time if the with_time option is disabled');
// date and time options as array
$t->diag('date and time options as array');
Esempio n. 2
0
    $t->fail('__construct() throws a InvalidArgumentException if the date/time options is not an array');
} catch (InvalidArgumentException $e) {
    $t->pass('__construct() throws a InvalidArgumentException if the date/time options is not an array');
}
// attributes
$t->diag('attributes');
$w = new sfWidgetFormDateTime();
$dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35', array('date' => array('disabled' => 'disabled'), 'time' => array('disabled' => 'disabled'))));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
$w->setAttribute('date', array('disabled' => 'disabled'));
$w->setAttribute('time', array('disabled' => 'disabled'));
$dom->loadHTML($w->render('foo', $year . '-10-15 12:30:35'));
$t->is(count($css->matchAll('select[disabled="disabled"]')->getNodes()), 5, '->render() takes the attributes into account for all the five embedded widgets');
// id_format
$t->diag('id_format');
$w = new sfWidgetFormDateTime();
$w->setIdFormat('id_%s');
$dom->loadHTML($w->render('foo'));
$t->is(count($css->matchAll('#id_foo_month')), 1, '->render() month considers id_format');
$t->is(count($css->matchAll('#id_foo_day')), 1, '->render() day considers id_format');
$t->is(count($css->matchAll('#id_foo_year')), 1, '->render() year considers id_format');
$t->is(count($css->matchAll('#id_foo_hour')), 1, '->render() hour considers id_format');
$t->is(count($css->matchAll('#id_foo_minute')), 1, '->render() minute considers id_format');
$w->setOption('date', array('id_format' => 'override_%s'));
$w->setOption('time', array('id_format' => 'override_%s'));
$dom->loadHTML($w->render('foo'));
$t->is(count($css->matchAll('#override_foo_month')), 1, '->render() month does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_day')), 1, '->render() day does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_year')), 1, '->render() year does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_hour')), 1, '->render() hour does not override subwidget id_format');
$t->is(count($css->matchAll('#override_foo_minute')), 1, '->render() minute does not override subwidget id_format');