$string['formerror_onlysometagsallowed'] = 'Only "{$a}" tags are allowed in the label for a marker';
$string['formerror_onlyusewholepositivenumbers'] = 'Please use only whole positive numbers to specify x,y coords and/or width and height of shapes. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';
$string['formerror_polygonmusthaveatleastthreepoints'] = 'For a polygon shape you need to specify at least 3 points. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';
+$string['formerror_repeatedpoint'] = 'You have given the same point twice. Please remove the duplication. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';
$string['formerror_shapeoutsideboundsofbgimage'] = 'The shape you have defined goes out of the bounds of the background image';
$string['formerror_toomanysemicolons'] = 'There are too many semi colon separated parts to the coordinates you have specified. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';
$string['formerror_unrecognisedwidthheightpart'] = 'We do not recognise the width and height you have specified. Your coordinates for a {$a->shape} should be expressed as - {$a->coordsstring}.';
if (count($coordsstringparts) < 3) {
$this->error = 'polygonmusthaveatleastthreepoints';
} else {
+ $lastxy = null;
foreach ($coordsstringparts as $coordsstringpart) {
$xy = explode(',', $coordsstringpart);
if (count($xy) !== 2) {
}
$xy[0] = (int) $xy[0];
$xy[1] = (int) $xy[1];
+ if ($lastxy !== null && $lastxy[0] == $xy[0] && $lastxy[1] == $xy[1]) {
+ $this->error = 'repeatedpoint';
+ }
$this->coords[] = $xy;
+ $lastxy = $xy;
if (isset($this->minxy)) {
$this->minxy[0] = min($this->minxy[0], $xy[0]);
$this->minxy[1] = min($this->minxy[1], $xy[1]);
*/
class qtype_ddmarker_shapes_test extends basic_testcase {
- public function test_polygon_valdiation_test() {
+ public function test_polygon_valdiation_test_ok() {
$shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20');
$this->assertFalse($shape->get_coords_interpreter_error()); // No errors.
}
+ public function test_polygon_valdiation_test_only_two_points() {
+ $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10');
+ $this->assertEquals(get_string('formerror_polygonmusthaveatleastthreepoints', 'qtype_ddmarker',
+ array('shape' => 'polygon', 'coordsstring' => get_string('shape_polygon_coords', 'qtype_ddmarker'))),
+ $shape->get_coords_interpreter_error());
+ }
+
+ public function test_polygon_valdiation_test_invalid_point() {
+ $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, ; 20, 20; 10, 20');
+ $this->assertEquals(get_string('formerror_onlyusewholepositivenumbers', 'qtype_ddmarker',
+ array('shape' => 'polygon', 'coordsstring' => get_string('shape_polygon_coords', 'qtype_ddmarker'))),
+ $shape->get_coords_interpreter_error());
+ }
+
+ public function test_polygon_valdiation_test_repeated_point() {
+ $shape = new qtype_ddmarker_shape_polygon('70,220;90,200;95,150;120,150;140,200;150,230;150,230;150,240;120,240;110,240;90,240');
+ $this->assertEquals(get_string('formerror_repeatedpoint', 'qtype_ddmarker',
+ array('shape' => 'polygon', 'coordsstring' => get_string('shape_polygon_coords', 'qtype_ddmarker'))),
+ $shape->get_coords_interpreter_error());
+ }
+
public function test_polygon_hit_test() {
$shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20');
$this->assertTrue($shape->is_point_in_shape(array(15, 15)));