Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
$app = 'frontend';
12
require_once(dirname(__FILE__).'/../bootstrap/functional.php');
13
 
14
$t = new lime_test(13);
15
 
16
$article = new Article();
17
$article->title = 'test';
18
$t->is($article->Translation['en']->title, 'test');
19
 
20
sfContext::getInstance()->getUser()->setCulture('fr');
21
$article->title = 'fr test';
22
$t->is($article->Translation['fr']->title, 'fr test');
23
 
24
$t->is($article->getTitle(), $article->title);
25
$article->setTitle('test');
26
$t->is($article->getTitle(), 'test');
27
 
28
$article->setTestColumn('test');
29
$t->is($article->getTestColumn(), 'test');
30
$t->is($article->Translation['fr']['test_column'], 'test');
31
 
32
$article->free(true);
33
 
34
class MyArticleForm extends ArticleForm
35
{
36
  public function configure()
37
  {
38
    parent::configure();
39
 
40
    $this->embedI18n(array('en', 'fr'));
41
 
42
    $authorForm = new AuthorForm($this->object->Author);
43
    unset($authorForm['id']);
44
 
45
    $this->embedForm('Author', $authorForm);
46
 
47
    unset($this['author_id']);
48
  }
49
}
50
 
51
$article = new Article();
52
$articleForm = new MyArticleForm($article);
53
 
54
$data = array(
55
  'is_on_homepage' => 1,
56
  'Author' => array(
57
    'name' => 'i18n author test',
58
    'type' => null),
59
  'en' => array(
60
    'title' => 'english title',
61
    'body'  => 'english body'),
62
  'fr' => array(
63
    'title' => 'french title',
64
    'body'  => 'french body'),
65
  'created_at' => time(),
66
  'updated_at' => time(),
67
);
68
 
69
$articleForm->bind($data);
70
$t->is($articleForm->isValid(), true);
71
 
72
$data = $articleForm->getValues();
73
 
74
$values = array(
75
  'is_on_homepage' => true,
76
  'Author' =>
77
  array(
78
    'name' => 'i18n author test',
79
    'type' => null
80
  ),
81
  'en' =>
82
  array(
83
    'title' => 'english title',
84
    'body' => 'english body',
85
    'test_column' => '',
86
    'slug' => '',
87
  ),
88
  'fr' =>
89
  array(
90
    'title' => 'french title',
91
    'body' => 'french body',
92
    'test_column' => '',
93
    'slug' => '',
94
  ),
95
  'id' => null,
96
  'type' => null,
97
  'views' => null,
98
  'created_at' => $data['created_at'],
99
  'updated_at' => $data['updated_at'],
100
);
101
 
102
$t->is($articleForm->getValues(), $values);
103
 
104
$articleForm->save();
105
 
106
$expected = array(
107
  'id' => $article->id,
108
  'author_id' => $article->Author->id,
109
  'is_on_homepage' => true,
110
  'type' => null,
111
  'views' => null,
112
  'created_at' => $article->created_at,
113
  'updated_at' => $article->updated_at,
114
  'Translation' =>
115
  array(
116
    'en' =>
117
    array(
118
      'id' => $article->id,
119
      'title' => 'english title',
120
      'body' => 'english body',
121
      'test_column' => '',
122
      'lang' => 'en',
123
      'slug' => 'english-title',
124
    ),
125
    'fr' =>
126
    array(
127
      'id' => $article->id,
128
      'title' => 'french title',
129
      'body' => 'french body',
130
      'test_column' => '',
131
      'lang' => 'fr',
132
      'slug' => 'french-title',
133
    ),
134
  ),
135
  'Author' =>
136
  array(
137
    'id' => $article->Author->id,
138
    'name' => 'i18n author test',
139
    'type' => null
140
  ),
141
);
142
 
143
$t->is($article->toArray(true), $expected);
144
 
145
$articleForm = new MyArticleForm($article);
146
 
147
$expected = array(
148
  'id' => $article->id,
149
  'author_id' => $article->author_id,
150
  'is_on_homepage' => true,
151
  'type' => null,
152
  'views' => null,
153
  'created_at' => $article->created_at,
154
  'updated_at' => $article->updated_at,
155
  'en' =>
156
  array(
157
    'id' => $article->id,
158
    'title' => 'english title',
159
    'body' => 'english body',
160
    'test_column' => '',
161
    'lang' => 'en',
162
    'slug' => 'english-title',
163
  ),
164
  'fr' =>
165
  array(
166
    'id' => $article->id,
167
    'title' => 'french title',
168
    'body' => 'french body',
169
    'test_column' => '',
170
    'lang' => 'fr',
171
    'slug' => 'french-title',
172
  ),
173
  'Author' =>
174
  array(
175
    'id' => $article->Author->id,
176
    'name' => 'i18n author test',
177
    'type' => null
178
  ),
179
);
180
 
181
$t->is($articleForm->getDefaults(), $expected);
182
 
183
// Bug #7486
184
$data = array(
185
  'id' => $article->id,
186
  'is_on_homepage' => true,
187
  'type' => null,
188
  'created_at' => $article->created_at,
189
  'updated_at' => $article->updated_at,
190
  'en' =>
191
  array(
192
    'id' => $article->id,
193
    'title' => 'english title',
194
    'body' => 'english body',
195
    'test_column' => '',
196
    'lang' => 'en',
197
    'slug' => 'english-title',
198
  ),
199
  'fr' =>
200
  array(
201
    'id' => $article->id,
202
    'title' => 'french title',
203
    'body' => 'french body',
204
    'test_column' => '',
205
    'lang' => 'fr',
206
    'slug' => 'french-title',
207
  ),
208
  'Author' =>
209
  array(
210
    'name' => 'i18n author test',
211
    'type' => null
212
  ),
213
);
214
 
215
$articleForm->bind($data);
216
$t->is($articleForm->isValid(), true);
217
 
218
$article = new Article();
219
$articleForm = new MyArticleForm($article);
220
 
221
$data = array(
222
  'is_on_homepage' => 1,
223
  'Author' => array(
224
    'name' => 'i18n author test',
225
    'type' => null),
226
  'en' => array(
227
    'title' => 'english title',
228
    'body'  => 'english body'),
229
  'fr' => array(
230
    'title' => 'french title',
231
    'body'  => 'french body'),
232
  'created_at' => time(),
233
  'updated_at' => time(),
234
);
235
 
236
$articleForm->bind($data);
237
$t->is($articleForm->isValid(), false);
238
// END: Bug #7486
239
 
240
$article = new Article();
241
sfContext::getInstance()->getUser()->setCulture('en');
242
$article->title = 'test';
243
sfContext::getInstance()->getUser()->setCulture('fr');
244
$t->is($article->title, 'test');