Exemplo n.º 1
0
 /**
  * @return array
  */
 protected function getSystemVariableValues()
 {
     if (null === $this->systemVariables) {
         $this->systemVariables = $this->variablesProvider->getSystemVariableValues();
     }
     return $this->systemVariables;
 }
Exemplo n.º 2
0
 public function testGetEntityVariableGettersForAllEntities()
 {
     $entity1Class = 'TestEntity1';
     $entity2Class = 'TestEntity2';
     $provider1 = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EntityVariablesProviderInterface');
     $provider1->expects($this->once())->method('getVariableGetters')->with(null)->will($this->returnValue([$entity1Class => ['var1' => 'getVar1']]));
     $provider2 = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EntityVariablesProviderInterface');
     $provider2->expects($this->once())->method('getVariableGetters')->with(null)->will($this->returnValue([$entity1Class => ['var2' => 'getVar2']]));
     $provider3 = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EntityVariablesProviderInterface');
     $provider3->expects($this->once())->method('getVariableGetters')->with(null)->will($this->returnValue([$entity2Class => ['var1' => 'getVar1']]));
     $this->provider->addEntityVariablesProvider($provider1);
     $this->provider->addEntityVariablesProvider($provider2);
     $this->provider->addEntityVariablesProvider($provider3);
     $result = $this->provider->getEntityVariableGetters();
     $this->assertEquals([$entity1Class => ['var1' => 'getVar1', 'var2' => 'getVar2'], $entity2Class => ['var1' => 'getVar1']], $result);
 }
 /**
  * @dataProvider fieldsDataProvider
  * @param $entityIsUser
  */
 public function testGetTemplateVariables($entityIsUser)
 {
     $configId1Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId1Mock->expects($this->once())->method('getClassName')->will($this->returnValue(get_class($this->user)));
     $configId2Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId2Mock->expects($this->once())->method('getClassName')->will($this->returnValue(self::TEST_ENTITY_NAME));
     $configId3Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId3Mock->expects($this->once())->method('getClassName')->will($this->returnValue(self::TEST_NOT_NEEDED_ENTITY_NAME));
     $configurableEntities = array($configId1Mock, $configId2Mock, $configId3Mock);
     $this->configProvider->expects($this->once())->method('getIds')->will($this->returnValue($configurableEntities));
     $field1Id = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\FieldConfigId')->disableOriginalConstructor()->getMock();
     $field1Id->expects($this->any())->method('getFieldName')->will($this->returnValue('someCode'));
     $field1 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field2 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field1->expects($this->any())->method('is')->with('available_in_template')->will($this->returnValue(true));
     $field1->expects($this->any())->method('getId')->will($this->returnValue($field1Id));
     $field2->expects($this->any())->method('is')->with('available_in_template')->will($this->returnValue(false));
     // fields for entity
     $fieldsCollection = new ArrayCollection();
     $this->configProvider->expects($this->at(1))->method('filter')->will($this->returnCallback(function ($callback) use($fieldsCollection) {
         return $fieldsCollection->filter($callback)->toArray();
     }));
     $fieldsCollection[] = $field1;
     $fieldsCollection[] = $field2;
     if (!$entityIsUser) {
         $field3Id = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\FieldConfigId')->disableOriginalConstructor()->getMock();
         $field3Id->expects($this->any())->method('getFieldName')->will($this->returnValue('someAnotherCode'));
         $field3 = clone $field1;
         $field3->expects($this->atLeastOnce())->method('is')->with('available_in_template')->will($this->returnValue(true));
         $field3->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($field3Id));
         $this->configProvider->expects($this->at(2))->method('filter')->will($this->returnCallback(function ($callback) use($fieldsCollection, $field3) {
             $fieldsCollection[] = $field3;
             return $fieldsCollection->filter($callback)->toArray();
         }));
         $result = $this->provider->getTemplateVariables(self::TEST_ENTITY_NAME);
     } else {
         $result = $this->provider->getTemplateVariables(get_class($this->user));
     }
     $this->assertArrayHasKey('user', $result);
     $this->assertArrayHasKey('entity', $result);
     $this->assertInternalType('array', $result['user']);
     $this->assertInternalType('array', $result['entity']);
     if ($entityIsUser) {
         $this->assertEquals($result['user'], $result['entity']);
     }
 }
Exemplo n.º 4
0
 /**
  * Compile email message
  *
  * @param EmailTemplateInterface $template
  * @param array                  $templateParams
  *
  * @return array first element is email subject, second - message
  */
 public function compileMessage(EmailTemplateInterface $template, array $templateParams = array())
 {
     $templateParams['system'] = $this->variablesProvider->getSystemVariableValues();
     $subject = $template->getSubject();
     $content = $template->getContent();
     if (isset($templateParams['entity'])) {
         $subject = $this->processDateTimeVariables($subject, $templateParams['entity']);
         $content = $this->processDateTimeVariables($content, $templateParams['entity']);
     }
     $templateRendered = $this->render($content, $templateParams);
     $subjectRendered = $this->render($subject, $templateParams);
     return array($subjectRendered, $templateRendered);
 }