예제 #1
0
 /**
  * Test toString
  */
 public function testToString()
 {
     $value = 'Opened';
     $requestStatus = new RequestStatus();
     $requestStatus->setLabel($value);
     $this->assertEquals($value, (string) $requestStatus);
 }
 protected function assertRequestChangeStatus()
 {
     $requestStatusEntity = new RequestStatus();
     $requestStatusEntity->setLabel('StatusLabel');
     $status = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $status->expects($this->once())->method('getData')->will($this->returnValue($requestStatusEntity));
     $note = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $note->expects($this->once())->method('getData')->will($this->returnValue('note'));
     $this->form->expects($this->exactly(2))->method('get')->with($this->logicalOr($this->equalTo('status'), $this->equalTo('note')))->will($this->returnCallback(function ($param) use($status, $note) {
         $data = null;
         switch ($param) {
             case 'status':
                 $data = $status;
                 break;
             case 'note':
                 $data = $note;
                 break;
             default:
                 break;
         }
         return $data;
     }));
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->templating->expects($this->once())->method('render')->with('OroB2BRFPBundle:Request:note.html.twig', ['status' => $requestStatusEntity->getLabel(), 'note' => 'note'])->will($this->returnValue('message'));
 }
 /**
  * @dataProvider supportedMethods
  * @param string $method
  * @param boolean $isValid
  * @param boolean $isProcessed
  */
 public function testProcessSupportedRequest($method, $isValid, $isProcessed)
 {
     $reflection = new \ReflectionProperty(get_class($this->entity), 'id');
     $reflection->setAccessible(true);
     $reflection->setValue($this->entity, 1);
     $this->manager->expects($this->once())->method('refresh')->with($this->entity);
     parent::testProcessSupportedRequest($method, $isValid, $isProcessed);
     $this->assertEquals(self::DEFAULT_LOCALE, $this->entity->getLocale());
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $om)
 {
     foreach ($this->requestStatuses as $requestStatusData) {
         $requestStatus = new RequestStatus();
         $requestStatus->setSortOrder($requestStatusData['order'])->setName($requestStatusData['name'])->setLabel($requestStatusData['label'])->setLocale($requestStatusData['locale'])->setDeleted($requestStatusData['deleted']);
         $om->persist($requestStatus);
     }
     $om->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var \Oro\Bundle\LocaleBundle\Model\LocaleSettings $localeSettings */
     $localeSettings = $this->container->get('oro_locale.settings');
     foreach ($this->statuses as $status) {
         $entity = new RequestStatus();
         $entity->setSortOrder($status['order']);
         $entity->setName($status['name']);
         $entity->setLocale($localeSettings->getLocale())->setLabel($status['label']);
         $manager->persist($entity);
     }
     $manager->flush();
 }
 /**
  * Process form
  *
  * @param  RequestStatus $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(RequestStatus $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $requestStatus = new RequestStatus();
     $requestStatus->setName(RequestStatus::OPEN);
     /* @var $repository ObjectRepository|\PHPUnit_Framework_MockObject_MockObject */
     $repository = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $repository->expects(static::any())->method('findOneBy')->with(['name' => RequestStatus::OPEN])->willReturn($requestStatus);
     /* @var $manager ObjectManager|\PHPUnit_Framework_MockObject_MockObject */
     $manager = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock();
     $manager->expects(static::any())->method('getRepository')->with(self::REQUEST_STATUS_CLASS)->willReturn($repository);
     /* @var $registry ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject */
     $registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $registry->expects(static::any())->method('getManagerForClass')->with(self::REQUEST_STATUS_CLASS)->willReturn($manager);
     /* @var $configManager ConfigManager|\PHPUnit_Framework_MockObject_MockObject */
     $configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $configManager->expects(static::any())->method('get')->with('oro_b2b_rfp.default_request_status')->willReturn(RequestStatus::OPEN);
     $this->formType = new RequestType($configManager, $registry);
     $this->formType->setDataClass(self::DATA_CLASS);
     $this->formType->setRequestStatusClass(self::REQUEST_STATUS_CLASS);
     parent::setUp();
 }
 /**
  * {@inheritdoc}
  */
 public function loadEntities(ObjectManager $objectManager)
 {
     $localeSettings = $this->container->get('oro_locale.settings');
     $defaultLocale = $localeSettings->getLocale();
     $locales = $this->getTranslationLocales();
     if (!in_array($defaultLocale, $locales, true)) {
         throw new \LogicException('There are no default locale in translations!');
     }
     foreach ($this->items as $item) {
         $status = new RequestStatus();
         $status->setSortOrder($item['order']);
         $status->setName($item['name']);
         foreach ($locales as $locale) {
             $label = $this->translate($item['name'], static::PREFIX, $locale);
             if ($locale == $defaultLocale) {
                 $status->setLabel($label)->setLocale($locale);
             } else {
                 $status->addTranslation((new RequestStatusTranslation())->setLocale($locale)->setField('label')->setContent($label));
             }
         }
         $objectManager->persist($status);
     }
     $objectManager->flush();
 }
 public function testIsDraft()
 {
     $requestStatus = new RequestStatus();
     $requestStatus->setName(RequestStatus::DRAFT);
     $this->assertTrue($requestStatus->isDraft());
 }