public function assert($expectation, $compare, $notused = '') { if (get_class($expectation) === 'question_pattern_expectation') { $this->assertRegExp($expectation->pattern, $compare, 'Expected regex ' . $expectation->pattern . ' not found in ' . $compare); return; } else { if (get_class($expectation) === 'question_no_pattern_expectation') { $this->assertNotRegExp($expectation->pattern, $compare, 'Unexpected regex ' . $expectation->pattern . ' found in ' . $compare); return; } else { if (get_class($expectation) === 'question_contains_tag_with_attributes') { $this->assertTag(array('tag' => $expectation->tag, 'attributes' => $expectation->expectedvalues), $compare, 'Looking for a ' . $expectation->tag . ' with attributes ' . html_writer::attributes($expectation->expectedvalues) . ' in ' . $compare); foreach ($expectation->forbiddenvalues as $k => $v) { $attr = $expectation->expectedvalues; $attr[$k] = $v; $this->assertNotTag(array('tag' => $expectation->tag, 'attributes' => $attr), $compare, $expectation->tag . ' had a ' . $k . ' attribute that should not be there in ' . $compare); } return; } else { if (get_class($expectation) === 'question_contains_tag_with_attribute') { $attr = array($expectation->attribute => $expectation->value); $this->assertTag(array('tag' => $expectation->tag, 'attributes' => $attr), $compare, 'Looking for a ' . $expectation->tag . ' with attribute ' . html_writer::attributes($attr) . ' in ' . $compare); return; } else { if (get_class($expectation) === 'question_does_not_contain_tag_with_attributes') { $this->assertNotTag(array('tag' => $expectation->tag, 'attributes' => $expectation->attributes), $compare, 'Unexpected ' . $expectation->tag . ' with attributes ' . html_writer::attributes($expectation->attributes) . ' found in ' . $compare); return; } else { if (get_class($expectation) === 'question_contains_select_expectation') { $tag = array('tag' => 'select', 'attributes' => array('name' => $expectation->name), 'children' => array('count' => count($expectation->choices))); if ($expectation->enabled === false) { $tag['attributes']['disabled'] = 'disabled'; } else { if ($expectation->enabled === true) { // TODO } } foreach (array_keys($expectation->choices) as $value) { if ($expectation->selected === $value) { $tag['child'] = array('tag' => 'option', 'attributes' => array('value' => $value, 'selected' => 'selected')); } else { $tag['child'] = array('tag' => 'option', 'attributes' => array('value' => $value)); } } $this->assertTag($tag, $compare, 'expected select not found in ' . $compare); return; } else { if (get_class($expectation) === 'question_check_specified_fields_expectation') { $expect = (array) $expectation->expect; $compare = (array) $compare; foreach ($expect as $k => $v) { if (!array_key_exists($k, $compare)) { $this->fail("Property {$k} does not exist"); } if ($v != $compare[$k]) { $this->fail("Property {$k} is different"); } } $this->assertTrue(true); return; } else { if (get_class($expectation) === 'question_contains_tag_with_contents') { $this->assertTag(array('tag' => $expectation->tag, 'content' => $expectation->content), $compare, 'Looking for a ' . $expectation->tag . ' with content ' . $expectation->content . ' in ' . $compare); return; } } } } } } } } throw new coding_exception('Unknown expectiontion:' . get_class($expectation)); }
protected function check_output_contains_hidden_input($name, $value) { $attributes = array('type' => 'hidden', 'name' => $this->quba->get_field_prefix($this->slot) . $name, 'value' => $value); $this->assertTag($this->get_tag_matcher('input', $attributes), $this->currentoutput, 'Looking for a hidden input with attributes ' . html_writer::attributes($attributes) . ' in ' . $this->currentoutput); }
protected function check_output_contains_text_input($name, $value = null, $enabled = true) { $attributes = array('type' => 'text', 'name' => $this->quba->get_field_prefix($this->slot) . $name); if (!is_null($value)) { $attributes['value'] = $value; } if (!$enabled) { $attributes['readonly'] = 'readonly'; } $matcher = $this->get_tag_matcher('input', $attributes); $this->assertTag($matcher, $this->currentoutput, 'Looking for an input with attributes ' . html_writer::attributes($attributes) . ' in ' . $this->currentoutput); if ($enabled) { $matcher['attributes']['readonly'] = 'readonly'; $this->assertNotTag($matcher, $this->currentoutput, 'input with attributes ' . html_writer::attributes($attributes) . ' should not be read-only in ' . $this->currentoutput); } }