<commit_before><?php

/*
 * This file is part of the symfony package.
 * (c) <NAME> <<EMAIL>>
 *
 * 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');

$t = new lime_test(15, new lime_output_color());

$w1 = new sfWidgetFormInput();
$w2 = new sfWidgetFormInput();
$ws = new sfWidgetFormSchema(array('w1' => $w1));

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");

// ->getWidget()
$t->diag('->getWidget()');
$t->is($w->getWidget(), $ws, '->getWidget() returns the decorated widget');

// ->render()
$t->diag('->render()');
$output = <<<EOF
<table>
<tr>
  <th><label for="w1">W1</label></th>
  <td><input type="text" name="w1" id="w1" /></td>
</tr>
</table>
EOF;
$t->is($w->render(null), $output, '->render() decorates the widget');

// implements ArrayAccess
$t->diag('implements ArrayAccess');
$w['w2'] = $w2;
$t->is($w->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

try
{
  $w['w1'] = 'string';
  $t->fail('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
}
catch (LogicException $e)
{
  $t->pass('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
}

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
$t->is(isset($w['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($w['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($ws['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($ws['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
$t->is($w['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($w['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
unset($w['w1']);
$t->is($w['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');<commit_msg>added unit test for sfWidgetFormSchemaDecorator::__clone()<commit_after><?php

/*
 * This file is part of the symfony package.
 * (c) <NAME> <<EMAIL>>
 *
 * 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');

$t = new lime_test(16, new lime_output_color());

$w1 = new sfWidgetFormInput();
$w2 = new sfWidgetFormInput();
$ws = new sfWidgetFormSchema(array('w1' => $w1));

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");

// ->getWidget()
$t->diag('->getWidget()');
$t->is($w->getWidget(), $ws, '->getWidget() returns the decorated widget');

// ->render()
$t->diag('->render()');
$output = <<<EOF
<table>
<tr>
  <th><label for="w1">W1</label></th>
  <td><input type="text" name="w1" id="w1" /></td>
</tr>
</table>
EOF;
$t->is($w->render(null), $output, '->render() decorates the widget');

// implements ArrayAccess
$t->diag('implements ArrayAccess');
$w['w2'] = $w2;
$t->is($w->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws->getFields(), array('w1' => $w1, 'w2' => $w2), 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

try
{
  $w['w1'] = 'string';
  $t->fail('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
}
catch (LogicException $e)
{
  $t->pass('sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
}

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
$t->is(isset($w['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($w['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($ws['w1']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is(isset($ws['w2']), true, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
$t->is($w['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($w['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w1'], $w1, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w2'], $w2, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

$w = new sfWidgetFormSchemaDecorator($ws, "<table>\n%content%</table>");
unset($w['w1']);
$t->is($w['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');
$t->is($ws['w1'], null, 'sfWidgetFormSchemaDecorator implements the ArrayAccess interface for the fields');

// __clone()
$t->diag('__clone()');
$w1 = clone $w;
$t->ok($w1->getWidget() !== $w->getWidget(), '__clone() clones the embedded widget');
{'fraction_non_alphanumeric': 0.19010504913588613, 'fraction_numerical': 0.01253812267028126, 'mean_word_length': 6.716339869281046, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7584904', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1935, 'n_words': 513}