diff --git a/dist/all.js b/dist/all.js
index ba4650c4..283dc039 100644
--- a/dist/all.js
+++ b/dist/all.js
@@ -5916,7 +5916,7 @@ Canvas.base.getElementOffset = getElementOffset;
*/
toObject: function() {
return Canvas.base.object.extend(this.callSuper('toObject'), {
- points: this.points.clone()
+ points: this.points.concat()
});
},
@@ -7236,7 +7236,7 @@ Canvas.base.getElementOffset = getElementOffset;
* @return {Canvas.Text} an instance
*/
Canvas.Text.fromObject = function(object) {
- return new Canvas.Text(object.text, Object.clone(object));
+ return new Canvas.Text(object.text, Canvas.base.object.clone(object));
};
/**
diff --git a/src/canvas_polygon.class.js b/src/canvas_polygon.class.js
index f56188e0..ca8bdbf2 100644
--- a/src/canvas_polygon.class.js
+++ b/src/canvas_polygon.class.js
@@ -68,7 +68,7 @@
*/
toObject: function() {
return Canvas.base.object.extend(this.callSuper('toObject'), {
- points: this.points.clone()
+ points: this.points.concat()
});
},
diff --git a/src/canvas_text.class.js b/src/canvas_text.class.js
index d401f056..16f6d7a0 100644
--- a/src/canvas_text.class.js
+++ b/src/canvas_text.class.js
@@ -177,7 +177,7 @@
* @return {Canvas.Text} an instance
*/
Canvas.Text.fromObject = function(object) {
- return new Canvas.Text(object.text, Object.clone(object));
+ return new Canvas.Text(object.text, Canvas.base.object.clone(object));
};
/**
diff --git a/test/unit/canvas_parser.js b/test/unit/canvas_parser.js
index e14dd9ea..610f5de8 100644
--- a/test/unit/canvas_parser.js
+++ b/test/unit/canvas_parser.js
@@ -130,7 +130,7 @@ function init() {
this.assert(Canvas.parseElements);
function getOptions(options) {
- return Object.extend(Object.clone({
+ return Canvas.base.object.extend(Canvas.base.object.clone({
left: 10, top: 20, width: 30, height: 40 }), options || { });
}
diff --git a/test/unit/canvas_polyline.html b/test/unit/canvas_polyline.html
index 15b6852a..6488c61b 100644
--- a/test/unit/canvas_polyline.html
+++ b/test/unit/canvas_polyline.html
@@ -3,26 +3,22 @@
- Canvas.Polyline unit tests
+ Canvas.Polyline unit tests
+
-
+
+
-
-
-
-
-
-
-
+
- Canvas.Polyline unit tests
-
+
+
+
+
\ No newline at end of file
diff --git a/test/unit/canvas_polyline.js b/test/unit/canvas_polyline.js
index 0116d1fc..39b75b7c 100644
--- a/test/unit/canvas_polyline.js
+++ b/test/unit/canvas_polyline.js
@@ -1,4 +1,4 @@
-function init() {
+(function() {
function getPoints() {
return [
@@ -26,76 +26,86 @@ function init() {
'points': getPoints()
};
- new Test.Unit.Runner({
- testConstructor: function() {
- this.assert(Canvas.Polyline);
-
- var polyline = new Canvas.Polyline(getPoints());
-
- this.assertInstanceOf(Canvas.Polyline, polyline);
- this.assertInstanceOf(Canvas.Object, polyline);
-
- this.assertIdentical('polyline', polyline.type);
- this.assertObjectIdentical(getPoints(), polyline.get('points'));
- },
- testComplexity: function() {
- var polyline = new Canvas.Polyline(getPoints());
- this.assertRespondsTo('complexity', polyline);
- },
- testToObject: function() {
- var polyline = new Canvas.Polyline(getPoints());
- this.assertRespondsTo('toObject', polyline);
-
- this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject());
- },
- testCanvasPolylineFromObject: function() {
- this.assertRespondsTo('fromObject', Canvas.Polyline);
- var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT);
- this.assertInstanceOf(Canvas.Polyline, polyline);
- this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject());
- },
- testCanvasPolylineFromElement: function() {
- this.assertRespondsTo('fromElement', Canvas.Polyline);
-
- var elPolyline = document.createElement('polyline');
-
- elPolyline.setAttribute('points', '10,12 20,22');
-
- var polyline = Canvas.Polyline.fromElement(elPolyline);
-
- this.assertInstanceOf(Canvas.Polyline, polyline);
- this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject());
-
- var elPolylineWithAttrs = document.createElement('polyline');
- elPolylineWithAttrs.setAttribute('points', '10,10 20,20 30,30 10,10');
- elPolylineWithAttrs.setAttribute('fill', 'rgb(255,255,255)');
- elPolylineWithAttrs.setAttribute('fill-opacity', '0.34');
- elPolylineWithAttrs.setAttribute('stroke-width', '3');
- elPolylineWithAttrs.setAttribute('stroke', 'blue');
- elPolylineWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2)');
-
- var polylineWithAttrs = Canvas.Polyline.fromElement(elPolylineWithAttrs);
- var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}];
-
- this.assertObjectIdentical(Object.extend(REFERENCE_OBJECT, {
- 'width': 20,
- 'height': 20,
- 'fill': 'rgb(255,255,255)',
- 'stroke': 'blue',
- 'strokeWidth': 3,
- 'opacity': 0.34,
- 'points': expectedPoints
- }), polylineWithAttrs.toObject());
-
- this.assertEnumEqual([ 2, 0, 0, 2, -10, -20 ], polylineWithAttrs.get('transformMatrix'));
-
- var elPolylineWithoutPoints = document.createElement('polyline');
-
- this.assertRaise('TypeError', function(){
- Canvas.Polyline.fromElement(elPolylineWithoutPoints);
- }, 'missing points attribute should result in error');
-
- this.assertNull(Canvas.Polyline.fromElement());
- }
+ test('constructor', function(){
+ ok(Canvas.Polyline);
+
+ var polyline = new Canvas.Polyline(getPoints());
+
+ ok(polyline instanceof Canvas.Polyline);
+ ok(polyline instanceof Canvas.Object);
+
+ equals(polyline.type, 'polyline');
+ same(polyline.get('points'), getPoints());
});
-}
\ No newline at end of file
+
+ test('complexity', function(){
+ var polyline = new Canvas.Polyline(getPoints());
+ ok(typeof polyline.complexity == 'function');
+ });
+
+ test('toObject', function(){
+ var polyline = new Canvas.Polyline(getPoints());
+ ok(typeof polyline.toObject == 'function');
+
+ same(polyline.toObject(), REFERENCE_OBJECT);
+ });
+
+ test('Canvas.Polyline.fromObject', function(){
+ ok(typeof Canvas.Polyline.fromObject == 'function');
+ var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT);
+ ok(polyline instanceof Canvas.Polyline);
+ same(polyline.toObject(), REFERENCE_OBJECT);
+ });
+
+ /*
+ testCanvasPolylineFromObject: function() {
+ this.assertRespondsTo('fromObject', Canvas.Polyline);
+ var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT);
+ this.assertInstanceOf(Canvas.Polyline, polyline);
+ this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject());
+ },
+ testCanvasPolylineFromElement: function() {
+ this.assertRespondsTo('fromElement', Canvas.Polyline);
+
+ var elPolyline = document.createElement('polyline');
+
+ elPolyline.setAttribute('points', '10,12 20,22');
+
+ var polyline = Canvas.Polyline.fromElement(elPolyline);
+
+ this.assertInstanceOf(Canvas.Polyline, polyline);
+ this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject());
+
+ var elPolylineWithAttrs = document.createElement('polyline');
+ elPolylineWithAttrs.setAttribute('points', '10,10 20,20 30,30 10,10');
+ elPolylineWithAttrs.setAttribute('fill', 'rgb(255,255,255)');
+ elPolylineWithAttrs.setAttribute('fill-opacity', '0.34');
+ elPolylineWithAttrs.setAttribute('stroke-width', '3');
+ elPolylineWithAttrs.setAttribute('stroke', 'blue');
+ elPolylineWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2)');
+
+ var polylineWithAttrs = Canvas.Polyline.fromElement(elPolylineWithAttrs);
+ var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}];
+
+ this.assertObjectIdentical(Object.extend(REFERENCE_OBJECT, {
+ 'width': 20,
+ 'height': 20,
+ 'fill': 'rgb(255,255,255)',
+ 'stroke': 'blue',
+ 'strokeWidth': 3,
+ 'opacity': 0.34,
+ 'points': expectedPoints
+ }), polylineWithAttrs.toObject());
+
+ this.assertEnumEqual([ 2, 0, 0, 2, -10, -20 ], polylineWithAttrs.get('transformMatrix'));
+
+ var elPolylineWithoutPoints = document.createElement('polyline');
+
+ this.assertRaise('TypeError', function(){
+ Canvas.Polyline.fromElement(elPolylineWithoutPoints);
+ }, 'missing points attribute should result in error');
+
+ this.assertNull(Canvas.Polyline.fromElement());
+ }
+ */
+})();
\ No newline at end of file
diff --git a/test/unit/canvas_rect.html b/test/unit/canvas_rect.html
index 05214c36..7327df47 100644
--- a/test/unit/canvas_rect.html
+++ b/test/unit/canvas_rect.html
@@ -3,30 +3,22 @@
- Canvas.Rect unit tests
-
-
+ Canvas.Rect unit tests
+
-
+
+
-
-
-
-
-
-
-
+
- Canvas.Rect unit tests
-
+
+
+
+
\ No newline at end of file
diff --git a/test/unit/canvas_rect.js b/test/unit/canvas_rect.js
index fb28b1af..d91ba5a1 100644
--- a/test/unit/canvas_rect.js
+++ b/test/unit/canvas_rect.js
@@ -1,4 +1,4 @@
-function init() {
+(function() {
var REFERENCE_RECT = {
'type': 'rect',
@@ -18,73 +18,76 @@ function init() {
'opacity': 1
};
- new Test.Unit.Runner({
- testConstructor: function() {
-
- this.assert(Canvas.Rect);
-
- var rect = new Canvas.Rect();
-
- this.assertInstanceOf(Canvas.Rect, rect);
- this.assertInstanceOf(Canvas.Object, rect);
-
- this.assertIdentical('rect', rect.get('type'));
- },
- testComplexity: function() {
- var rect = new Canvas.Rect();
- this.assertRespondsTo('complexity', rect);
- },
- testToObject: function() {
- var rect = new Canvas.Rect();
- this.assertRespondsTo('toObject', rect);
-
- var object = rect.toObject();
- this.assertObjectIdentical(REFERENCE_RECT, object);
- },
- testCanvasRectFromObject: function() {
- this.assertRespondsTo('fromObject', Canvas.Rect);
- var rect = Canvas.Rect.fromObject(REFERENCE_RECT);
- this.assertInstanceOf(Canvas.Rect, rect);
- this.assertObjectIdentical(REFERENCE_RECT, rect.toObject());
- },
- testCanvasRectFromElement: function() {
- this.assertRespondsTo('fromElement', Canvas.Rect);
-
- var elRect = document.createElement('rect');
- var rect = Canvas.Rect.fromElement(elRect);
-
- this.assertInstanceOf(Canvas.Rect, rect);
- this.assertObjectIdentical(REFERENCE_RECT, rect.toObject());
-
- var elRectWithAttrs = document.createElement('rect');
- elRectWithAttrs.setAttribute('x', 10);
- elRectWithAttrs.setAttribute('y', 20);
- elRectWithAttrs.setAttribute('width', 222);
- elRectWithAttrs.setAttribute('height', 333);
- elRectWithAttrs.setAttribute('rx', 11);
- elRectWithAttrs.setAttribute('ry', 12);
- elRectWithAttrs.setAttribute('fill', 'rgb(255,255,255)');
- elRectWithAttrs.setAttribute('fill-opacity', 0.45);
- elRectWithAttrs.setAttribute('stroke', 'blue');
- elRectWithAttrs.setAttribute('stroke-width', 3);
- //elRectWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2) rotate(45) translate(5,10)');
-
- var rectWithAttrs = Canvas.Rect.fromElement(elRectWithAttrs);
- this.assertInstanceOf(Canvas.Rect, rectWithAttrs);
-
- var expectedObject = Object.extend(REFERENCE_RECT, {
- left: 121,
- top: 186.5,
- width: 222,
- height: 333,
- fill: 'rgb(255,255,255)',
- opacity: 0.45,
- stroke: 'blue',
- strokeWidth: 3
- });
- this.assertObjectIdentical(expectedObject, rectWithAttrs.toObject());
-
- this.assertNull(Canvas.Rect.fromElement());
- }
+ test('constructor', function(){
+ ok(Canvas.Rect);
+
+ var rect = new Canvas.Rect();
+
+ ok(rect instanceof Canvas.Rect);
+ ok(rect instanceof Canvas.Object);
+
+ same(rect.get('type'), 'rect');
});
-}
\ No newline at end of file
+
+ test('complexity', function() {
+ var rect = new Canvas.Rect();
+
+ ok(typeof rect.complexity == 'function');
+ });
+
+ test('toObject', function() {
+ var rect = new Canvas.Rect();
+ ok(typeof rect.toObject == 'function');
+
+ var object = rect.toObject();
+ same(object, REFERENCE_RECT);
+ });
+
+ test('Canvas.Rect.fromObject', function() {
+ ok(typeof Canvas.Rect.fromObject == 'function');
+
+ var rect = Canvas.Rect.fromObject(REFERENCE_RECT);
+ ok(rect instanceof Canvas.Rect);
+ same(rect.toObject(), REFERENCE_RECT);
+ });
+
+ test('Canvas.Rect.fromElement', function() {
+ ok(typeof Canvas.Rect.fromElement == 'function');
+
+ var elRect = document.createElement('rect');
+ var rect = Canvas.Rect.fromElement(elRect);
+
+ ok(rect instanceof Canvas.Rect);
+ same(rect.toObject(), REFERENCE_RECT);
+
+ var elRectWithAttrs = document.createElement('rect');
+ elRectWithAttrs.setAttribute('x', 10);
+ elRectWithAttrs.setAttribute('y', 20);
+ elRectWithAttrs.setAttribute('width', 222);
+ elRectWithAttrs.setAttribute('height', 333);
+ elRectWithAttrs.setAttribute('rx', 11);
+ elRectWithAttrs.setAttribute('ry', 12);
+ elRectWithAttrs.setAttribute('fill', 'rgb(255,255,255)');
+ elRectWithAttrs.setAttribute('fill-opacity', 0.45);
+ elRectWithAttrs.setAttribute('stroke', 'blue');
+ elRectWithAttrs.setAttribute('stroke-width', 3);
+ //elRectWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2) rotate(45) translate(5,10)');
+
+ var rectWithAttrs = Canvas.Rect.fromElement(elRectWithAttrs);
+ ok(rectWithAttrs instanceof Canvas.Rect);
+
+ var expectedObject = Canvas.base.object.extend(REFERENCE_RECT, {
+ left: 121,
+ top: 186.5,
+ width: 222,
+ height: 333,
+ fill: 'rgb(255,255,255)',
+ opacity: 0.45,
+ stroke: 'blue',
+ strokeWidth: 3
+ });
+ same(rectWithAttrs.toObject(), expectedObject);
+
+ ok(Canvas.Rect.fromElement() === null);
+ });
+})();
\ No newline at end of file
diff --git a/test/unit/canvas_text.html b/test/unit/canvas_text.html
index de30ea07..9da081e5 100644
--- a/test/unit/canvas_text.html
+++ b/test/unit/canvas_text.html
@@ -3,15 +3,22 @@
- Canvas.Text unit tests
+ Canvas.Text unit tests
+
-
+
-
-
+
+
+
+
- Canvas.Text unit tests
-
+
+
+
+
\ No newline at end of file
diff --git a/test/unit/canvas_text.js b/test/unit/canvas_text.js
index 195405d7..46ab81fa 100644
--- a/test/unit/canvas_text.js
+++ b/test/unit/canvas_text.js
@@ -1,4 +1,4 @@
-function init(){
+(function() {
var REFERENCE_TEXT_OBJECT = {
'type': 'text',
@@ -6,7 +6,7 @@ function init(){
'top': 10,
'width': 100,
'height': 100,
- 'fill': '#000000',
+ 'fill': 'rgb(0,0,0)',
'overlayFill': null,
'stroke': null,
'strokeWidth': 1,
@@ -23,86 +23,106 @@ function init(){
'path': null
};
- new Test.Unit.Runner({
- testConstructor: function() {
- this.assert(Canvas.Text);
- var text = new Canvas.Text('foo');
-
- this.assertInstanceOf(Canvas.Text, text);
- this.assertInstanceOf(Canvas.Object, text);
-
- this.assertIdentical('text', text.get('type'));
- this.assertIdentical('foo', text.get('text'));
- },
- testToString: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('toString', text);
- this.assertIdentical('#', text.toString());
- },
- testToObject: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('toObject', text);
- this.assertObjectIdentical(REFERENCE_TEXT_OBJECT, text.toObject());
- },
- testComplexity: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('complexity', text);
- },
- testSet: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('set', text);
- this.assertIdentical(text, text.set('text', 'bar'), 'should be chainable');
- },
- testSetColor: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('setColor', text);
- this.assertIdentical(text, text.setColor('123456'), 'should be chainable');
- this.assertIdentical('123456', text.get('fill'));
- },
- testSetFontsize: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('setFontsize', text);
- this.assertIdentical(text, text.setFontsize(12));
- this.assertIdentical(12, text.get('fontsize'));
- },
- testGetText: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('getText', text);
- this.assertIdentical('foo', text.getText());
- this.assertIdentical(text.get('text'), text.getText());
- },
- testSetText: function() {
- var text = new Canvas.Text('foo');
- this.assertRespondsTo('setText', text);
- this.assertIdentical(text, text.setText('bar'), 'should be chainable');
- this.assertIdentical('bar', text.getText());
- },
- testCanvasTextFromObject: function() {
- this.assertRespondsTo('fromObject', Canvas.Text);
- var text = Canvas.Text.fromObject(REFERENCE_TEXT_OBJECT);
- this.assertObjectIdentical(REFERENCE_TEXT_OBJECT, text.toObject());
- },
- testCanvasTextAlreadyDefined: function() {
- var warnWasCalled = false;
- console.warn = function() {
- warnWasCalled = true;
- }
- loadScript('../../canvas/canvas_text.class.js');
- this.wait(1000, function(){
- this.assert(warnWasCalled);
- });
- },
- testCanvasObjectDoesntExist: function() {
- var warnWasCalled = false;
- console.warn = function() {
- warnWasCalled = true;
- }
- delete Canvas.Text;
- delete Canvas.Object;
- loadScript('../../canvas/canvas_text.class.js');
- this.wait(1000, function() {
- this.assert(warnWasCalled);
- });
- }
+ test('constructor', function() {
+ ok(Canvas.Text);
+ var text = new Canvas.Text('foo');
+
+ ok(text instanceof Canvas.Text);
+ ok(text instanceof Canvas.Object);
+
+ equals(text.get('type'), 'text');
+ equals(text.get('text'), 'foo');
});
-}
+
+ test('toString', function() {
+ var text = new Canvas.Text('foo');
+ ok(typeof text.toString == 'function');
+ equals(text.toString(), '#');
+ });
+
+ test('toObject', function() {
+ var text = new Canvas.Text('foo');
+ ok(typeof text.toObject == 'function');
+ same(text.toObject(), REFERENCE_TEXT_OBJECT);
+ });
+
+ test('complexity', function(){
+ var text = new Canvas.Text('foo');
+ ok(typeof text.complexity == 'function');
+ });
+
+ test('set', function() {
+ var text = new Canvas.Text('foo');
+ ok(typeof text.set == 'function');
+ equals(text.set('text', 'bar'), text, 'should be chainable');
+ });
+
+ test('setColor', function(){
+ var text = new Canvas.Text('foo');
+ ok(typeof text.setColor == 'function');
+ equals(text.setColor('123456'), text, 'should be chainable');
+ equals(text.get('fill'), '123456');
+ });
+
+ test('setFontsize', function(){
+ var text = new Canvas.Text('foo');
+ ok(typeof text.setFontsize == 'function');
+ equals(text.setFontsize(12), text);
+ equals(text.get('fontsize'), 12);
+ });
+
+ test('getText', function(){
+ var text = new Canvas.Text('foo');
+ ok(typeof text.getText == 'function');
+ equals(text.getText(), 'foo');
+ equals(text.getText(), text.get('text'));
+ });
+
+ test('setText', function(){
+ var text = new Canvas.Text('foo');
+ ok(typeof text.setText == 'function');
+ equals(text.setText('bar'), text, 'should be chainable');
+ equals(text.getText(), 'bar');
+ });
+
+ test('Canvas.Text.fromObject', function(){
+ ok(typeof Canvas.Text.fromObject == 'function');
+ var text = Canvas.Text.fromObject(REFERENCE_TEXT_OBJECT);
+ same(text.toObject(), REFERENCE_TEXT_OBJECT);
+ });
+
+ asyncTest('Text already defined', function() {
+ var warnWasCalled = false;
+ console.warn = function() {
+ warnWasCalled = true;
+ };
+
+ var el = document.createElement('script');
+ el.src = '../../src/canvas_text.class.js';
+ document.body.appendChild(el);
+
+ setTimeout(function() {
+ ok(warnWasCalled);
+ start();
+ }, 500);
+ });
+
+ asyncTest('Object doesn\'t exist', function() {
+ var warnWasCalled = false;
+ console.warn = function() {
+ warnWasCalled = true;
+ }
+ delete Canvas.Text;
+ delete Canvas.Object;
+
+ var el = document.createElement('script');
+ el.src = '../../src/canvas_text.class.js';
+ document.body.appendChild(el);
+
+ setTimeout(function(){
+ ok(warnWasCalled);
+ start();
+ }, 500);
+ });
+
+})();
\ No newline at end of file
diff --git a/test/unit/canvas_util.html b/test/unit/canvas_util.html
index 0d4a4b26..ff3e7982 100644
--- a/test/unit/canvas_util.html
+++ b/test/unit/canvas_util.html
@@ -5,20 +5,21 @@
Canvas.util unit tests
-
+
-
-
-
+
-
+
+
-
+
- Canvas.util.* unit tests
-
+
+
+
+