| 1 |
<?php |
|---|
| 2 |
require_once(dirname(__FILE__).'/../bootstrap/unit.php'); |
|---|
| 3 |
require_once(dirname(__FILE__).'/../../lib/widget/ExtendedWidgetFormI18nSelectCountry.class.php'); |
|---|
| 4 |
|
|---|
| 5 |
$t = new lime_test(6, new lime_output_color()); |
|---|
| 6 |
|
|---|
| 7 |
$dom = new DomDocument('1.0', 'utf-8'); |
|---|
| 8 |
$dom->validateOnParse = true; |
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
$t->diag('->configure()'); |
|---|
| 12 |
try |
|---|
| 13 |
{ |
|---|
| 14 |
new ExtendedWidgetFormI18nSelectCountry(array('culture' => 'en', 'countries' => array('EN'))); |
|---|
| 15 |
$t->fail('->configure() throws an InvalidArgumentException if a country does not exist'); |
|---|
| 16 |
} |
|---|
| 17 |
catch (InvalidArgumentException $e) |
|---|
| 18 |
{ |
|---|
| 19 |
$t->pass('->configure() throws an InvalidArgumentException if a country does not exist'); |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
$v = new ExtendedWidgetFormI18nSelectCountry(array('culture' => 'en', 'countries' => array('FR', 'GB'))); |
|---|
| 23 |
$t->is(array_keys($v->getOption('choices')), array('FR', 'GB'), '->configure() can restrict the number of countries with the countries option'); |
|---|
| 24 |
|
|---|
| 25 |
$v = new ExtendedWidgetFormI18nSelectCountry(array('culture' => 'en', 'countries' => array('FR', 'GB'), 'add_label_option' => 'Select:')); |
|---|
| 26 |
$t->is(array_keys($v->getOption('choices')), array('', 'FR', 'GB'), '->configure() custom option is added to the top of available options'); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
$t->diag('->render()'); |
|---|
| 30 |
$w = new ExtendedWidgetFormI18nSelectCountry(array('culture' => 'fr')); |
|---|
| 31 |
$dom->loadHTML($w->render('country', 'FR')); |
|---|
| 32 |
$css = new sfDomCssSelector($dom); |
|---|
| 33 |
$t->is($css->matchSingle('#country option[value="FR"]')->getValue(), 'France', '->render() renders all countries as option tags'); |
|---|
| 34 |
$t->is(count($css->matchAll('#country option[value="FR"][selected="selected"]')->getNodes()), 1, '->render() renders all countries as option tags'); |
|---|
| 35 |
|
|---|
| 36 |
$w = new ExtendedWidgetFormI18nSelectCountry(array('culture' => 'en', 'countries' => array('FR', 'GB'), 'add_label_option' => 'Select:')); |
|---|
| 37 |
$dom->loadHTML($w->render('country', '')); |
|---|
| 38 |
$css = new sfDomCssSelector($dom); |
|---|
| 39 |
$t->is($css->matchSingle('#country option[value=""]')->getValue(), 'Select:', '->render() renders custom option'); |
|---|
| 40 |
|
|---|