Esempio n. 1
0
 public function testMarkUnread()
 {
     $this->configuration->offsetUnset('mark_type');
     $this->unreadAction = new MarkUnreadMassAction();
     $this->unreadAction->setOptions($this->configuration);
     $options = $this->unreadAction->getOptions();
     $this->assertEquals(MarkMassActionHandler::MARK_UNREAD, $options->offsetGet('mark_type'));
 }
 function it_doesnt_allow_overriding_frontend_type()
 {
     $params = ['route' => 'foo', 'frontend_type' => 'bar'];
     $options = ActionConfiguration::createNamed('edit', $params);
     $this->setOptions($options)->shouldNotThrow(Argument::any());
     $this->getOptions()->offsetGet('frontend_type')->shouldReturn('redirect');
 }
 /**
  * @dataProvider actionOptions
  *
  * @param array $actionOptions
  * @param string $link
  * @param string $title
  * @param string $translatedTitle
  */
 public function testGetOptions(array $actionOptions, $link, $title, $translatedTitle)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|TranslatorInterface $translator */
     $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     if (count($actionOptions) > 1) {
         $translator->expects($this->once())->method('trans')->with($title)->will($this->returnValue($translatedTitle));
     }
     $actionConfiguration = ActionConfiguration::create($actionOptions);
     $action = new RequestChangeStatusDialogAction($translator);
     $action->setOptions($actionConfiguration);
     $options = $action->getOptions();
     $this->assertInstanceOf('Oro\\Bundle\\DataGridBundle\\Extension\\Action\\Actions\\AbstractAction', $action);
     $this->assertInstanceOf('Oro\\Bundle\\DataGridBundle\\Extension\\Action\\ActionConfiguration', $options);
     $this->assertCount(count($actionOptions) + 1, $options);
     $this->assertArrayHasKey('launcherOptions', $options);
     $this->assertArrayHasKey('link', $options);
     $this->assertEquals($link, $options['link']);
     $this->assertArrayHasKey('onClickReturnValue', $options['launcherOptions']);
     $this->assertTrue($options['launcherOptions']['onClickReturnValue']);
     $this->assertArrayHasKey('runAction', $options['launcherOptions']);
     $this->assertTrue($options['launcherOptions']['runAction']);
     $this->assertArrayHasKey('className', $options['launcherOptions']);
     $this->assertEquals('no-hash', $options['launcherOptions']['className']);
     $this->assertArrayHasKey('widget', $options['launcherOptions']);
     $this->assertEquals([], $options['launcherOptions']['widget']);
     $this->assertArrayHasKey('messages', $options['launcherOptions']);
     $this->assertEquals([], $options['launcherOptions']['messages']);
     if ($translatedTitle) {
         $this->assertArrayHasKey('widgetOptions', $options);
         $this->assertArrayHasKey('options', $options['widgetOptions']);
         $this->assertArrayHasKey('dialogOptions', $options['widgetOptions']['options']);
         $this->assertArrayHasKey('title', $options['widgetOptions']['options']['dialogOptions']);
         $this->assertEquals($translatedTitle, $options['widgetOptions']['options']['dialogOptions']['title']);
     }
 }
 function it_doesnt_allow_overriding_frontend_type()
 {
     $routeParams = array('_format' => 'foo', '_contentType' => 'bar');
     $params = array('route_parameters' => $routeParams, 'frontend_type' => 'bar');
     $options = ActionConfiguration::createNamed('edit', $params);
     $this->setOptions($options)->shouldNotThrow(Argument::any());
     $this->getOptions()->offsetGet('frontend_type')->shouldReturn('export');
 }
