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(17);
15
 
16
// test for ticket #4935
17
$user = new User();
18
$profile = $user->getProfile();
19
 
20
$userForm = new UserForm($user);
21
$profileForm = new ProfileForm($profile);
22
unset($profileForm['id'], $profileForm['user_id']);
23
 
24
$userForm->embedForm('Profile', $profileForm);
25
 
26
$data = array('username' => 'jwage',
27
              'password' => 'changeme',
28
              'Profile'  => array(
29
                  'first_name' => 'Jonathan',
30
                  'last_name'  => 'Wage'
31
                ));
32
 
33
$userForm->bind($data);
34
$userForm->save();
35
 
36
$t->is($user->getId() > 0, true);
37
$t->is($user->getId(), $profile->getUserId());
38
$t->is($user->getUsername(), 'jwage');
39
$t->is($profile->getFirstName(), 'Jonathan');
40
 
41
$userCount = Doctrine_Query::create()
42
  ->from('User u')
43
  ->count();
44
 
45
$t->is($userCount, 1);
46
 
47
$profileCount = Doctrine_Query::create()
48
  ->from('Profile p')
49
  ->count();
50
 
51
$t->is($profileCount, 1);
52
 
53
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User'));
54
$t->is($widget->getChoices(), array(1 => 1));
55
 
56
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'key_method' => 'getUsername', 'method' => 'getPassword'));
57
$t->is($widget->getChoices(), array('jwage' => '4cb9c8a8048fd02294477fcb1a41191a'));
58
 
59
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'key_method' => 'getUsername', 'method' => 'getPassword'));
60
$t->is($widget->getChoices(), array('jwage' => '4cb9c8a8048fd02294477fcb1a41191a'));
61
 
62
$methods = array(
63
  'widgetChoiceTableMethod1',
64
  'widgetChoiceTableMethod2',
65
  'widgetChoiceTableMethod3'
66
);
67
 
68
foreach ($methods as $method)
69
{
70
  $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => $method));
71
  $t->is($widget->getChoices(), array(1 => 1));
72
}
73
 
74
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => 'widgetChoiceTableMethod4'));
75
$t->is($widget->getChoices(), array());
76
 
77
$user = new User();
78
$user->Groups[]->name = 'User Group 1';
79
$user->Groups[]->name = 'User Group 2';
80
 
81
class UserGroupForm extends GroupForm
82
{
83
  public function configure()
84
  {
85
    parent::configure();
86
    $this->useFields(array('name'));
87
  }
88
}
89
 
90
$userForm = new UserForm($user);
91
$userForm->embedRelation('Groups', 'UserGroupForm');
92
 
93
$data = array(
94
  'username' => 'jonwage',
95
  'password' => 'changeme',
96
  'Groups'  => array(
97
 
98
      'name' => 'New User Group 1 Name'
99
    ),
100
    1 => array(
101
      'name' => 'New User Group 2 Name'
102
    )
103
  )
104
);
105
 
106
$userForm->bind($data);
107
$t->is($userForm->isValid(), true);
108
 
109
if ($userForm->isValid())
110
{
111
  $userForm->save();
112
}
113
 
114
$t->is($user->Groups[0]->name, 'New User Group 1 Name');
115
$t->is($user->Groups[1]->name, 'New User Group 2 Name');
116
 
117
$form = new DefaultValueTestForm();
118
$validatorSchema = $form->getValidatorSchema();
119
$t->is($validatorSchema['name']->getOption('required'), false);