Ghost/core/test/unit/metadata/image-dimensions_spec.js
Aileen Nowak d2f2888da0 Favicon URI (#7700)
closes #7688

- Use `/favicon.ico` and `/favicon.png` in blog app. Depending on type of storage (custom upload = local file storage), serves either from storage adapter with `read()` method or reads the bytes via `fs`.
- Redirects requests for `favicon.ico` to `favicon.png` if custom `png` icon is uploaded and vice versa.
- Redirect requests for `favicon.png` to `favicon.ico` if default icon is used (in `core/shared`).
- Changes the `{{asset}}` helper for favicon to not serve from theme assets anymore. It will either be served the custom blog-icon or the default one.
- The `{{@blog.icon}}` helper renders the url of the **uploaded** blog icon. It won't render the default icon.
2017-01-26 18:01:19 +00:00

133 lines
4.6 KiB
JavaScript

var should = require('should'),
sinon = require('sinon'),
rewire = require('rewire'),
// Stuff we are testing
getImageDimensions = rewire('../../../server/data/meta/image-dimensions'),
getCachedImageSizeFromUrl = rewire('../../../server/utils/cached-image-size-from-url'),
sandbox = sinon.sandbox.create();
describe('getImageDimensions', function () {
var sizeOfStub;
beforeEach(function () {
sizeOfStub = sandbox.stub();
});
afterEach(function () {
sandbox.restore();
getCachedImageSizeFromUrl.__set__('imageSizeCache', {});
});
it('should return dimension for images', function (done) {
var metaData = {
coverImage: {
url: 'http://mysite.com/content/image/mypostcoverimage.jpg'
},
authorImage: {
url: 'http://mysite.com/author/image/url/me.jpg'
},
blog: {
logo: {
url: 'http://mysite.com/author/image/url/logo.jpg'
}
}
};
sizeOfStub.returns({
width: 50,
height: 50,
type: 'jpg'
});
getImageDimensions.__set__('getCachedImageSizeFromUrl', sizeOfStub);
getImageDimensions(metaData).then(function (result) {
should.exist(result);
sizeOfStub.calledWith(metaData.coverImage.url).should.be.true();
sizeOfStub.calledWith(metaData.authorImage.url).should.be.true();
sizeOfStub.calledWith(metaData.blog.logo.url).should.be.true();
result.coverImage.should.have.property('dimensions');
result.coverImage.should.have.property('url');
result.blog.logo.should.have.property('dimensions');
result.blog.logo.should.have.property('url');
result.authorImage.should.have.property('dimensions');
result.authorImage.should.have.property('url');
done();
}).catch(done);
});
it('should return metaData if url is undefined or null', function (done) {
var metaData = {
coverImage: {
url: undefined
},
authorImage: {
url: null
},
blog: {
logo: {
url: 'noUrl'
}
}
};
sizeOfStub.returns({});
getImageDimensions.__set__('getCachedImageSizeFromUrl', sizeOfStub);
getImageDimensions(metaData).then(function (result) {
should.exist(result);
sizeOfStub.calledWith(metaData.coverImage.url).should.be.true();
sizeOfStub.calledWith(metaData.authorImage.url).should.be.true();
sizeOfStub.calledWith(metaData.blog.logo.url).should.be.true();
result.coverImage.should.not.have.property('dimensions');
result.blog.logo.should.not.have.property('dimensions');
result.authorImage.should.not.have.property('dimensions');
result.coverImage.should.have.property('url');
result.blog.logo.should.have.property('url');
result.authorImage.should.have.property('url');
done();
}).catch(done);
});
it('should not return dimension for publisher.logo only if logo is too big', function (done) {
var metaData = {
coverImage: {
url: 'http://mysite.com/content/image/mypostcoverimage.jpg'
},
authorImage: {
url: 'http://mysite.com/author/image/url/me.jpg'
},
blog: {
logo: {
url: 'http://mysite.com/author/image/url/logo.jpg'
}
}
};
sizeOfStub.returns({
width: 480,
height: 80,
type: 'jpg'
});
getImageDimensions.__set__('getCachedImageSizeFromUrl', sizeOfStub);
getImageDimensions(metaData).then(function (result) {
should.exist(result);
sizeOfStub.calledWith(metaData.coverImage.url).should.be.true();
sizeOfStub.calledWith(metaData.authorImage.url).should.be.true();
sizeOfStub.calledWith(metaData.blog.logo.url).should.be.true();
result.coverImage.should.have.property('dimensions');
result.blog.logo.should.not.have.property('dimensions');
result.authorImage.should.have.property('dimensions');
result.coverImage.should.have.property('url');
result.blog.logo.should.have.property('url');
result.authorImage.should.have.property('url');
done();
}).catch(done);
});
});