/** * Tests generate. */ public function testGenerate() { $manager = new MandrillTemplateManager(); $mustache = $this->getMock('Mustache_Engine', array(), array(), '', false); $mustache->expects($this->once())->method('setPartials')->with($this->equalTo(array('a' => 'a', 'b' => 'b'))); $mustache->expects($this->once())->method('render')->with($this->equalTo('{{> a}}<p>{{name}}</p>{{> b}}'), $this->equalTo(array('name' => 'See Wah')))->will($this->returnValue('a<p>See Wah</p>b')); $cssInliner = $this->getMock('\\TijsVerkoyen\\CssToInlineStyles\\CssToInlineStyles', array(), array(), '', false); $cssInliner->expects($this->once())->method('setHTML')->with($this->equalTo('a<p>See Wah</p>b')); $cssInliner->expects($this->once())->method('setCSS')->with($this->equalTo('body {}' . PHP_EOL . 'a {}')); $cssInliner->expects($this->once())->method('convert')->with($this->equalTo(true))->will($this->returnValue('<STYLE type="text/css"> <![CDATA[ p {} ]]> </style>a<p>See Wah</p>b')); $manager->setMustache($mustache); $manager->setCssInliner($cssInliner); $manager->generate('{{> a}}<p>{{name}}</p>{{> b}}', array('a' => 'a', 'b' => 'b'), array('name' => 'See Wah'), array('body {}', 'a {}'), true); $this->assertEquals('<STYLE type="text/css"> p {} </style>a<p>See Wah</p>b', $manager->getHtml()); }
$templateSpecificConfig = json_decode(file_get_contents($argv[2]), true); $config = array_merge($config, $templateSpecificConfig); if (isset($config["additionalIncludes"])) { $config["includes"] = array_merge($config["includes"], $config["additionalIncludes"]); unset($config["additionalIncludes"]); } if (isset($config["additionalCss"])) { $config["css"] = array_merge($config["css"], $config["additionalCss"]); unset($config["additionalCss"]); } // publish status $publishStatus = $argv[3]; if ($publishStatus != 'live' && $publishStatus != 'draft') { echo 'third arg must be either live or draft'; exit; } // template name suffix $suffix = count($argv) > 4 ? $argv[4] : ''; // preparing final partials(includes) and css list $includes = array_map(function ($item) { global $config; return file_get_contents($config["includeBaseDir"] . $item); }, $config["includes"]); $css = array_map(function ($item) { global $config; return file_get_contents($config["cssBaseDir"] . $item); }, $config["css"]); $manager->generate($template, $includes, $config, $css); $manager->save('output.html'); // we are not actually required to save before publishing to mandrill $manager->publish($config['mandrillApiKey'], $config['templateName'] . $suffix, $config['fromEmail'], $config['fromName'], $config['subject'], $publishStatus == 'live');