public function javascript($file)
 {
     if (!$this->isURL($file)) {
         if (!Director::fileExists($file)) {
             $file = $this->findRequirementFile($file, "js");
         }
     }
     return parent::javascript($file);
 }
 public function testExternalUrls()
 {
     $backend = new Requirements_Backend();
     $backend->setCombinedFilesEnabled(true);
     $backend->javascript('http://www.mydomain.com/test.js');
     $backend->javascript('https://www.mysecuredomain.com/test.js');
     $backend->javascript('//scheme-relative.example.com/test.js');
     $backend->css('http://www.mydomain.com/test.css');
     $backend->css('https://www.mysecuredomain.com/test.css');
     $backend->css('//scheme-relative.example.com/test.css');
     $html = $backend->includeInHTML(false, self::$html_template);
     $this->assertTrue(strpos($html, 'http://www.mydomain.com/test.js') !== false, 'Load external javascript URL');
     $this->assertTrue(strpos($html, 'https://www.mysecuredomain.com/test.js') !== false, 'Load external secure javascript URL');
     $this->assertTrue(strpos($html, '//scheme-relative.example.com/test.js') !== false, 'Load external scheme-relative javascript URL');
     $this->assertTrue(strpos($html, 'http://www.mydomain.com/test.css') !== false, 'Load external CSS URL');
     $this->assertTrue(strpos($html, 'https://www.mysecuredomain.com/test.css') !== false, 'Load external secure CSS URL');
     $this->assertTrue(strpos($html, '//scheme-relative.example.com/test.css') !== false, 'Load scheme-relative CSS URL');
 }
 function testRequirementsBackend()
 {
     $backend = new Requirements_Backend();
     $backend->javascript(SAPPHIRE_DIR . '/tests/forms/a.js');
     $this->assertTrue(count($backend->get_javascript()) == 1, "There should be only 1 file included in required javascript.");
     $this->assertTrue(in_array(SAPPHIRE_DIR . '/tests/forms/a.js', $backend->get_javascript()), "/test/forms/a.js should be included in required javascript.");
     $backend->javascript(SAPPHIRE_DIR . '/tests/forms/b.js');
     $this->assertTrue(count($backend->get_javascript()) == 2, "There should be 2 files included in required javascript.");
     $backend->block(SAPPHIRE_DIR . '/tests/forms/a.js');
     $this->assertTrue(count($backend->get_javascript()) == 1, "There should be only 1 file included in required javascript.");
     $this->assertFalse(in_array(SAPPHIRE_DIR . '/tests/forms/a.js', $backend->get_javascript()), "/test/forms/a.js should not be included in required javascript after it has been blocked.");
     $this->assertTrue(in_array(SAPPHIRE_DIR . '/tests/forms/b.js', $backend->get_javascript()), "/test/forms/b.js should be included in required javascript.");
     $backend->css(SAPPHIRE_DIR . '/tests/forms/a.css');
     $this->assertTrue(count($backend->get_css()) == 1, "There should be only 1 file included in required css.");
     $this->assertArrayHasKey(SAPPHIRE_DIR . '/tests/forms/a.css', $backend->get_css(), "/tests/forms/a.css should be in required css.");
     $backend->block(SAPPHIRE_DIR . '/tests/forms/a.css');
     $this->assertTrue(count($backend->get_css()) == 0, "There should be nothing in required css after file has been blocked.");
 }
 public function testSuffix()
 {
     $template = '<html><head></head><body><header>My header</header><p>Body</p></body></html>';
     $basePath = $this->getCurrentRelativePath();
     $basePath = 'framework' . substr($basePath, strlen(FRAMEWORK_DIR));
     $backend = new Requirements_Backend();
     $backend->javascript($basePath . '/RequirementsTest_a.js');
     $backend->javascript($basePath . '/RequirementsTest_b.js?foo=bar&bla=blubb');
     $backend->css($basePath . '/RequirementsTest_a.css');
     $backend->css($basePath . '/RequirementsTest_b.css?foo=bar&bla=blubb');
     $backend->set_suffix_requirements(true);
     $html = $backend->includeInHTML(false, $template);
     $this->assertRegexp('/RequirementsTest_a\\.js\\?m=[\\d]*"/', $html);
     $this->assertRegexp('/RequirementsTest_b\\.js\\?m=[\\d]*&amp;foo=bar&amp;bla=blubb"/', $html);
     $this->assertRegexp('/RequirementsTest_a\\.css\\?m=[\\d]*"/', $html);
     $this->assertRegexp('/RequirementsTest_b\\.css\\?m=[\\d]*&amp;foo=bar&amp;bla=blubb"/', $html);
     $backend->set_suffix_requirements(false);
     $html = $backend->includeInHTML(false, $template);
     $this->assertNotContains('RequirementsTest_a.js=', $html);
     $this->assertNotRegexp('/RequirementsTest_a\\.js\\?m=[\\d]*"/', $html);
     $this->assertNotRegexp('/RequirementsTest_b\\.js\\?m=[\\d]*&amp;foo=bar&amp;bla=blubb"/', $html);
     $this->assertNotRegexp('/RequirementsTest_a\\.css\\?m=[\\d]*"/', $html);
     $this->assertNotRegexp('/RequirementsTest_b\\.css\\?m=[\\d]*&amp;foo=bar&amp;bla=blubb"/', $html);
 }
Beispiel #5
0
 function testRequirementsBackend()
 {
     $basePath = $this->getCurrentRelativePath();
     $backend = new Requirements_Backend();
     $backend->javascript($basePath . '/a.js');
     $this->assertTrue(count($backend->get_javascript()) == 1, "There should be only 1 file included in required javascript.");
     $this->assertTrue(in_array($basePath . '/a.js', $backend->get_javascript()), "a.js should be included in required javascript.");
     $backend->javascript($basePath . '/b.js');
     $this->assertTrue(count($backend->get_javascript()) == 2, "There should be 2 files included in required javascript.");
     $backend->block($basePath . '/a.js');
     $this->assertTrue(count($backend->get_javascript()) == 1, "There should be only 1 file included in required javascript.");
     $this->assertFalse(in_array($basePath . '/a.js', $backend->get_javascript()), "a.js should not be included in required javascript after it has been blocked.");
     $this->assertTrue(in_array($basePath . '/b.js', $backend->get_javascript()), "b.js should be included in required javascript.");
     $backend->css($basePath . '/a.css');
     $this->assertTrue(count($backend->get_css()) == 1, "There should be only 1 file included in required css.");
     $this->assertArrayHasKey($basePath . '/a.css', $backend->get_css(), "a.css should be in required css.");
     $backend->block($basePath . '/a.css');
     $this->assertTrue(count($backend->get_css()) == 0, "There should be nothing in required css after file has been blocked.");
 }
 public function javascript($file)
 {
     if (strpos($file, THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php') === 0) {
         return $this->after([$file], THIRDPARTY_DIR . '/jquery/jquery.js', 'javascript');
     }
     return parent::javascript($file);
 }
Beispiel #7
0
 public function testJsWriteToBody()
 {
     $backend = new Requirements_Backend();
     $backend->javascript('http://www.mydomain.com/test.js');
     // Test matching with HTML5 <header> tags as well
     $template = '<html><head></head><body><header>My header</header><p>Body</p></body></html>';
     $backend->set_write_js_to_body(false);
     $html = $backend->includeInHTML(false, $template);
     $this->assertContains('<head><script', $html);
     $backend->set_write_js_to_body(true);
     $html = $backend->includeInHTML(false, $template);
     $this->assertNotContains('<head><script', $html);
     $this->assertContains('</script></body>', $html);
 }