public function testFiles() { $timestamp = '200000'; $templateId = 5; $shopId = 4; $templateMock = $this->createTemplateMock($templateId); $shopMock = $this->createShopMock($shopId, $templateMock); $filenameHash = $timestamp . '_' . md5($timestamp . $templateId . $shopId . \Shopware::REVISION); $expected = '/my/root/dir/web/cache/' . $filenameHash . '.css'; $this->assertEquals($expected, $this->pathResolver->getCssFilePath($shopMock, $timestamp)); $expected = '/my/root/dir/web/cache/' . $filenameHash . '.js'; $this->assertEquals($expected, $this->pathResolver->getJsFilePath($shopMock, $timestamp)); }
/** * Compiles all required resources for the passed shop and template. * The function compiles all theme and plugin less files and * compresses the theme and plugin javascript and css files * into one file. * * @param $timestamp * @param Shop\Template $template * @param Shop\Shop $shop * @throws \Exception */ public function compileLess($timestamp, Shop\Template $template, Shop\Shop $shop) { if ($shop->getMain()) { $shop = $shop->getMain(); } $file = $this->pathResolver->getCssFilePath($shop, $timestamp); $file = new \SplFileObject($file, "a"); if (!$file->flock(LOCK_EX)) { return; } $file->ftruncate(0); $this->compiler->setConfiguration($this->getCompilerConfiguration($shop)); $config = $this->getConfig($template, $shop); $this->compiler->setVariables($config); $definitions = $this->collectLessDefinitions($template, $shop); foreach ($definitions as $definition) { $this->compileLessDefinition($shop, $definition); } $css = $this->compiler->get(); $this->compiler->reset(); $success = $file->fwrite($css); if ($success === null) { throw new \RuntimeException("Could not write to " . $file->getPath()); } $file->flock(LOCK_UN); // release the lock }