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');
|
2021-10-06 12:52:46 +03:00
|
|
|
const configUtils = require('../../../utils/configUtils');
|
|
|
|
const asset = require('../../../../core/frontend/helpers/asset');
|
|
|
|
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 () {
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = asset('favicon.ico');
|
2014-10-10 18:54:07 +04:00
|
|
|
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 () {
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = 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
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = asset('favicon.png');
|
2017-01-26 21:01:19 +03:00
|
|
|
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
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = asset('favicon.ico');
|
2017-01-26 21:01:19 +03:00
|
|
|
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 = '';
|
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = 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 () {
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = asset('js/asset.js');
|
2014-10-10 18:54:07 +04:00
|
|
|
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 () {
|
2021-10-04 18:30:54 +03:00
|
|
|
rendered = asset('js/asset.js', {hash: {hasMinFile: true}});
|
2017-04-10 12:30:21 +03:00
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/assets/js/asset.min.js?v=abc');
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
2021-11-03 13:19:56 +03:00
|
|
|
|
|
|
|
describe('different admin and site urls', function () {
|
|
|
|
before(function () {
|
|
|
|
configUtils.set({url: 'http://127.0.0.1'});
|
|
|
|
configUtils.set({'admin:url': 'http://localhost'});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles favicon correctly', function () {
|
|
|
|
rendered = asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('http://127.0.0.1/favicon.ico');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles ghost.css for default templates correctly', function () {
|
|
|
|
rendered = asset('public/ghost.css');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('http://127.0.0.1/public/ghost.css?v=abc');
|
|
|
|
});
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|