2019-06-18 16:13:55 +03:00
|
|
|
// NOTE: the sole purpose of this suite is to test is it calls through to getAssetUrlHelper
|
|
|
|
// more complicated use cases are tested directly in asset_url.spec
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const configUtils = require('../../utils/configUtils');
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
2021-06-30 16:56:57 +03:00
|
|
|
const settingsCache = require('../../../core/shared/settings-cache');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{asset}} helper', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
let rendered;
|
|
|
|
const localSettingsCache = {};
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
before(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({assetHash: 'abc'});
|
2017-04-10 12:30:21 +03:00
|
|
|
configUtils.set({useMinFiles: true});
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key) {
|
2017-02-03 16:15:11 +03:00
|
|
|
return localSettingsCache[key];
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore();
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('no subdirectory', function () {
|
|
|
|
it('handles favicon correctly', function () {
|
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/favicon.ico');
|
|
|
|
});
|
|
|
|
|
2017-04-04 12:06:38 +03:00
|
|
|
it('handles ghost.css for default templates correctly', function () {
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/ghost.css');
|
2017-04-04 12:06:38 +03:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/public/ghost.css?v=abc');
|
2017-04-04 12:06:38 +03:00
|
|
|
});
|
|
|
|
|
2017-01-26 21:01:19 +03:00
|
|
|
it('handles custom favicon correctly', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.png';
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with png
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.png');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/favicon.png');
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.ico';
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with ico
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/favicon.ico');
|
2017-01-26 21:01:19 +03:00
|
|
|
});
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
it('handles public assets correctly', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '';
|
|
|
|
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/asset.js');
|
2014-10-10 18:54:07 +04:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/public/asset.js?v=abc');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles theme assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/assets/js/asset.js?v=abc');
|
|
|
|
});
|
2017-04-10 12:30:21 +03:00
|
|
|
|
|
|
|
it('handles hasMinFile assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js', {hash: {hasMinFile: true}});
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/assets/js/asset.min.js?v=abc');
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|