diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 0e48c806..54d018f1 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -281,8 +281,6 @@ MapController.prototype.instantiateTemplate = function(req, res, prepareParamsFn res.set('X-Layergroup-Id', layergroup.layergroupid); self.surrogateKeysCache.tag(res, new NamedMapsCacheEntry(cdbuser, mapConfigProvider.getTemplateName())); - console.log(layergroup); - self.send(req, res, layergroup, 200); } } diff --git a/test/acceptance/turbo-cartocss-regressions.js b/test/acceptance/turbo-cartocss-regressions.js new file mode 100644 index 00000000..c429645b --- /dev/null +++ b/test/acceptance/turbo-cartocss-regressions.js @@ -0,0 +1,67 @@ +require('../support/test_helper'); + +var assert = require('../support/assert'); +var TestClient = require('../support/test-client'); + +function makeMapconfig(cartocss) { + return { + "version": "1.4.0", + "layers": [ + { + "type": 'mapnik', + "options": { + "cartocss_version": '2.3.0', + "sql": [ + 'SELECT test_table.*, _prices.price FROM test_table JOIN (' + + ' SELECT 1 AS cartodb_id, 10.00 AS price', + ' UNION', + ' SELECT 2, 10.50', + ' UNION', + ' SELECT 3, 11.00', + ' UNION', + ' SELECT 4, 12.00', + ' UNION', + ' SELECT 5, 21.00', + ') _prices ON _prices.cartodb_id = test_table.cartodb_id' + ].join('\n'), + "cartocss": cartocss + } + } + ] + }; +} + +describe.skip('turbo-cartocss regressions', function() { + + it('should accept // comments', function(done) { + var cartocss = [ + "/** simple visualization */", + "", + "Map {", + " buffer-size: 256;", + "}", + "", + "#county_points_with_population{", + " marker-fill-opacity: 0.1;", + " marker-line-color:#FFFFFF;//#CF1C90;", + " marker-line-width: 0;", + " marker-line-opacity: 0.3;", + " marker-placement: point;", + " marker-type: ellipse;", + " //marker-comp-op: overlay;", + " marker-width: [price];", + " [zoom=5]{marker-width: [price]*2;}", + " [zoom=6]{marker-width: [price]*4;}", + " marker-fill: #000000;", + " marker-allow-overlap: true;", + " ", + "", + "}" + ].join('\n'); + var testClient = new TestClient(makeMapconfig(cartocss)); + testClient.createLayergroup(function(err) { + assert.ok(!err, err); + done(); + }); + }); +}); diff --git a/test/acceptance/turbo-cartocss.js b/test/acceptance/turbo-cartocss.js new file mode 100644 index 00000000..ae2de717 --- /dev/null +++ b/test/acceptance/turbo-cartocss.js @@ -0,0 +1,128 @@ +var assert = require('../support/assert'); +var TestClient = require('../support/test-client'); + +var IMAGE_TOLERANCE_PER_MIL = 20; + +function imageCompareFn(fixture, done) { + return function(err, res, image) { + assert.ok(!err, err); + assert.imageIsSimilarToFile(image, './test/fixtures/' + fixture, IMAGE_TOLERANCE_PER_MIL, done); + }; +} + +function makeMapconfig(cartocss) { + return { + "version": "1.4.0", + "layers": [ + { + "type": 'mapnik', + "options": { + "cartocss_version": '2.3.0', + "sql": [ + 'SELECT test_table.*, _prices.price FROM test_table JOIN (' + + ' SELECT 1 AS cartodb_id, 10.00 AS price', + ' UNION', + ' SELECT 2, 10.50', + ' UNION', + ' SELECT 3, 11.00', + ' UNION', + ' SELECT 4, 12.00', + ' UNION', + ' SELECT 5, 21.00', + ') _prices ON _prices.cartodb_id = test_table.cartodb_id' + ].join('\n'), + "cartocss": cartocss + } + } + ] + }; +} + +describe('turbo-cartocss', function() { + describe('parsing ramp function with colorbrewer for greens and mapnik renderer', function () { + beforeEach(function () { + var turboCartocss = '#layer { marker-fill: ramp([price], colorbrewer(Greens)); }'; + this.testClient = new TestClient(makeMapconfig(turboCartocss)); + }); + + afterEach(function (done) { + this.testClient.drain(done); + }); + + it('should get a tile with turbo-cartocss parsed properly', function (done) { + var fixturePath = 'test_turbo_cartocss_greens_13_4011_3088.png'; + this.testClient.getTile(13, 4011, 3088, imageCompareFn(fixturePath, done)); + }); + }); + + describe('parsing ramp function with colorbrewer for reds and mapnik renderer', function () { + beforeEach(function () { + var turboCartocss = '#layer { marker-fill: ramp([price], colorbrewer(Reds)); }'; + this.testClient = new TestClient(makeMapconfig(turboCartocss)); + }); + + afterEach(function (done) { + this.testClient.drain(done); + }); + + it('should get a tile with turbo-cartocss parsed properly', function (done) { + var fixtureFileName = 'test_turbo_cartocss_reds_13_4011_3088.png'; + this.testClient.getTile(13, 4011, 3088, imageCompareFn(fixtureFileName, done)); + }); + }); + + describe('parsing ramp function with colorbrewer for greens and toque renderer', function () { + var mapConfig = { + version: '1.2.0', + layers: [ + { + type: 'torque', + options: { + sql: "SELECT * FROM populated_places_simple_reduced where the_geom" + + " && ST_MakeEnvelope(-90, 0, 90, 65)", + cartocss: [ + 'Map {', + ' buffer-size:0;', + ' -torque-frame-count:1;', + ' -torque-animation-duration:30;', + ' -torque-time-attribute:"cartodb_id";', + ' -torque-aggregation-function:"count(cartodb_id)";', + ' -torque-resolution:1;', + ' -torque-data-aggregation:linear;', + '};', + '#populated_places_simple_reduced {', + ' comp-op: multiply;', + ' marker-fill-opacity: 1;', + ' marker-line-color: #FFF;', + ' marker-line-width: 0;', + ' marker-line-opacity: 1;', + ' marker-type: rectangle;', + ' marker-width: 3;', + ' marker-fill: ramp([pop_max], colorbrewer(Greens));', + '};' + ].join(' '), + cartocss_version: '2.3.0' + } + } + ] + }; + + beforeEach(function () { + this.testClient = new TestClient(mapConfig); + }); + + afterEach(function (done) { + this.testClient.drain(done); + }); + + it('should get a tile with turbo-cartocss parsed properly', function (done) { + var z = 2; + var x = 2; + var y = 1; + + var pngFixture = 'torque/populated_places_simple_reduced-turbo-cartocss-' + [z, x, y].join('.') + '.png'; + + this.testClient.getTile(z, x, y, { layers: 0, format: 'torque.png' }, imageCompareFn(pngFixture, done)); + }); + }); +}); diff --git a/test/fixtures/test_turbo_cartocss_greens_13_4011_3088.png b/test/fixtures/test_turbo_cartocss_greens_13_4011_3088.png new file mode 100644 index 00000000..062352d2 Binary files /dev/null and b/test/fixtures/test_turbo_cartocss_greens_13_4011_3088.png differ diff --git a/test/fixtures/test_turbo_cartocss_reds_13_4011_3088.png b/test/fixtures/test_turbo_cartocss_reds_13_4011_3088.png new file mode 100644 index 00000000..a8c93799 Binary files /dev/null and b/test/fixtures/test_turbo_cartocss_reds_13_4011_3088.png differ diff --git a/test/fixtures/torque/populated_places_simple_reduced-turbo-cartocss-2.2.1.png b/test/fixtures/torque/populated_places_simple_reduced-turbo-cartocss-2.2.1.png new file mode 100644 index 00000000..59f0d5c1 Binary files /dev/null and b/test/fixtures/torque/populated_places_simple_reduced-turbo-cartocss-2.2.1.png differ diff --git a/test/support/prepare_db.sh b/test/support/prepare_db.sh index f573e819..f03d52de 100755 --- a/test/support/prepare_db.sh +++ b/test/support/prepare_db.sh @@ -80,7 +80,7 @@ if test x"$PREPARE_PGSQL" = xyes; then cat sql/_CDB_QueryStatements.sql | psql -v ON_ERROR_STOP=1 ${TEST_DB} || exit 1 - SQL_SCRIPTS='CDB_QueryTables CDB_CartodbfyTable CDB_TableMetadata CDB_ForeignTable CDB_UserTables CDB_ColumnNames CDB_ZoomFromScale CDB_Overviews' + SQL_SCRIPTS='CDB_QueryTables CDB_CartodbfyTable CDB_TableMetadata CDB_ForeignTable CDB_UserTables CDB_ColumnNames CDB_ZoomFromScale CDB_Overviews CDB_QuantileBins CDB_JenksBins CDB_HeadsTailsBins CDB_EqualIntervalBins' for i in ${SQL_SCRIPTS} do curl -L -s https://github.com/CartoDB/cartodb-postgresql/raw/master/scripts-available/$i.sql -o sql/$i.sql diff --git a/test/support/test-client.js b/test/support/test-client.js index 1a29f564..02128e36 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -168,7 +168,8 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { url = '/api/v1/map/' + layergroupId + '/'; var layers = params.layers; - if (!!layers) { + + if (layers !== undefined) { layers = Array.isArray(layers) ? layers : [layers]; url += layers.join(',') + '/'; } @@ -190,7 +191,6 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { } }; - var expectedResponse = { status: 200, headers: { @@ -198,7 +198,7 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { } }; - var isPng = format === 'png'; + var isPng = format === 'png' || format === 'torque.png'; if (isPng) { request.encoding = 'binary';