Changeset 6340
- Timestamp:
- 12/06/07 17:00:57 (7 months ago)
- Files:
-
- trunk/lib/widget/sfWidgetFormDateTime.class.php (modified) (2 diffs)
- trunk/test/unit/widget/sfWidgetFormDateTest.php (modified) (3 diffs)
- trunk/test/unit/widget/sfWidgetFormDateTimeTest.php (modified) (1 diff)
- trunk/test/unit/widget/sfWidgetFormTimeTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/widget/sfWidgetFormDateTime.class.php
r6327 r6340 65 65 { 66 66 // date 67 $date = new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date'));67 $date = $this->getDateWidget()->render($name, $value); 68 68 69 69 if (!$this->getOption('with_time')) 70 70 { 71 return $date ->render($name, $value);71 return $date; 72 72 } 73 73 74 $dateTime = array('%date%' => $date->render($name, $value)); 75 76 // time 77 $time = new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time')); 78 79 $dateTime['%time%'] = $time->render($name, $value); 80 81 return strtr($this->getOption('format'), $dateTime); 74 return strtr($this->getOption('format'), array( 75 '%date%' => $date, 76 '%time%' => $this->getTimeWidget()->render($name, $value), 77 )); 82 78 } 83 79 80 /** 81 * Returns the date widget 82 * 83 * @return sfWidgetForm A Widget representing the date 84 */ 85 protected function getDateWidget() 86 { 87 return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date')); 88 } 89 90 /** 91 * Returns the time widget 92 * 93 * @return sfWidgetForm A Widget representing the time 94 */ 95 protected function getTimeWidget() 96 { 97 return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time')); 98 } 99 100 /** 101 * Returns an array of options for the given type 102 * 103 * @param string The type (date or time) 104 * 105 * @return array An array of options 106 */ 84 107 protected function getOptionsFor($type) 85 108 { … … 93 116 } 94 117 118 /** 119 * Returns an array of HTML attributes for the given type 120 * 121 * @param string The type (date or time) 122 * 123 * @return array An array of HTML attributes 124 */ 95 125 protected function getAttributesFor($type) 96 126 { trunk/test/unit/widget/sfWidgetFormDateTest.php
r6327 r6340 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 2, new lime_output_color());13 $t = new lime_test(29, new lime_output_color()); 14 14 15 15 $w = new sfWidgetFormDate(); … … 49 49 50 50 // number of options in each select 51 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 12, '->render() renders a select tag for the 10 years around the current one'); 52 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 13, '->render() renders a select tag for the 12 months in a year'); 53 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 32, '->render() renders a select tag for the 31 days in a month'); 54 55 // can_be_empty option 56 $t->diag('can_be_empty option'); 57 $w->setOption('can_be_empty', false); 58 $dom->loadHTML($w->render('foo', '2005-10-15')); 59 $css = new sfDomCssSelector($dom); 51 60 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 11, '->render() renders a select tag for the 10 years around the current one'); 52 61 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 12, '->render() renders a select tag for the 12 months in a year'); 53 62 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 31, '->render() renders a select tag for the 31 days in a month'); 63 $w->setOption('can_be_empty', true); 64 65 // empty_values 66 $t->diag('empty_values option'); 67 $w->setOption('empty_values', array('year' => 'YEAR', 'month' => 'MONTH', 'day' => 'DAY')); 68 $dom->loadHTML($w->render('foo', '2005-10-15')); 69 $css = new sfDomCssSelector($dom); 70 $t->is($css->matchSingle('#foo_year option')->getNode()->nodeValue, 'YEAR', '->configure() can change the empty values'); 71 $t->is($css->matchSingle('#foo_month option')->getNode()->nodeValue, 'MONTH', '->configure() can change the empty values'); 72 $t->is($css->matchSingle('#foo_day option')->getNode()->nodeValue, 'DAY', '->configure() can change the empty values'); 73 $w->setOption('empty_values', array('year' => '', 'month' => '', 'day' => '')); 54 74 55 75 // format option … … 76 96 $dom->loadHTML($w->render('foo', '2005-10-15')); 77 97 $css = new sfDomCssSelector($dom); 78 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 4, '__construct() can change the default array used for years');79 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 3, '__construct() can change the default array used for months');80 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 2, '__construct() can change the default array used for days');98 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 5, '__construct() can change the default array used for years'); 99 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 4, '__construct() can change the default array used for months'); 100 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 3, '__construct() can change the default array used for days'); trunk/test/unit/widget/sfWidgetFormDateTimeTest.php
r6327 r6340 55 55 56 56 // number of options in each select 57 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 1 1, '->render() renders a select tag for the 10 years around the current one');58 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 1 2, '->render() renders a select tag for the 12 months in a year');59 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 3 1, '->render() renders a select tag for the 31 days in a month');60 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 2 4, '->render() renders a select tag for the 24 hours in a day');61 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 6 0, '->render() renders a select tag for the 60 minutes in an hour');62 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 6 0, '->render() renders a select tag for the 60 seconds in a minute');57 $t->is(count($css->matchAll('#foo_year option')->getNodes()), 12, '->render() renders a select tag for the 10 years around the current one'); 58 $t->is(count($css->matchAll('#foo_month option')->getNodes()), 13, '->render() renders a select tag for the 12 months in a year'); 59 $t->is(count($css->matchAll('#foo_day option')->getNodes()), 32, '->render() renders a select tag for the 31 days in a month'); 60 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 25, '->render() renders a select tag for the 24 hours in a day'); 61 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 61, '->render() renders a select tag for the 60 minutes in an hour'); 62 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 61, '->render() renders a select tag for the 60 seconds in a minute'); 63 63 64 64 // date and time format option trunk/test/unit/widget/sfWidgetFormTimeTest.php
r6327 r6340 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 3, new lime_output_color());13 $t = new lime_test(29, new lime_output_color()); 14 14 15 15 $w = new sfWidgetFormTime(array('with_seconds' => true)); … … 48 48 49 49 // number of options in each select 50 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 24, '->render() renders a select tag for the 24 hours in a day'); 50 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 25, '->render() renders a select tag for the 24 hours in a day'); 51 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 61, '->render() renders a select tag for the 60 minutes in an hour'); 52 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 61, '->render() renders a select tag for the 60 seconds in a minute'); 53 54 // can_be_empty option 55 $t->diag('can_be_empty option'); 56 $w->setOption('can_be_empty', false); 57 $dom->loadHTML($w->render('foo', '2005-10-15')); 58 $css = new sfDomCssSelector($dom); 59 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 24, '->render() renders a select tag for the 24 hours around in a day'); 51 60 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 60, '->render() renders a select tag for the 60 minutes in an hour'); 52 61 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 60, '->render() renders a select tag for the 60 seconds in a minute'); 62 $w->setOption('can_be_empty', true); 63 64 // empty_values 65 $t->diag('empty_values option'); 66 $w->setOption('empty_values', array('hour' => 'HOUR', 'minute' => 'MINUTE', 'second' => 'SECOND')); 67 $dom->loadHTML($w->render('foo', '2005-10-15')); 68 $css = new sfDomCssSelector($dom); 69 $t->is($css->matchSingle('#foo_hour option')->getNode()->nodeValue, 'HOUR', '->configure() can change the empty values'); 70 $t->is($css->matchSingle('#foo_minute option')->getNode()->nodeValue, 'MINUTE', '->configure() can change the empty values'); 71 $t->is($css->matchSingle('#foo_second option')->getNode()->nodeValue, 'SECOND', '->configure() can change the empty values'); 72 $w->setOption('empty_values', array('hour' => '', 'minute' => '', 'second' => '')); 53 73 54 74 // format option … … 75 95 $dom->loadHTML($w->render('foo', '12:30:35')); 76 96 $css = new sfDomCssSelector($dom); 77 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 4, '__construct() can change the default array used for hours');78 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 2, '__construct() can change the default array used for minutes');79 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 3, '__construct() can change the default array used for seconds');97 $t->is(count($css->matchAll('#foo_hour option')->getNodes()), 5, '__construct() can change the default array used for hours'); 98 $t->is(count($css->matchAll('#foo_minute option')->getNodes()), 3, '__construct() can change the default array used for minutes'); 99 $t->is(count($css->matchAll('#foo_second option')->getNodes()), 4, '__construct() can change the default array used for seconds'); 80 100 81 101 // with_seconds option