| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
$app = 'frontend';
|
|
|
4 |
include dirname(__FILE__).'/../../bootstrap/functional.php';
|
|
|
5 |
|
|
|
6 |
$t = new lime_test(13);
|
|
|
7 |
|
|
|
8 |
// ->__construct()
|
|
|
9 |
$t->diag('->__construct()');
|
|
|
10 |
|
|
|
11 |
class NumericFieldForm extends ArticleForm
|
|
|
12 |
{
|
|
|
13 |
public function configure()
|
|
|
14 |
{
|
|
|
15 |
$this->widgetSchema[1] = new sfWidgetFormInputText();
|
|
|
16 |
$this->validatorSchema[1] = new sfValidatorPass();
|
|
|
17 |
$this->setDefault(1, '==DEFAULT_VALUE==');
|
|
|
18 |
}
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
$form = new NumericFieldForm();
|
|
|
22 |
$defaults = $form->getDefaults();
|
|
|
23 |
$t->is($defaults[1], '==DEFAULT_VALUE==', '->__construct() allows ->configure() to set defaults on numeric fields');
|
|
|
24 |
|
|
|
25 |
class DefaultValuesForm extends AuthorForm
|
|
|
26 |
{
|
|
|
27 |
public function configure()
|
|
|
28 |
{
|
|
|
29 |
$this->setDefault('name', 'John Doe');
|
|
|
30 |
}
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
$author = new Author();
|
|
|
34 |
$form = new DefaultValuesForm($author);
|
|
|
35 |
$t->is($form->getDefault('name'), 'John Doe', '->__construct() uses form defaults for new objects');
|
|
|
36 |
|
|
|
37 |
$author = new Author();
|
|
|
38 |
$author->name = 'Jacques Doe';
|
|
|
39 |
$author->save();
|
|
|
40 |
$form = new DefaultValuesForm($author);
|
|
|
41 |
$t->is($form->getDefault('name'), 'Jacques Doe', '->__construct() uses object value as a default for existing objects');
|
|
|
42 |
$author->delete();
|
|
|
43 |
|
|
|
44 |
// ->embedRelation()
|
|
|
45 |
$t->diag('->embedRelation()');
|
|
|
46 |
|
|
|
47 |
class myArticleForm extends ArticleForm
|
|
|
48 |
{
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
$table = Doctrine_Core::getTable('Author');
|
|
|
52 |
$form = new AuthorForm($table->create(array(
|
|
|
53 |
'Articles' => array(
|
|
|
54 |
array('title' => 'Article 1'),
|
|
|
55 |
array('title' => 'Article 2'),
|
|
|
56 |
array('title' => 'Article 3'),
|
|
|
57 |
),
|
|
|
58 |
)));
|
|
|
59 |
|
|
|
60 |
$form->embedRelation('Articles');
|
|
|
61 |
$embeddedForms = $form->getEmbeddedForms();
|
|
|
62 |
|
|
|
63 |
$t->ok(isset($form['Articles']), '->embedRelation() embeds forms');
|
|
|
64 |
$t->is(count($embeddedForms['Articles']), 3, '->embedRelation() embeds one form for each related object');
|
|
|
65 |
|
|
|
66 |
$form->embedRelation('Articles', 'myArticleForm', array(array('test' => true)));
|
|
|
67 |
$embeddedForms = $form->getEmbeddedForms();
|
|
|
68 |
$moreEmbeddedForms = $embeddedForms['Articles']->getEmbeddedForms();
|
|
|
69 |
$t->isa_ok($moreEmbeddedForms[0], 'myArticleForm', '->embedRelation() accepts a form class argument');
|
|
|
70 |
$t->ok($moreEmbeddedForms[0]->getOption('test'), '->embedRelation() accepts a form arguments argument');
|
|
|
71 |
|
|
|
72 |
$form = new AuthorForm($table->create(array(
|
|
|
73 |
'Articles' => array(
|
|
|
74 |
array('title' => 'Article 1'),
|
|
|
75 |
array('title' => 'Article 2'),
|
|
|
76 |
),
|
|
|
77 |
)));
|
|
|
78 |
$form->embedRelation('Articles as author_articles');
|
|
|
79 |
$t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias');
|
|
|
80 |
$t->is(count($form['author_articles']), 2, '->embedRelation() embeds one form for each related object using an alias');
|
|
|
81 |
|
|
|
82 |
$form = new AuthorForm($table->create(array(
|
|
|
83 |
'Articles' => array(
|
|
|
84 |
array('title' => 'Article 1'),
|
|
|
85 |
array('title' => 'Article 2'),
|
|
|
86 |
),
|
|
|
87 |
)));
|
|
|
88 |
$form->embedRelation('Articles AS author_articles');
|
|
|
89 |
$t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias with a case insensitive separator');
|
|
|
90 |
|
|
|
91 |
$form = new ArticleForm(Doctrine_Core::getTable('Article')->create(array(
|
|
|
92 |
'Author' => array('name' => 'John Doe'),
|
|
|
93 |
)));
|
|
|
94 |
$form->embedRelation('Author');
|
|
|
95 |
$t->is(isset($form['Author']), true, '->embedRelation() embeds a ONE type relation');
|
|
|
96 |
$t->is(isset($form['Author']['name']), true, '->embedRelation() embeds a ONE type relation');
|
|
|
97 |
$t->is($form['Author']['name']->getValue(), 'John Doe', '->embedRelation() uses values from the related object');
|