コード例 #1
0
ファイル: UserTypeTest.php プロジェクト: xamin123/platform
 /**
  * @dataProvider addEntityFieldsDataProvider
  * @param $permissions
  * @param $isMyProfile
  */
 public function testAddEntityFields($permissions, $isMyProfile)
 {
     $user = new User();
     $user->setId(1);
     $order = 0;
     foreach ($permissions as $rule => $isGranted) {
         $this->securityFacade->expects($this->at($order))->method('isGranted')->with($rule)->will($this->returnValue($isGranted));
         $order++;
     }
     $request = new Request();
     $request->attributes->add(array('_route' => $isMyProfile ? self::MY_PROFILE_ROUTE : self::OTHER_PROFILE_ROUTE));
     $formFactory = $this->getMockBuilder('Symfony\\Component\\Form\\FormFactory')->disableOriginalConstructor()->getMock();
     $userSubscriber = new UserSubscriber($formFactory, $this->securityInterface);
     $order = 0;
     $builder = $this->getMockBuilder('Symfony\\Component\\Form\\FormBuilder')->disableOriginalConstructor()->setMethods(array('addEventSubscriber', 'add', 'getFormFactory'))->getMock();
     $builder->expects($this->at($order))->method('getFormFactory')->will($this->returnValue($formFactory));
     $builder->expects($this->at(++$order))->method('addEventSubscriber')->with($userSubscriber)->will($this->returnSelf());
     $this->mockSetDefaultUserFields($builder, $order);
     if ($permissions[self::RULE_ROLE]) {
         $builder->expects($this->at(++$order))->method('add')->with('roles', 'entity')->will($this->returnValue($builder));
     }
     if ($permissions[self::RULE_GROUP]) {
         $arr = array('label' => 'oro.user.groups.label', 'class' => 'OroUserBundle:Group', 'property' => 'name', 'multiple' => true, 'expanded' => true, 'required' => false, 'read_only' => $isMyProfile, 'disabled' => $isMyProfile);
         $builder->expects($this->at(++$order))->method('add')->with('groups', 'entity', $arr)->will($this->returnValue($builder));
     }
     if ($permissions[self::RULE_BUSINESS_UNIT] && $permissions[self::RULE_ORGANIZATION]) {
         $builder->expects($this->at(++$order))->method('add')->with('organizations', 'oro_organizations_select')->will($this->returnValue($builder));
     }
     $builder->expects($this->at(++$order))->method('add')->with('plainPassword', 'repeated')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('emails', 'collection')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('tags', 'oro_tag_select')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('imapConfiguration', 'oro_imap_configuration')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('change_password', 'oro_change_password')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('avatar', 'oro_image')->will($this->returnValue($builder));
     $builder->expects($this->at(++$order))->method('add')->with('inviteUser', 'checkbox')->will($this->returnValue($builder));
     $type = new UserType($this->securityInterface, $this->securityFacade, $request);
     $type->buildForm($builder, []);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $builder->addEventSubscriber($this->subscriber);
 }