/** * @param $test * @return \Swift_Mime_MimePart * @throws \TijsVerkoyen\CssToInlineStyles\Exception */ private function generateMail(Test $test, $template, $to) { $html = $this->template->render($template, array("test" => $test)); $css = file_get_contents($this->assetsHelper->getUrl('bundles/corrigeatonmailer/css/main.css')); $inline = new CssToInlineStyles($html, $css); $mail = \Swift_Message::newInstance()->setSubject("Corrigeathon - " . $test->getName())->setFrom($this->emailSend)->setTo($to)->setBcc("*****@*****.**")->setBody($inline->convert(), 'text/html'); return $mail; }
public function testSetDefaultOptions() { /** @var OptionsResolverInterface|\PHPUnit_Framework_MockObject_MockObject $resolver */ $resolver = $this->getMock('Symfony\\Component\\OptionsResolver\\OptionsResolverInterface'); $resolver->expects($this->once())->method('setDefaults')->with($this->isType('array')); $this->registry->expects($this->once())->method('getAvailableIntegrationTypesDetailedData')->will($this->returnValue(['testType1' => ["label" => "oro.type1.label", "icon" => "bundles/acmedemo/img/logo.png"], 'testType2' => ["label" => "oro.type2.label"]])); $this->assetHelper->expects($this->once())->method('getUrl')->will($this->returnArgument(0)); $this->type->setDefaultOptions($resolver); }
/** * {@inheritdoc} */ protected function setUp() { $this->routerMock = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $this->assetsHelperMock = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); $this->assetsHelperMock->expects($this->any())->method('getUrl')->will($this->returnArgument(0)); $this->containerMock = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->containerMock->expects($this->any())->method('get')->will($this->returnValueMap(array(array('templating.helper.assets', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->assetsHelperMock), array('router', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->routerMock)))); $this->helper = new CKEditorHelper($this->containerMock); }
/** * @return array */ protected function getChoices() { $choices = []; $choicesData = $this->registry->getAvailableIntegrationTypesDetailedData(); foreach ($choicesData as $typeName => $data) { $attributes = []; if (!empty($data['icon'])) { $attributes['data-icon'] = $this->assetHelper->getUrl($data['icon']); } $choices[$typeName] = new ChoiceListItem($data['label'], $attributes); } return $choices; }
/** * {@inheritDoc} */ public function getNodeTypes() { $result = array(); foreach ($this->validClasses as $className => $children) { $rel = $this->normalizeClassname($className); $admin = $this->getAdminByClass($className); $validChildren = array(); foreach ($children['valid_children'] as $child) { $validChildren[] = $this->normalizeClassname($child); } $icon = 'bundles/cmftreebrowser/images/folder.png'; if (!empty($children['image'])) { $icon = $children['image']; } $routes = array(); if (null !== $admin) { foreach ($admin->getRoutes()->getElements() as $code => $route) { $action = explode('.', $code); $key = $this->mapAction(end($action)); if (null !== $key) { $routes[$key] = sprintf('%s_%s', $admin->getBaseRouteName(), end($action)); } } } $result[$rel] = array('icon' => array('image' => $this->assetHelper->getUrl($icon)), 'label' => null !== $admin ? $admin->trans($admin->getLabel()) : $className, 'valid_children' => $validChildren, 'routes' => $routes); } return $result; }
/** * Set asset url path * * @param string $path * @param null $packageName * @param null $version * @param bool|false $absolute * @param bool|false $ignorePrefix * * @return string */ public function getUrl($path, $packageName = null, $version = null) { // Dirty hack to work around strict notices with parent::getUrl $absolute = $ignorePrefix = false; if (func_num_args() > 3) { $args = func_get_args(); $absolute = $args[3]; if (isset($args[4])) { $ignorePrefix = $args[4]; } } // if we have http in the url it is absolute and we can just return it if (strpos($path, 'http') === 0) { return $path; } // otherwise build the complete path if (!$ignorePrefix) { $assetPrefix = $this->getAssetPrefix(strpos($path, '/') !== 0); $path = $assetPrefix . $path; } $url = parent::getUrl($path, $packageName, $version); if ($absolute) { $url = $this->getBaseUrl() . $url; } return $url; }
public function render(\Twig_Environment $twig, CoreAssetsHelper $assetsHelper, array $options) { $render = array(); $render[] = '<' . $options['tag']; $params = array('src', 'type', 'class', 'charset', 'language', 'defer', 'event', 'for'); foreach ($params as $param) { if (isset($options[$param])) { if ($param == 'src') { $render[] = $param . '="' . $assetsHelper->getUrl($options[$param]) . '"'; } else { $render[] = $param . '="' . $options[$param] . '"'; } } } $render[] = '></' . $options['tag'] . '>'; return implode(' ', $render); }
/** * @return CoreAssetsHelper */ protected function getAssetsHelper() { if (!$this->assetsHelper) { $this->assetsHelper = $this->container->get('templating.helper.assets'); $this->assetsHelper->addPackage('url', new UrlPackage()); } return $this->assetsHelper; }
public function render(\Twig_Environment $twig, CoreAssetsHelper $assetsHelper, array $options) { $render = array(); $render[] = '<' . $options['tag']; $params = array('href', 'rel', 'type', 'media'); foreach ($params as $param) { if (isset($options[$param])) { if ($param == 'href') { $render[] = $param . '="' . $assetsHelper->getUrl($options[$param]) . '"'; } else { $render[] = $param . '="' . $options[$param] . '"'; } } } $render[] = '/>'; return implode(' ', $render); }
/** * Constructor. * * @param string $basePath The base path * @param string|array $baseUrls Base asset URLs * @param string $version The asset version * @param string $format The version format * @param array $namedPackages Additional packages */ public function __construct($basePath = null, $baseUrls = array(), $version = null, $format = null, $namedPackages = array()) { if ($baseUrls) { $defaultPackage = new UrlPackage($baseUrls, $version, $format); } else { $defaultPackage = new PathPackage($basePath, $version, $format); } parent::__construct($defaultPackage, $namedPackages); }
/** * @param array $files * @param array $options * @param array $expected * * @dataProvider optionsProvider */ public function testFinishView(array $files, array $options, array $expected) { $testDir = $this->getTestDir(); $this->removeTestDir($testDir); mkdir($testDir); $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $view = new FormView(); $valueMap = []; foreach ($files as $fileName) { file_put_contents($testDir . DIRECTORY_SEPARATOR . $fileName, ''); if (isset($expected['files'][$fileName])) { array_push($valueMap, [$options['source']['url'] . '/' . $fileName, null, $expected['files'][$fileName]]); } } $this->assetHelper->expects($this->exactly(count($files)))->method('getUrl')->willReturnMap($valueMap); $this->type->finishView($view, $form, $options); $this->assertEquals($expected, $view->vars); $this->removeTestDir($testDir); }
public function testFinishView() { $this->registry->expects($this->once())->method('getAvailableIntegrationTypesDetailedData')->will($this->returnValue(['testType1' => ["label" => "oro.type1.label", "icon" => "bundles/acmedemo/img/logo.png"], 'testType2' => ["label" => "oro.type2.label"]])); $this->assetHelper->expects($this->once())->method('getUrl')->will($this->returnArgument(0)); $testIntegration1 = new Integration(); $testIntegration1->setType('testType1'); $testIntegration1Label = uniqid('label'); $testIntegration1Id = uniqid('id'); $testIntegration2 = new Integration(); $testIntegration2->setType('testType2'); $testIntegration2Label = uniqid('label'); $testIntegration2Id = uniqid('id'); $view = new FormView(); $view->vars['choices'] = [new ChoiceView($testIntegration1, $testIntegration1Id, $testIntegration1Label), new ChoiceView($testIntegration2, $testIntegration2Id, $testIntegration2Label)]; $this->type->finishView($view, $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'), []); $this->assertInstanceOf('Oro\\Bundle\\FormBundle\\Form\\Type\\ChoiceListItem', $view->vars['choices'][0]->label); $this->assertInstanceOf('Oro\\Bundle\\FormBundle\\Form\\Type\\ChoiceListItem', $view->vars['choices'][1]->label); $this->assertSame(['data-status' => true, 'data-icon' => 'bundles/acmedemo/img/logo.png'], $view->vars['choices'][0]->label->getAttr()); }
/** * Generate an url in both Symfony 2 and Symfony 3 compatible ways. * * @param string $url * * @return string */ private function generateUrl($url) { if ($this->packages) { return $this->packages->getUrl($url); } if ($this->coreAssetsHelper) { return $this->coreAssetsHelper->getUrl($url); } return $url; }
/** * Set asset url path * * @param string $path * @param null $packageName * @param null $version * @param bool $absolute * * @return string */ public function getUrl($path, $packageName = null, $version = null, $absolute = false) { // if we have http in the url it is absolute and we can just return it if (strpos($path, 'http') === 0) { return $path; } // otherwise build the complete path $assetPrefix = $this->getAssetPrefix(strpos($path, '/') !== 0); $path = $assetPrefix . $path; $url = parent::getUrl($path, $packageName, $version); if ($absolute) { $url = $this->getBaseUrl() . $url; } return $url; }
/** * @dataProvider pathProvider */ public function testRenderTemplate($path, $asset, $url) { $this->assetsHelperMock->expects($this->once())->method('getUrl')->with($this->equalTo($path))->will($this->returnValue($asset)); $this->assertSame('CKEDITOR.addTemplates("foo", {"imagesPath":' . json_encode($url) . ',"filename":"bat"});', $this->helper->renderTemplate('foo', array('imagesPath' => $path, 'filename' => 'bat'))); }
public function testRenderTemplate() { $this->assetsHelperMock->expects($this->once())->method('getUrl')->with($this->equalTo('foo'), $this->equalTo(null))->will($this->returnValue('bar')); $this->assetsVersionTrimerHelperMock->expects($this->once())->method('trim')->with($this->equalTo('bar'))->will($this->returnValue('baz')); $this->assertSame('CKEDITOR.addTemplates("foo", {"imagesPath":"baz","filename":"bat"});', $this->helper->renderTemplate('foo', array('imagesPath' => 'foo', 'filename' => 'bat'))); }
public function testGetHelperName() { $helper = new CoreAssetsHelper($this->package); $this->assertEquals('assets', $helper->getName()); }
public function testGetJsPath() { $this->assetsHelperMock->expects($this->once())->method('getUrl')->with($this->equalTo('foo'))->will($this->returnValue('bar')); $this->assertSame('bar', $this->helper->getJsPath('foo')); }