Esempio n. 1
0
 public function testProcessTranslationsEnableKey()
 {
     $language = CMTest_TH::createLanguage('test');
     $languageKey = CM_Model_LanguageKey::create('Hello World');
     $this->assertSame(false, $languageKey->getJavascript());
     $site = CM_Site_Abstract::factory();
     $render = new CM_Frontend_Render(new CM_Frontend_Environment(null, null, $language));
     // Check that key is *not* included in the JS translations list
     $versionJavascript = CM_Model_Language::getVersionJavascript();
     $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js"));
     $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertNotContains('Hello World', $response->getContent());
     // Request JS-enabling of language key via RPC call
     $body = CM_Params::jsonEncode(['method' => 'CM_Model_Language.requestTranslationJs', 'params' => ['Hello World']]);
     $request = new CM_Http_Request_Post('/rpc', null, null, $body);
     $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     CMTest_TH::reinstantiateModel($languageKey);
     $this->assertSame(true, $languageKey->getJavascript());
     // Check that key *is* included in the JS translations list
     $versionJavascript = CM_Model_Language::getVersionJavascript();
     $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js"));
     $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertContains('Hello World', $response->getContent());
 }
Esempio n. 2
0
 public function testCaching()
 {
     $debug = new CM_Debug(true);
     $flag = '<img class="flag" src="' . $this->_render->getUrlResource('layout', 'img/flags/fo.png') . '" title="countryFoo" />';
     $expected = '<span class="function-location contains-flag">cityFoo, stateFoo, countryFoo' . $flag . '</span>';
     $this->_assertSame($expected, array('location' => $this->_location));
     $debug->setEnabled(false);
     $this->assertEmpty($debug->getStats());
 }
Esempio n. 3
0
 public function getSuggestion($location, CM_Frontend_Render $render)
 {
     $names = array();
     for ($level = $location->getLevel(); $level >= CM_Model_Location::LEVEL_COUNTRY; $level--) {
         $names[] = $location->getName($level);
     }
     return array('id' => CM_Params::jsonEncode($location->toArray()), 'name' => implode(', ', array_filter($names)), 'img' => $render->getUrlResource('layout', 'img/flags/' . strtolower($location->getAbbreviation(CM_Model_Location::LEVEL_COUNTRY)) . '.png'));
 }
Esempio n. 4
0
 public function testProcess()
 {
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $request = new CM_Http_Request_Get($render->getUrlResource('library-css', 'all.css'));
     $response = new CM_Http_Response_Resource_Css_Library($request, $this->getServiceManager());
     $response->process();
     $this->assertContains('body{', $response->getContent());
 }
Esempio n. 5
0
 public function testProcessTranslations()
 {
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $request = new CM_Http_Request_Get($render->getUrlResource('library-js', 'translations/123.js'));
     $response = new CM_Http_Response_Resource_Javascript_Library($request, $this->getServiceManager());
     $response->process();
     $this->assertContains('cm.language.setAll', $response->getContent());
 }
Esempio n. 6
0
 public function testProcess()
 {
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $url = $render->getUrlResource('layout', 'img/logo.png', ['root' => true]);
     $this->assertSame(1, substr_count(parse_url($url, PHP_URL_PATH), '/'));
     $request = $this->createRequest($url);
     $response = $this->processRequest($request);
     $this->assertContains('Content-Type: image/png', $response->getHeaders());
 }
Esempio n. 7
0
 public function testProcessAfterBody()
 {
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $request = new CM_Http_Request_Get($render->getUrlResource('vendor-js', 'after-body.js'));
     $response = new CM_Http_Response_Resource_Javascript_Vendor($request, $this->getServiceManager());
     $response->process();
     $this->assertContains('function()', $response->getContent());
     $this->assertContains('jQuery', $response->getContent());
 }
Esempio n. 8
0
 public function testRenderCrossSite()
 {
     $smarty = new Smarty();
     $render = new CM_Frontend_Render();
     $siteOther = $this->getMockSite('CM_Site_Abstract', null, ['urlCdn' => 'http://cdn.other.com']);
     $renderOther = new CM_Frontend_Render(new CM_Frontend_Environment($siteOther));
     $template = $smarty->createTemplate('string:');
     $template->assignGlobal('render', $render);
     $this->assertContains($renderOther->getUrlResource('layout', 'img/foo.png'), smarty_function_img(['path' => 'foo.png', 'site' => $siteOther], $template));
 }
