コード例 #1
0
 /**
  * Encode a value from the widget to native data of the data provider via event.
  *
  * @param string           $property       The property.
  *
  * @param mixed            $value          The value of the property.
  *
  * @param PropertyValueBag $propertyValues The property value bag the property value originates from.
  *
  * @return mixed
  */
 public function encodeValue($property, $value, PropertyValueBag $propertyValues)
 {
     $environment = $this->getEnvironment();
     $event = new EncodePropertyValueFromWidgetEvent($environment, $this->model, $propertyValues);
     $event->setProperty($property)->setValue($value);
     $environment->getEventDispatcher()->dispatch(EncodePropertyValueFromWidgetEvent::NAME, $event);
     return $event->getValue();
 }
コード例 #2
0
 /**
  * Encode a value from the widget to native data of the data provider via event.
  *
  * @param string $property The property.
  *
  * @param mixed  $value    The value of the property.
  *
  * @return mixed
  */
 public function encodeValue($property, $value)
 {
     $environment = $this->getEnvironment();
     $event = new EncodePropertyValueFromWidgetEvent($environment, $this->model);
     $event->setProperty($property)->setValue($value);
     $environment->getEventPropagator()->propagate($event::NAME, $event, array($environment->getDataDefinition()->getName(), $property));
     return $event->getValue();
 }
コード例 #3
0
 /**
  * The subscriber creates the date from a timestamp.
  *
  * @param string $format The given date format.
  * @param string $value  The given date example
  *
  * @dataProvider dataProvider
  * @test
  */
 public function it_parses_timestamp_for_widget($format, $value)
 {
     $valuesBag = $this->getMock('ContaoCommunityAlliance\\DcGeneral\\Data\\PropertyValueBagInterface', array(), array());
     // Attribute will return timestamp, create it.
     $dateTime = \DateTime::createFromFormat($format, $value);
     $timestamp = $dateTime->getTimestamp();
     $attribute = $this->mockAttribute($format);
     $attribute->expects($this->any())->method('valueToWidget')->will($this->returnValue($timestamp));
     $model = $this->mockModelWithAttribute($attribute);
     $event = new EncodePropertyValueFromWidgetEvent($this->mockEnvironment(), $model, $valuesBag);
     $event->setProperty('date');
     $event->setValue($value);
     $this->backendSubscriber->handleEncodePropertyValueFromWidget($event);
     $this->assertEquals($timestamp, $event->getValue());
 }
コード例 #4
0
 /**
  * Check that the parsing of the callbacks is working.
  *
  * @return void
  */
 public function testCallbackParsing()
 {
     $this->aliasContaoClass('Session');
     $this->aliasContaoClass('System');
     $this->aliasContaoClass('Controller');
     $this->aliasContaoClass('Backend');
     $this->aliasContaoClass('DataContainer');
     $dispatcher = new EventDispatcher();
     $container = new DefaultContainer('tl_test');
     $event = new BuildDataDefinitionEvent($container);
     $builder = $this->mockBuilderWithDca(array('fields' => array('testProperty' => array('save_callback' => array(function () {
         return 'executed';
     })))), $event::NAME, $dispatcher);
     $builder->build($event->getContainer(), $event);
     $environment = new DefaultEnvironment();
     $environment->setDataDefinition($container);
     $event = new EncodePropertyValueFromWidgetEvent($environment, new DefaultModel(), new PropertyValueBag());
     $event->setProperty('testProperty');
     $this->assertEquals(1, count($dispatcher->getListeners(EncodePropertyValueFromWidgetEvent::NAME)));
     foreach ($dispatcher->getListeners(EncodePropertyValueFromWidgetEvent::NAME) as $listener) {
         /** @var AbstractCallbackListener $listener */
         $this->assertTrue($listener->wantToExecute($event));
         $event->setValue('testvalue');
         $listener($event);
         $this->assertEquals('executed', $event->getValue());
     }
     $event->setProperty('testProperty2');
     foreach ($dispatcher->getListeners(EncodePropertyValueFromWidgetEvent::NAME) as $listener) {
         /** @var AbstractCallbackListener $listener */
         $this->assertFalse($listener->wantToExecute($event));
     }
 }