diff --git a/core/frontend/helpers/content.js b/core/frontend/helpers/content.js index bea0bd43dd..c1dcfacbb4 100644 --- a/core/frontend/helpers/content.js +++ b/core/frontend/helpers/content.js @@ -4,6 +4,8 @@ // Turns content html into a safestring so that the user doesn't have to // escape it or tell handlebars to leave it alone with a triple-brace. // +// Shows default or custom CTA when trying to see content without access +// // Enables tag-safe truncation of content by characters or words. // // Dev flag feature: In case of restricted content access for member-only posts, shows CTA box @@ -20,7 +22,7 @@ function restrictedCta(options) { accentColor: (options.data.site && options.data.site.accent_color) || '#3db0ef' }); const data = createFrame(options.data); - return templates.execute('content', this, {data}); + return templates.execute('content-cta', this, {data}); } module.exports = function content(options = {}) { diff --git a/core/frontend/helpers/tpl/content.hbs b/core/frontend/helpers/tpl/content-cta.hbs similarity index 100% rename from core/frontend/helpers/tpl/content.hbs rename to core/frontend/helpers/tpl/content-cta.hbs diff --git a/test/unit/helpers/content_spec.js b/test/unit/helpers/content_spec.js index 9b4eaaf7ce..8f0e89e70f 100644 --- a/test/unit/helpers/content_spec.js +++ b/test/unit/helpers/content_spec.js @@ -1,9 +1,21 @@ const should = require('should'); +const hbs = require('../../../core/frontend/services/themes/engine'); +const configUtils = require('../../utils/configUtils'); +const path = require('path'); +const runHelper = data => helpers.navigation.call({}, data); // Stuff we are testing const helpers = require('../../../core/frontend/helpers'); describe('{{content}} helper', function () { + before(function (done) { + hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]}); + + hbs.cachePartials(function () { + done(); + }); + }); + it('renders empty string when null', function () { const html = null; const rendered = helpers.content.call({html: html}); @@ -65,3 +77,55 @@ describe('{{content}} helper', function () { rendered.string.should.equal('

Hello Wo

'); }); }); + +describe('{{content}} helper with no access', function () { + let optionsData; + before(function (done) { + hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]}); + + hbs.cachePartials(function () { + done(); + }); + }); + + beforeEach(function () { + optionsData = { + data: { + site: { + accent_color: '#abcdef' + } + } + }; + }); + + it('can render default template', function () { + const html = 'Hello World'; + const rendered = helpers.content.call({html: html, access: false}, optionsData); + rendered.string.should.containEql('gh-post-upgrade-cta'); + rendered.string.should.containEql('gh-post-upgrade-cta-content'); + rendered.string.should.containEql('"background-color: #abcdef"'); + + should.exist(rendered); + }); +}); + +describe('{{content}} helper with no access', function () { + let optionsData; + before(function (done) { + hbs.express4({partialsDir: [path.resolve(__dirname, './test_tpl')]}); + + hbs.cachePartials(function () { + done(); + }); + }); + + it('can render custom template', function () { + const html = 'Hello World'; + const rendered = helpers.content.call({html: html, access: false}, optionsData); + rendered.string.should.not.containEql('gh-post-upgrade-cta'); + rendered.string.should.containEql('custom-post-upgrade-cta'); + rendered.string.should.containEql('custom-post-upgrade-cta-content'); + + should.exist(rendered); + }); +}); diff --git a/test/unit/helpers/test_tpl/content-cta.hbs b/test/unit/helpers/test_tpl/content-cta.hbs new file mode 100644 index 0000000000..005f268318 --- /dev/null +++ b/test/unit/helpers/test_tpl/content-cta.hbs @@ -0,0 +1,10 @@ +