mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
35e3e0708c
- The proxy is not a helper, we want the helpers folder to only include helpers - The proxy is also meant to be the interface to Ghost for the helpers, and we want to enforce that - This is a small step on the way
92 lines
3.1 KiB
JavaScript
92 lines
3.1 KiB
JavaScript
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
helpers = require('../../../core/frontend/helpers'),
|
|
proxy = require('../../../core/frontend/services/proxy'),
|
|
settingsCache = proxy.settingsCache;
|
|
|
|
describe('{{ghost_foot}} helper', function () {
|
|
var settingsCacheStub;
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
beforeEach(function () {
|
|
settingsCacheStub = sinon.stub(settingsCache, 'get');
|
|
});
|
|
|
|
it('outputs global injected code', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
should.exist(rendered);
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
});
|
|
|
|
it('outputs post injected code', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
|
|
|
const rendered = helpers.ghost_foot({
|
|
data: {
|
|
root: {
|
|
post: {
|
|
codeinjection_foot: 'post-codeinjection'
|
|
}
|
|
}
|
|
}
|
|
});
|
|
should.exist(rendered);
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
rendered.string.should.match(/post-codeinjection/);
|
|
});
|
|
|
|
it('handles post injected code being null', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
|
|
|
const rendered = helpers.ghost_foot({
|
|
data: {
|
|
root: {
|
|
post: {
|
|
codeinjection_foot: null
|
|
}
|
|
}
|
|
}
|
|
});
|
|
should.exist(rendered);
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
|
});
|
|
|
|
it('handles post injected code being empty', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns('<script>var test = \'I am a variable!\'</script>');
|
|
|
|
const rendered = helpers.ghost_foot({
|
|
data: {
|
|
root: {
|
|
post: {
|
|
codeinjection_foot: ''
|
|
}
|
|
}
|
|
}
|
|
});
|
|
should.exist(rendered);
|
|
rendered.string.should.match(/<script>var test = 'I am a variable!'<\/script>/);
|
|
rendered.string.should.not.match(/post-codeinjection/);
|
|
});
|
|
|
|
it('handles global empty code injection', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns('');
|
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
should.exist(rendered);
|
|
rendered.string.should.eql('');
|
|
});
|
|
|
|
it('handles global undefined code injection', function () {
|
|
settingsCacheStub.withArgs('ghost_foot').returns(undefined);
|
|
|
|
const rendered = helpers.ghost_foot({data: {}});
|
|
should.exist(rendered);
|
|
rendered.string.should.eql('');
|
|
});
|
|
});
|