Esempio n. 5
0
 /**
  * @param array $source
  * @param array $expected
  * @dataProvider setOptionsDataProvider
  */
 public function testSetOptions(array $source, array $expected)
 {
     $this->action->setOptions(ActionConfiguration::create($source));
     $actual = $this->action->getOptions();
     foreach ($expected as $name => $value) {
         $this->assertEquals($value, $actual->offsetGet($name));
     }
 }
 public function testSetOptions()
 {
     $actionConfiguration = ActionConfiguration::create(['confirmation' => true]);
     $massAction = (new AddProductsMassAction())->setOptions($actionConfiguration);
     $options = $massAction->getOptions();
     $this->assertEquals('add-products-mass', $options['frontend_type']);
     $this->assertEquals('orob2b_shopping_list.mass_action.add_products_handler', $options['handler']);
     $this->assertEquals('orob2b_shopping_list_add_products_massaction', $options['route']);
     $this->assertEmpty($options['route_parameters']);
     $this->assertEquals('ajax', $options['frontend_handle']);
 }
 /**
  * @expectedException        \RuntimeException
  * @expectedExceptionMessage Field name was not specified with option 'mass_edit_field'
  *
  * @throws \Exception
  */
 public function testBatchUpdateNoFieldName()
 {
     /** @var MassActionInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
     $massActionMock = $this->getMock(MassActionInterface::class);
     $entityName = 'Test\\Entity';
     $options = ActionConfiguration::create(['entityName' => $entityName]);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     /** @var IterableResultInterface|\PHPUnit_Framework_MockObject_MockObject $massActionMock */
     $iteratorMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\IterableResultInterface');
     $data = [];
     $this->actionRepo->batchUpdate($massActionMock, $iteratorMock, $data);
 }
Esempio n. 8
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Trying to get name of unnamed object
  */
 public function testMergeMassActionSetOptionShouldThrowExceptionIfClassNameOptionIsEmpty()
 {
     $this->target->setOptions(ActionConfiguration::create(array()));
 }
 public function testHandleUpdateNotAllowed()
 {
     $massActionMock = $this->getMock(MassActionInterface::class);
     $datagridMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $iteratorMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\IterableResultInterface');
     $entityName = 'Test\\EntityName';
     $hasConfig = true;
     $isEnabled = true;
     $isGranted = false;
     $data = [];
     $this->actionRepoMock->expects($this->once())->method('getEntityName')->with($datagridMock)->will($this->returnValue($entityName));
     $this->configMock->expects($this->once())->method('hasConfig')->with($entityName)->will($this->returnValue($hasConfig));
     $this->configMock->expects($this->once())->method('getConfig')->with($entityName)->will($this->returnValue(new Config(new EntityConfigId('extend', $entityName), ['update_mass_action_enabled' => $isEnabled])));
     $this->securityMock->expects($this->once())->method('isGranted')->with('EDIT', 'entity:' . $entityName)->will($this->returnValue($isGranted));
     $this->actionRepoMock->expects($this->never())->method('batchUpdate');
     $this->transMock->expects($this->once())->method('trans')->will($this->returnValue(uniqid()));
     $options = ActionConfiguration::create(['success_message' => '', 'error_message' => '']);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     $this->transMock->expects($this->once())->method('trans')->with('', ['%error%' => 'Action not configured or not allowed']);
     $this->loggerMock->expects($this->once())->method('debug');
     $actionResponse = $this->handler->handle(new MassActionHandlerArgs($massActionMock, $datagridMock, $iteratorMock, $data));
     $this->assertFalse($actionResponse->isSuccessful());
 }
Esempio n. 10
0
 /**
  * {@inheritDoc}
  */
 public function getName()
 {
     return $this->options->getName();
 }
 /**
  * @return array
  */
 public function setOptionsDataProvider()
 {
     $link = 'http://localhost';
     return ['without confirmation' => ['options' => ['link' => $link], 'expected' => ActionConfiguration::create(['link' => $link, 'confirmation' => true])], 'with confirmation' => ['options' => ['confirmation' => true, 'link' => $link], 'expected' => ActionConfiguration::create(['link' => $link, 'confirmation' => true])]];
 }
Esempio n. 12
0
 public function testSetOptions()
 {
     $options = ['frontend_type' => 'frontend-mass'];
     $this->action->setOptions(ActionConfiguration::create($options));
     $this->assertEquals($options, $this->action->getOptions()->toArray());
 }