Skip to content

Commit

Permalink
Adding new Configure::$App['www_root']
Browse files Browse the repository at this point in the history
Helper::webroot(); will now check for theme assets in APP/webroot/theme/<theme_name>/
Adding ico key to Media::$mimeType;
Fixed bug in previous commits that would not use views/themed/<theme_name>/layouts/ from a plugin
Adding test cases for Helper::webroot();
Adding more tests for ThemeView.
  • Loading branch information
phpnut committed Nov 26, 2009
1 parent 3907893 commit 903a1fd
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cake/libs/configure.php
Expand Up @@ -390,7 +390,7 @@ function __loadBootstrap($boot) {
$libPaths = $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null;

if ($boot) {
Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));

if (!include(CONFIGS . 'core.php')) {
trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
Expand Down
25 changes: 18 additions & 7 deletions cake/libs/view/helper.php
Expand Up @@ -201,17 +201,28 @@ function webroot($file) {
$asset = explode('?', $file);
$asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
$webPath = "{$this->webroot}" . $asset[0];
$file = $asset[0];

if (!empty($this->theme)) {
$viewPaths = App::path('views');
$file = trim($file, '/');
$theme = $this->theme . '/';

foreach ($viewPaths as $viewPath) {
$path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $asset[0];
$theme = $this->theme . '/';
if (DS === '\\') {
$file = str_replace('/', '\\', $file);
}

if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) {
$webPath = "{$this->webroot}theme/" . $theme . $asset[0];
} else {
$viewPaths = App::path('views');

if (file_exists($path)) {
$webPath = "{$this->webroot}theme/" . $theme . $asset[0];
break;
foreach ($viewPaths as $viewPath) {
$path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $file;

if (file_exists($path)) {
$webPath = "{$this->webroot}theme/" . $theme . $asset[0];
break;
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions cake/libs/view/media.php
Expand Up @@ -35,11 +35,11 @@ class MediaView {
'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset',
'flv' => 'video/x-flv', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip',
'bz2' => 'application/x-bzip', '7z' => 'application/x-7z-compressed', 'hdf' => 'application/x-hdf',
'hqx' => 'application/mac-binhex40', 'ips' => 'application/x-ipscript', 'ipx' => 'application/x-ipix',
'js' => 'application/x-javascript', 'latex' => 'application/x-latex', 'lha' => 'application/octet-stream',
'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream', 'man' => 'application/x-troff-man',
'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif', 'ms' => 'application/x-troff-ms',
'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf',
'hqx' => 'application/mac-binhex40', 'ico' => 'image/vnd.microsoft.icon', 'ips' => 'application/x-ipscript',
'ipx' => 'application/x-ipix', 'js' => 'application/x-javascript', 'latex' => 'application/x-latex',
'lha' => 'application/octet-stream', 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream',
'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif',
'ms' => 'application/x-troff-ms', 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf',
'pgn' => 'application/x-chess-pgn', 'pot' => 'application/mspowerpoint', 'pps' => 'application/mspowerpoint',
'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'pre' => 'application/x-freelance',
'prt' => 'application/pro_eng', 'ps' => 'application/postscript', 'roff' => 'application/x-troff',
Expand Down
3 changes: 1 addition & 2 deletions cake/libs/view/theme.php
Expand Up @@ -60,9 +60,8 @@ function _paths($plugin = null, $cached = true) {
&& strpos($paths[$i], DS . $plugin . DS) === false) {
if ($plugin) {
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS;
} else {
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
}
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
}
}
$paths = array_merge($themePaths, $paths);
Expand Down
38 changes: 38 additions & 0 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -663,6 +663,44 @@ function testMultiDimensionalField() {
$result = $this->Helper->value('My.title');
$this->assertEqual($result,'My Title');
}

function testWebrootPaths() {
$this->Helper->webroot = '/';
$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/img/cake.power.gif';
$this->assertEqual($result, $expected);

$this->Helper->theme = 'test_theme';

App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));

$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/theme/test_theme/img/cake.power.gif';
$this->assertEqual($result, $expected);

$result = $this->Helper->webroot('/img/test.jpg');
$expected = '/theme/test_theme/img/test.jpg';
$this->assertEqual($result, $expected);

$webRoot = Configure::read('App.www_root');
Configure::write('App.www_root', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'webroot' . DS);

$result = $this->Helper->webroot('/img/cake.power.gif');
$expected = '/theme/test_theme/img/cake.power.gif';
$this->assertEqual($result, $expected);

$result = $this->Helper->webroot('/img/test.jpg');
$expected = '/theme/test_theme/img/test.jpg';
$this->assertEqual($result, $expected);

$result = $this->Helper->webroot('/img/cake.icon.gif');
$expected = '/img/cake.icon.gif';
$this->assertEqual($result, $expected);

Configure::write('App.www_root', $webRoot);
}

}
?>
8 changes: 6 additions & 2 deletions cake/tests/cases/libs/view/theme.test.php
Expand Up @@ -211,8 +211,12 @@ function testPluginThemedGetTemplate() {
$result = $ThemeView->getViewFileName('index');
$this->assertEqual($result, $expected);

$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'plugins' . DS . 'test_plugin' . DS . 'layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName();
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'plugins' . DS . 'test_plugin' . DS . 'layouts' . DS .'plugin_default.ctp';
$result = $ThemeView->getLayoutFileName('plugin_default');
$this->assertEqual($result, $expected);

$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'layouts' . DS .'default.ctp';
$result = $ThemeView->getLayoutFileName('default');
$this->assertEqual($result, $expected);
}

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 903a1fd

Please sign in to comment.