2017-03-21 08:24:11 +00:00
|
|
|
var should = require('should'), // jshint ignore:line
|
|
|
|
makeAbsoluteUrls = require('../../../server/utils/make-absolute-urls'),
|
|
|
|
configUtils = require('../../utils/configUtils');
|
2016-08-25 08:09:40 +02:00
|
|
|
|
|
|
|
describe('Make absolute URLs ', function () {
|
|
|
|
var siteUrl = 'http://my-ghost-blog.com',
|
|
|
|
itemUrl = 'my-awesome-post';
|
2017-03-21 08:24:11 +00:00
|
|
|
|
2016-08-25 08:09:40 +02:00
|
|
|
beforeEach(function () {
|
|
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
});
|
|
|
|
|
2017-10-18 23:54:17 +07:00
|
|
|
it('[success] does not convert absolute URLs', function () {
|
2016-08-25 08:09:40 +02:00
|
|
|
var html = '<a href="http://my-ghost-blog.com/content/images" title="Absolute URL">',
|
|
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/content\/images" title="Absolute URL">/);
|
|
|
|
});
|
2017-10-18 23:54:17 +07:00
|
|
|
it('[failure] does not convert protocol relative `//` URLs', function () {
|
2016-08-25 08:09:40 +02:00
|
|
|
var html = '<a href="//my-ghost-blog.com/content/images" title="Absolute URL">',
|
|
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
|
|
|
|
result.should.match(/<a href="\/\/my-ghost-blog.com\/content\/images" title="Absolute URL">/);
|
|
|
|
});
|
2017-10-18 23:54:17 +07:00
|
|
|
it('[failure] does not convert internal links starting with "#"', function () {
|
|
|
|
var html = '<a href="#jumptosection" title="Table of Content">',
|
|
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
|
|
|
|
result.should.match(/<a href="#jumptosection" title="Table of Content">/);
|
|
|
|
});
|
|
|
|
it('[success] converts a relative URL', function () {
|
2016-08-25 08:09:40 +02:00
|
|
|
var html = '<a href="/about#nowhere" title="Relative URL">',
|
|
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/about#nowhere" title="Relative URL">/);
|
|
|
|
});
|
2017-10-18 23:54:17 +07:00
|
|
|
it('[success] converts a relative URL including subdirectories', function () {
|
2016-08-25 08:09:40 +02:00
|
|
|
var html = '<a href="/about#nowhere" title="Relative URL">',
|
|
|
|
result = makeAbsoluteUrls(html, 'http://my-ghost-blog.com/blog', itemUrl).html();
|
|
|
|
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/blog\/about#nowhere" title="Relative URL">/);
|
|
|
|
});
|
|
|
|
});
|