mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Swapped out usage of stubUrlUtils for configUtils
- stubUrlUtils is now doing the same thing as our existing configUtils but is slightly harder to use - swapped this out, and made stubUrlUtils an internal-only utility
This commit is contained in:
parent
d8c2428094
commit
737d19c78c
6 changed files with 25 additions and 105 deletions
|
@ -1,7 +1,6 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const getPaginatedUrl = require('../../../../core/frontend/meta/paginated_url');
|
||||
const urlUtils = require('../../../utils/urlUtils');
|
||||
const configUtils = require('../../../utils/configUtils');
|
||||
|
||||
describe('getPaginatedUrl', function () {
|
||||
let data;
|
||||
|
@ -125,16 +124,12 @@ describe('getPaginatedUrl', function () {
|
|||
});
|
||||
|
||||
describe('with /blog subdirectory', function () {
|
||||
let sandbox;
|
||||
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/blog'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/blog'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
urlUtils.restore();
|
||||
sandbox.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should calculate correct urls for index', function () {
|
||||
|
|
|
@ -5,7 +5,6 @@ const sinon = require('sinon');
|
|||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
const testUtils = require('../../utils');
|
||||
const testUrlUtils = require('../../utils/urlUtils');
|
||||
const configUtils = require('../../utils/configUtils');
|
||||
const themeEngine = require('../../../core/frontend/services/theme-engine');
|
||||
const models = require('../../../core/server/models');
|
||||
|
@ -306,17 +305,8 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('without Code Injection', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
|
||||
testUrlUtils.stubUrlUtils({url: 'http://localhost:65530/'}, sandbox);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
testUrlUtils.restore();
|
||||
configUtils.set({url: 'http://localhost:65530/'});
|
||||
});
|
||||
|
||||
it('returns meta tag string on paginated index page without structured data and schema', function (done) {
|
||||
|
@ -1286,21 +1276,15 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('with /site subdirectory', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
|
||||
settingsCache.get.withArgs('icon').returns('/content/images/favicon.png');
|
||||
|
||||
testUrlUtils.stubUrlUtils({url: 'http://localhost:65530/site'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65530/site'});
|
||||
|
||||
routing.registry.getRssUrl.returns('http://localhost:65530/site/rss/');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
testUrlUtils.restore();
|
||||
routing.registry.getRssUrl.returns('http://localhost:65530/rss/');
|
||||
});
|
||||
|
||||
|
@ -1324,23 +1308,13 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('with changed origin in config file', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
|
||||
settingsCache.get.withArgs('icon').returns('/content/images/favicon.png');
|
||||
|
||||
configUtils.set({
|
||||
url: 'http://localhost:65530/site',
|
||||
referrerPolicy: 'origin'
|
||||
});
|
||||
|
||||
testUrlUtils.stubUrlUtils({url: 'http://localhost:65530/site'}, sandbox);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
testUrlUtils.restore();
|
||||
});
|
||||
|
||||
it('contains the changed origin', function (done) {
|
||||
|
@ -1361,24 +1335,15 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('with useStructuredData is set to false in config file', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
settingsCache.get.withArgs('icon').returns('/content/images/favicon.png');
|
||||
|
||||
configUtils.set({
|
||||
url: 'http://localhost:65530/',
|
||||
privacy: {
|
||||
useStructuredData: false
|
||||
}
|
||||
});
|
||||
|
||||
testUrlUtils.stubUrlUtils({url: 'http://localhost:65530/'}, sandbox);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
testUrlUtils.restore();
|
||||
});
|
||||
|
||||
it('does not return structured data', function (done) {
|
||||
|
@ -1410,19 +1375,11 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('with Code Injection', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
settingsCache.get.withArgs('icon').returns('/content/images/favicon.png');
|
||||
settingsCache.get.withArgs('codeinjection_head').returns('<style>body {background: red;}</style>');
|
||||
|
||||
testUrlUtils.stubUrlUtils({url: 'http://localhost:65530/'}, sandbox);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
testUrlUtils.restore();
|
||||
configUtils.set({url: 'http://localhost:65530/'});
|
||||
});
|
||||
|
||||
it('returns meta tag plus injected code', function (done) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const urlUtils = require('../../utils/urlUtils');
|
||||
const configUtils = require('../../utils/configUtils');
|
||||
|
||||
// Stuff we are testing
|
||||
const helpers = require('../../../core/frontend/helpers');
|
||||
|
||||
const logging = require('@tryghost/logging');
|
||||
|
||||
describe('{{image}} helper', function () {
|
||||
describe('{{img_url}} helper', function () {
|
||||
let logWarnStub;
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -19,16 +19,12 @@ describe('{{image}} helper', function () {
|
|||
});
|
||||
|
||||
describe('without sub-directory', function () {
|
||||
let sandbox;
|
||||
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should output relative url of image', function () {
|
||||
|
@ -65,7 +61,7 @@ describe('{{image}} helper', function () {
|
|||
logWarnStub.called.should.be.false();
|
||||
});
|
||||
|
||||
it('should have no output if the image attributeis not provided (with warning)', function () {
|
||||
it('should have no output if the image attribute is not provided (with warning)', function () {
|
||||
const rendered = helpers.img_url({hash: {absolute: 'true'}});
|
||||
should.not.exist(rendered);
|
||||
logWarnStub.calledOnce.should.be.true();
|
||||
|
@ -85,16 +81,12 @@ describe('{{image}} helper', function () {
|
|||
});
|
||||
|
||||
describe('with sub-directory', function () {
|
||||
let sandbox;
|
||||
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/blog'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/blog'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should output relative url of image', function () {
|
||||
|
@ -117,16 +109,12 @@ describe('{{image}} helper', function () {
|
|||
});
|
||||
|
||||
describe('image_sizes', function () {
|
||||
let sandbox;
|
||||
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should output correct url for absolute paths which are internal', function () {
|
||||
|
|
|
@ -3,6 +3,7 @@ const sinon = require('sinon');
|
|||
const Promise = require('bluebird');
|
||||
const testUtils = require('../../utils');
|
||||
const urlUtils = require('../../utils/urlUtils');
|
||||
const configUtils = require('../../utils/configUtils');
|
||||
const markdownToMobiledoc = require('../../utils/fixtures/data-generator').markdownToMobiledoc;
|
||||
const helpers = require('../../../core/frontend/helpers');
|
||||
const urlService = require('../../../core/frontend/services/url');
|
||||
|
@ -10,7 +11,6 @@ const api = require('../../../core/server/api');
|
|||
|
||||
describe('{{url}} helper', function () {
|
||||
let rendered;
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
rendered = null;
|
||||
|
@ -28,13 +28,11 @@ describe('{{url}} helper', function () {
|
|||
|
||||
describe('no subdir', function () {
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('should return the slug with a prefix slash if the context is a post', function () {
|
||||
|
@ -273,13 +271,11 @@ describe('{{url}} helper', function () {
|
|||
|
||||
describe('with subdir', function () {
|
||||
before(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://localhost:65535/blog'}, sandbox);
|
||||
configUtils.set({url: 'http://localhost:65535/blog'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('external urls should be retained in a nav context with subdir', function () {
|
||||
|
|
|
@ -2,7 +2,7 @@ const should = require('should');
|
|||
const sinon = require('sinon');
|
||||
const _ = require('lodash');
|
||||
const testUtils = require('../../../utils');
|
||||
const urlUtils = require('../../../utils/urlUtils');
|
||||
const configUtils = require('../../../utils/configUtils');
|
||||
const urlService = require('../../../../core/frontend/services/url');
|
||||
const generateFeed = require('../../../../core/frontend/services/rss/generate-feed');
|
||||
|
||||
|
@ -39,6 +39,7 @@ describe('RSS: Generate Feed', function () {
|
|||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -53,16 +54,8 @@ describe('RSS: Generate Feed', function () {
|
|||
});
|
||||
|
||||
describe('without subdirectory', function () {
|
||||
let sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox();
|
||||
urlUtils.stubUrlUtils({url: 'http://my-ghost-blog.com'}, sandbox);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
urlUtils.restore();
|
||||
configUtils.set({url: 'http://my-ghost-blog.com'});
|
||||
});
|
||||
|
||||
it('should get the RSS tags correct', function (done) {
|
||||
|
|
|
@ -39,14 +39,6 @@ const stubUrlUtils = (options, sandbox) => {
|
|||
}
|
||||
});
|
||||
|
||||
if (options.url) {
|
||||
configUtils.set('url', options.url);
|
||||
}
|
||||
|
||||
if (options.adminUrl) {
|
||||
configUtils.set('admin:url', options.adminUrl);
|
||||
}
|
||||
|
||||
return stubInstance;
|
||||
};
|
||||
|
||||
|
@ -68,7 +60,6 @@ const restore = () => {
|
|||
configUtils.restore();
|
||||
};
|
||||
|
||||
module.exports.stubUrlUtils = stubUrlUtils;
|
||||
module.exports.stubUrlUtilsFromConfig = stubUrlUtilsFromConfig;
|
||||
module.exports.restore = restore;
|
||||
module.exports.getInstance = getInstance;
|
||||
|
|
Loading…
Add table
Reference in a new issue