/** * The xCSS processor itself. * * @param sfWebRequest $request * * @return string */ public function execute($request) { // we do not care, whether this is a valid CSS file here $this->requestedCSSFile = $request->getParameter('file'); $targetFile = sfXCSSTools::getCacheOutputDirectory() . $this->requestedCSSFile; // because we cache the generated files, we check for an existing one if (file_exists($targetFile) === false) { $config = sfXCSSPluginConfiguration::getXCSSConfiguration(true); $config['xCSS_files'] = array($this->requestedCSSFile => $targetFile); $xCSS = new xCSS($config); $xCSS->compile(); } $this->xcss = file_get_contents($targetFile); chmod($targetFile, 0666); return sfView::SUCCESS; }
<?php require_once dirname(__FILE__) . '/../../bootstrap/functional.php'; $browser = new sfTestFunctional(new sfBrowser()); $limeTest = $browser->test(); $limeTest->plan = 14; $cacheDir = sfXCSSTools::getCacheOutputDirectory(); $filename = 'style.css'; $limeTest->ok(!file_exists($cacheDir), 'Cache dir does not exist.'); $limeTest->ok(!empty($cacheDir), 'Cache dir configured.'); $limeTest->ok(sfXCSSTools::createCacheDirectory(), 'Cache dir created.'); $limeTest->ok(is_writable($cacheDir), 'Cache dir writable.'); $limeTest->ok(rmdir($cacheDir), 'Cache dir removed.'); // case: disabled web caching sfConfig::set('app_xcssplugin_saveforweb', false); try { sfXCSSTools::saveForWeb($filename, 'some css'); $limeTest->fail('Exception not thrown.'); } catch (RuntimeException $e) { $limeTest->is($e->getMessage(), sfXCSSTools::EXCEPTION_SAVE_FOR_WEB_DISABLED, 'Exception caught.'); } // case: enabled web caching, but wrong permissions sfConfig::set('app_xcssplugin_saveforweb', 'tmp'); $folder = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'tmp'; $limeTest->ok(mkdir($folder, 00), 'Save For Web dir not writable.'); try { sfXCSSTools::saveForWeb($filename, 'some css'); $limeTest->fail('Exception not thrown.'); } catch (RuntimeException $e) { $limeTest->is($e->getMessage(), sfXCSSTools::EXCEPTION_COULD_NOT_CREATE_SAVE_FOR_WEB_DIR, 'Exception caught.'); }