diff --git a/question/type/calculated/tests/variablesubstituter_test.php b/question/type/calculated/tests/variablesubstituter_test.php
index <HASH>..<HASH> 100644
--- a/question/type/calculated/tests/variablesubstituter_test.php
+++ b/question/type/calculated/tests/variablesubstituter_test.php
@@ -65,6 +65,17 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase {
         $vs->calculate('{a}{b}'); // Have to make sure this does not just evaluate to 12.
     }
 
+    public function test_division_by_zero_expression() {
+
+        if (intval(PHP_VERSION) < 7) {
+            $this->markTestSkipped('Division by zero triggers a PHP warning before PHP 7.');
+        }
+
+        $this->setExpectedException('moodle_exception');
+        $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 0), '.');
+        $vs->calculate('{a} / {b}');
+    }
+
     public function test_replace_expressions_in_text_simple_var() {
         $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.');
         $this->assertEquals('1 + 2', $vs->replace_expressions_in_text('{a} + {b}'));
MDL-<I>: qtype_calculated: Adding division by zero test