Esempio n. 9
0
 public function testProcess()
 {
     $site = CM_Site_Abstract::factory();
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $request = new CM_Http_Request_Get($render->getUrlResource('library-css', 'all.css'));
     $response = CM_Http_Response_Resource_Css_Library::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertContains('Cache-Control: max-age=31536000', $response->getHeaders());
     $this->assertContains('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 31536000), $response->getHeaders());
     $this->assertContains('body{', $response->getContent());
 }
Esempio n. 10
0
 public function testRenderCrossSite()
 {
     $smarty = new Smarty();
     $render = new CM_Frontend_Render();
     $siteOther = $this->getMockSite('CM_Site_Abstract', null, ['urlCdn' => 'http://cdn.other.com']);
     $renderOther = new CM_Frontend_Render(new CM_Frontend_Environment($siteOther));
     $template = $smarty->createTemplate('string:');
     $template->assignGlobal('render', $render);
     $this->assertSame($renderOther->getUrlResource('layout', 'foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'layout', 'site' => $siteOther), $template));
     $this->assertSame($renderOther->getUrlStatic('foo'), smarty_function_resourceUrl(array('path' => 'foo', 'type' => 'static', 'site' => $siteOther), $template));
 }
Esempio n. 11
0
 public function testProcessAfterBody()
 {
     $site = CM_Site_Abstract::factory();
     $render = new CM_Frontend_Render(new CM_Frontend_Environment());
     $request = new CM_Http_Request_Get($render->getUrlResource('vendor-js', 'after-body.js'));
     $response = CM_Http_Response_Resource_Javascript_Vendor::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertContains('Cache-Control: max-age=31536000', $response->getHeaders());
     $this->assertContains('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 31536000), $response->getHeaders());
     $this->assertContains('function()', $response->getContent());
     $this->assertContains('jQuery', $response->getContent());
 }
Esempio n. 12
0
    public function testBackgroundImage()
    {
        $render = new CM_Frontend_Render();
        $css = new CM_Asset_Css($render, "body { background-image: image('icon/mailbox_read.png'); }");
        $url = $render->getUrlResource('layout', 'img/icon/mailbox_read.png');
        $expected = <<<EOD
body {
  background-image: url('{$url}');
}
EOD;
        $this->assertEquals($expected, $css->get());
    }
Esempio n. 13
0
 public function testNonexistentFile()
 {
     $site = $this->getMockSite();
     $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
     $url = $render->getUrlResource('layout', 'nonExistent.css');
     $request = new CM_Http_Request_Get($url, ['host' => $site->getHost()]);
     try {
         $this->processRequest($request);
     } catch (CM_Exception_Nonexistent $ex) {
         $this->assertSame('Invalid filename', $ex->getMessage());
         $this->assertSame(['path' => '/nonExistent.css'], $ex->getMetaInfo());
     }
 }
Esempio n. 14
0
 /**
  * @param CM_Frontend_Render $render
  * @return array
  */
 private function _getEmoticonData(CM_Frontend_Render $render)
 {
     $cacheKey = CM_CacheConst::Usertext_Filter_EmoticonList . '_fixedHeight:' . (string) $this->_fixedHeight;
     $cache = CM_Cache_Local::getInstance();
     if (($emoticons = $cache->get($cacheKey)) === false) {
         $emoticons = array('codes' => array(), 'htmls' => array());
         $fixedHeight = '';
         if (null !== $this->_fixedHeight) {
             $fixedHeight = ' height="' . $this->_fixedHeight . '"';
         }
         /** @var CM_Emoticon $emoticon */
         foreach (new CM_Paging_Emoticon_All() as $emoticon) {
             foreach ($emoticon->getCodes() as $code) {
                 $emoticons['codes'][] = $code;
                 $emoticons['htmls'][] = '<img src="' . $render->getUrlResource('layout', 'img/emoticon/' . $emoticon->getFileName()) . '" class="emoticon emoticon-' . $emoticon->getName() . '" title="' . $emoticon->getDefaultCode() . '"' . $fixedHeight . ' />';
             }
         }
         $cache->set($cacheKey, $emoticons);
     }
     return $emoticons;
 }
Esempio n. 15
0
 public function testGetUrlResourceDifferentSite()
 {
     $render = new CM_Frontend_Render();
     $site = $this->getMockSite('CM_Site_Abstract', null, ['urlCdn' => 'http://cdn.other.com']);
     $siteType = $site->getType();
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $this->assertSame('http://cdn.other.com/layout/' . $siteType . '/' . $deployVersion . '/foo/bar.jpg', $render->getUrlResource('layout', 'foo/bar.jpg', null, $site));
 }
Esempio n. 16
0
 public function testGetUrlResourceWithoutCdn()
 {
     $site = $this->getMockBuilder('CM_Site_Abstract')->setMethods(array('getType', 'getUrlCdn'))->getMockForAbstractClass();
     $site->expects($this->any())->method('getType')->will($this->returnValue(12));
     $site->expects($this->any())->method('getUrlCdn')->will($this->returnValue(null));
     /** @var CM_Site_Abstract $site */
     $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $this->assertSame('http://www.default.dev/layout/' . $site->getType() . '/' . $deployVersion . '/foo.jpg', $render->getUrlResource('layout', 'foo.jpg'));
 }