/** * Tests publish - existing template. */ public function testPublishExistingTemplate() { $manager = new MandrillTemplateManager(); $manager->setHtml('<p>Read this now!</p>'); $service = $this->getMock('Mandrill_Templates', array(), array(), '', false); $service->expects($this->once())->method('getList')->will($this->returnValue(array(array('name' => 'my fav template')))); $service->expects($this->once())->method('update')->with($this->equalTo('my fav template'), $this->equalTo('*****@*****.**'), $this->equalTo('Mr C'), $this->equalTo('Amazing subject...'), $this->equalTo('<p>Read this now!</p>'), $this->equalTo(''), $this->equalTo(true)); $service->expects($this->never())->method('add'); $manager->setMandrillTemplatesService($service); $manager->publish('my_key', 'my fav template', '*****@*****.**', 'Mr C', 'Amazing subject...', true); }
<?php // usage: php example.php welcome.mustache welcome.json live|draft .staging require dirname(__FILE__) . '/../vendor/autoload.php'; use SeeWah\MandrillTemplateManager\MandrillTemplateManager; $manager = new MandrillTemplateManager(); // global config $config = json_decode(file_get_contents(dirname(__FILE__) . '/config.json'), true); // template file $template = file_get_contents($argv[1]); // template-specific config $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) {