How to use generate method of namespace class

Best Atoum code snippet using namespace.generate

cc_asssesment.php

Source:cc_asssesment.php Github

copy

Full Screen

...219 * @param XMLGenericDocument $doc220 * @param DOMNode $item221 * @param string $namespace222 */223 public function generate_attributes(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {224 foreach ($this->metadata as $attribute => $value) {225 if (!is_null($value)) {226 if (!is_array($value)) {227 $doc->append_new_attribute_ns($item, $namespace, $attribute, $value);228 } else {229 $ns = key($value);230 $nval = current($value);231 if (!is_null($nval)) {232 $doc->append_new_attribute_ns($item, $ns, $attribute, $nval);233 }234 }235 }236 }237 }238 /**239 * @param XMLGenericDocument $doc240 * @param DOMNode $item241 * @param string $namespace242 */243 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {244 $qtimetadata = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::qtimetadata);245 foreach ($this->metadata as $label => $entry) {246 if (!is_null($entry)) {247 $qtimetadatafield = $doc->append_new_element_ns($qtimetadata, $namespace, cc_qti_tags::qtimetadatafield);248 $doc->append_new_element_ns($qtimetadatafield, $namespace, cc_qti_tags::fieldlabel, $label);249 $doc->append_new_element_ns($qtimetadatafield, $namespace, cc_qti_tags::fieldentry, $entry);250 }251 }252 }253}254class cc_question_metadata extends cc_question_metadata_base {255 public function set_category($value) {256 $this->set_setting(cc_qti_metadata::cc_question_category, $value);257 }258 public function set_weighting($value) {259 $this->set_setting(cc_qti_metadata::cc_weighting, $value);260 }261 public function enable_scoringpermitted($value = true) {262 $this->enable_setting_yesno(cc_qti_metadata::qmd_scoringpermitted, $value);263 }264 public function enable_computerscored($value = true) {265 $this->enable_setting_yesno(cc_qti_metadata::qmd_computerscored, $value);266 }267 /**268 *269 * Constructs metadata270 * @param string $profile271 * @throws InvalidArgumentException272 */273 public function __construct($profile) {274 if (!cc_qti_profiletype::valid($profile)) {275 throw new InvalidArgumentException('Invalid profile type!');276 }277 $this->set_setting(cc_qti_metadata::cc_profile, $profile);278 $this->set_setting(cc_qti_metadata::cc_question_category);279 $this->set_setting(cc_qti_metadata::cc_weighting );280 $this->set_setting(cc_qti_metadata::qmd_scoringpermitted);281 $this->set_setting(cc_qti_metadata::qmd_computerscored );282 }283}284class cc_assesment_metadata extends cc_question_metadata_base {285 public function enable_hints($value = true) {286 $this->enable_setting_yesno(cc_qti_metadata::qmd_hintspermitted, $value);287 }288 public function enable_solutions($value = true) {289 $this->enable_setting_yesno(cc_qti_metadata::qmd_solutionspermitted, $value);290 }291 public function enable_latesubmissions($value = true) {292 $this->enable_setting_yesno(cc_qti_metadata::cc_allow_late_submission, $value);293 }294 public function enable_feedback($value = true) {295 $this->enable_setting_yesno(cc_qti_metadata::qmd_feedbackpermitted, $value);296 }297 public function set_timelimit($value) {298 $ivalue = (int)$value;299 if (($ivalue < 0) || ($ivalue > 527401)) {300 throw new OutOfRangeException('Time limit value out of permitted range!');301 }302 $this->set_setting(cc_qti_metadata::qmd_timelimit, $value);303 }304 public function set_maxattempts($value) {305 $valid_values = array(cc_qti_values::Examination, cc_qti_values::unlimited, 1, 2, 3, 4, 5);306 if (!in_array($value, $valid_values)) {307 throw new OutOfRangeException('Max attempts has invalid value');308 }309 $this->set_setting(cc_qti_metadata::cc_maxattempts, $value);310 }311 public function __construct() {312 //prepared default values313 $this->set_setting(cc_qti_metadata::cc_profile , cc_qti_values::exam_profile);314 $this->set_setting(cc_qti_metadata::qmd_assessmenttype, cc_qti_values::Examination );315 $this->set_setting(cc_qti_metadata::qmd_scoretype , cc_qti_values::Percentage );316 //optional empty values317 $this->set_setting(cc_qti_metadata::qmd_feedbackpermitted );318 $this->set_setting(cc_qti_metadata::qmd_hintspermitted );319 $this->set_setting(cc_qti_metadata::qmd_solutionspermitted );320 $this->set_setting(cc_qti_metadata::qmd_timelimit );321 $this->set_setting(cc_qti_metadata::cc_allow_late_submission);322 $this->set_setting(cc_qti_metadata::cc_maxattempts );323 }324}325class cc_assesment_mattext extends cc_question_metadata_base {326 protected $value = null;327 public function __construct($value = null) {328 $this->set_setting(cc_qti_tags::texttype, cc_qti_values::texttype);329 $this->set_setting(cc_qti_tags::charset);//, 'ascii-us');330 $this->set_setting(cc_qti_tags::label);331 $this->set_setting(cc_qti_tags::uri);332 $this->set_setting(cc_qti_tags::width);333 $this->set_setting(cc_qti_tags::height);334 $this->set_setting(cc_qti_tags::x0);335 $this->set_setting(cc_qti_tags::y0);336 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml);337 $this->set_setting_wns(cc_qti_tags::xml_space, cc_xml_namespace::xml);//, 'default');338 $this->value = $value;339 }340 public function set_label($value) {341 $this->set_setting(cc_qti_tags::label, $value);342 }343 public function set_uri($value) {344 $this->set_setting(cc_qti_tags::uri, $value);345 }346 public function set_width_height($width = null, $height = null) {347 $this->set_setting(cc_qti_tags::width, $width);348 $this->set_setting(cc_qti_tags::height, $height);349 }350 public function set_coor($x = null, $y = null) {351 $this->set_setting(cc_qti_tags::x0, $x);352 $this->set_setting(cc_qti_tags::y0, $y);353 }354 public function set_lang($lang = null) {355 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml, $lang);356 }357 public function set_content($content, $type = cc_qti_values::texttype, $charset = null) {358 $this->value = $content;359 $this->set_setting(cc_qti_tags::texttype, $type);360 $this->set_setting(cc_qti_tags::charset, $charset);361 }362 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {363 $mattext = $doc->append_new_element_ns_cdata($item, $namespace, cc_qti_tags::mattext, $this->value);364 $this->generate_attributes($doc, $mattext, $namespace);365 }366}367class cc_assesment_matref {368 protected $linkref = null;369 public function __construct($linkref) {370 $this->linkref = $linkref;371 }372 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {373 $doc->append_new_element_ns($item, $namespace, cc_qti_tags::matref, $this->linkref);374 $doc->append_new_attribute_ns($node, $namespace, cc_qti_tags::linkrefid, $this->linkref);375 }376}377class cc_assesment_response_matref extends cc_assesment_matref {378 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {379 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::material_ref);380 $doc->append_new_attribute_ns($node, $namespace, cc_qti_tags::linkrefid, $this->linkref);381 }382}383class cc_assesment_matbreak {384 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {385 $doc->append_new_element_ns($item, $namespace, cc_qti_tags::matbreak);386 }387}388abstract class cc_assesment_material_base extends cc_question_metadata_base {389 /**390 * @var mixed391 */392 protected $mattag = null;393 protected $tagname = null;394 protected function set_tag_value($object) {395 $this->mattag = $object;396 }397 public function set_mattext(cc_assesment_mattext $object) {398 $this->set_tag_value($object);399 }400 public function set_matref(cc_assesment_matref $object) {401 $this->set_tag_value($object);402 }403 public function set_matbreak(cc_assesment_matbreak $object) {404 $this->set_tag_value($object);405 }406 public function set_lang($value) {407 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml, $value);408 }409 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {410 $material = $doc->append_new_element_ns($item, $namespace, $this->tagname);411 $this->generate_attributes($doc, $material, $namespace);412 if (!empty($this->mattag)) {413 $this->mattag->generate($doc, $material, $namespace);414 }415 return $material;416 }417}418class cc_assesment_altmaterial extends cc_assesment_material_base {419 public function __construct($value = null) {420 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml);421 $this->tagname = cc_qti_tags::altmaterial;422 }423}424class cc_assesment_material extends cc_assesment_material_base {425 protected $altmaterial = null;426 public function __construct($value = null) {427 $this->set_setting(cc_qti_tags::label);428 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml);429 $this->tagname = cc_qti_tags::material;430 }431 public function set_label($value) {432 $this->set_setting(cc_qti_tags::label, $value);433 }434 public function set_altmaterial(cc_assesment_altmaterial $object) {435 $this->altmaterial = $object;436 }437 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {438 $material = parent::generate($doc, $item, $namespace);439 if (!empty($this->altmaterial)) {440 $this->altmaterial->generate($doc, $material, $namespace);441 }442 }443}444class cc_assesment_rubric_base extends cc_question_metadata_base {445 protected $material = null;446 public function set_material($object) {447 $this->material = $object;448 }449 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {450 $rubric = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::rubric);451 if (!empty($this->material)) {452 $this->material->generate($doc, $rubric, $namespace);453 }454 }455}456class cc_assesment_presentation_material_base extends cc_question_metadata_base {457 protected $flowmats = array();458 public function add_flow_mat($object) {459 $this->flowmats[] = $object;460 }461 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {462 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::presentation_material);463 if (!empty($this->flowmats)) {464 foreach ($this->flowmats as $flow_mat) {465 $flow_mat->generate($doc, $node, $namespace);466 }467 }468 }469}470class cc_assesment_flow_mat_base extends cc_question_metadata_base {471 protected $mattag = null;472 protected function set_tag_value($object) {473 $this->mattag = $object;474 }475 public function set_flow_mat(cc_assesment_flow_mat_base $object) {476 $this->set_tag_value($object);477 }478 public function set_material(cc_assesment_material $object) {479 $this->set_tag_value($object);480 }481 public function set_material_ref(cc_assesment_matref $object) {482 $this->set_tag_value($object);483 }484 public function __construct($value = null) {485 $this->set_setting(cc_qti_tags::t_class);486 }487 public function set_class($value) {488 $this->set_setting(cc_qti_tags::t_class, $value);489 }490 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {491 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::flow_mat);492 $this->generate_attributes($doc, $node, $namespace);493 if (!empty($this->mattag)) {494 $this->mattag->generate($doc, $node, $namespace);495 }496 }497}498class cc_assesment_section extends cc_question_metadata_base {499 /**500 * @var array501 */502 protected $items = array();503 public function __construct() {504 $this->set_setting(cc_qti_tags::ident, cc_helpers::uuidgen('I_'));505 $this->set_setting(cc_qti_tags::title);506 $this->set_setting_wns(cc_qti_tags::xml_lang, cc_xml_namespace::xml);507 }508 public function set_ident($value) {509 $this->set_setting(cc_qti_tags::ident, $value);510 }511 public function set_title($value) {512 $this->set_setting(cc_qti_tags::title, $value);513 }514 public function set_lang($value) {515 $this->set_setting_wns(cc_qti_tags::xml_lang, cc_xml_namespace::xml, $value);516 }517 public function add_item(cc_assesment_section_item $object) {518 $this->items[] = $object;519 }520 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {521 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::section);522 $this->generate_attributes($doc, $node, $namespace);523 if (!empty($this->items)) {524 foreach ($this->items as $item) {525 $item->generate($doc, $node, $namespace);526 }527 }528 }529}530class cc_assesment_itemmetadata extends cc_question_metadata_base {531 public function add_metadata($object) {532 $this->metadata[] = $object;533 }534 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {535 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::itemmetadata);536 if (!empty($this->metadata)) {537 foreach ($this->metadata as $metaitem) {538 $metaitem->generate($doc, $node, $namespace);539 }540 }541 }542}543class cc_assesment_decvartype extends cc_question_metadata_base {544 public function __construct() {545 $this->set_setting(cc_qti_tags::varname, cc_qti_values::SCORE);546 $this->set_setting(cc_qti_tags::vartype, cc_qti_values::Integer);547 $this->set_setting(cc_qti_tags::minvalue);548 $this->set_setting(cc_qti_tags::maxvalue);549 }550 public function set_vartype($value) {551 $this->set_setting(cc_qti_tags::vartype, $value);552 }553 public function set_limits($min = null, $max = null) {554 $this->set_setting(cc_qti_tags::minvalue, $min);555 $this->set_setting(cc_qti_tags::maxvalue, $max);556 }557 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {558 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::decvar);559 $this->generate_attributes($doc, $node, $namespace);560 }561}562class cc_assignment_conditionvar_othertype extends cc_question_metadata_base {563 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {564 $doc->append_new_element_ns($item, $namespace, cc_qti_tags::other);565 }566}567class cc_assignment_conditionvar_varequaltype extends cc_question_metadata_base {568 protected $tagname = null;569 protected $answerid = null;570 public function __construct($value = null) {571 if (is_null($value)) {572 throw new InvalidArgumentException('Must not pass null!');573 }574 $this->answerid = $value;575 $this->set_setting(cc_qti_tags::respident);576 $this->set_setting(cc_qti_tags::case_);//, cc_qti_values::No );577 $this->tagname = cc_qti_tags::varequal;578 }579 public function set_respident($value) {580 $this->set_setting(cc_qti_tags::respident, $value);581 }582 public function enable_case($value = true) {583 $this->enable_setting_yesno(cc_qti_tags::case_, $value);584 }585 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {586 $node = $doc->append_new_element_ns($item, $namespace, $this->tagname, $this->answerid);587 $this->generate_attributes($doc, $node, $namespace);588 }589}590class cc_assignment_conditionvar_varsubstringtype extends cc_assignment_conditionvar_varequaltype {591 public function __construct($value) {592 parent::__construct($value);593 $this->tagname = cc_qti_tags::varsubstring;594 }595}596class cc_assignment_conditionvar_andtype extends cc_question_metadata_base {597 protected $not = null;598 protected $varequal = null;599 public function set_not(cc_assignment_conditionvar_varequaltype $object) {600 $this->not = $object;601 }602 public function set_varequal(cc_assignment_conditionvar_varequaltype $object) {603 $this->varequal = $object;604 }605 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {606 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::and_);607 if (!empty($this->not)) {608 $not = $doc->append_new_element_ns($node, $namespace, cc_qti_tags::not_);609 $this->not->generate($doc, $not, $namespace);610 }611 if (!empty($this->varequal)) {612 $this->varequal->generate($doc, $node, $namespace);613 }614 }615}616class cc_assignment_conditionvar extends cc_question_metadata_base {617 /**618 * @var cc_assignment_conditionvar_andtype619 */620 protected $and = null;621 /**622 * @var cc_assignment_conditionvar_othertype623 */624 protected $other = null;625 /**626 * @var cc_assignment_conditionvar_varequaltype627 */628 protected $varequal = null;629 /**630 * @var cc_assignment_conditionvar_varsubstringtype631 */632 protected $varsubstring = null;633 public function set_and(cc_assignment_conditionvar_andtype $object) {634 $this->and = $object;635 }636 public function set_other(cc_assignment_conditionvar_othertype $object) {637 $this->other = $object;638 }639 public function set_varequal(cc_assignment_conditionvar_varequaltype $object) {640 $this->varequal = $object;641 }642 public function set_varsubstring(cc_assignment_conditionvar_varsubstringtype $object) {643 $this->varsubstring = $object;644 }645 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {646 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::conditionvar);647 if (!empty($this->and)) {648 $this->and->generate($doc, $node, $namespace);649 }650 if (!empty($this->other)) {651 $this->other->generate($doc, $node, $namespace);652 }653 if (!empty($this->varequal)) {654 $this->varequal->generate($doc, $node, $namespace);655 }656 if (!empty($this->varsubstring)) {657 $this->varsubstring->generate($doc, $node, $namespace);658 }659 }660}661class cc_assignment_displayfeedbacktype extends cc_question_metadata_base {662 public function __construct() {663 $this->set_setting(cc_qti_tags::feedbacktype);664 $this->set_setting(cc_qti_tags::linkrefid);665 }666 public function set_feedbacktype($value) {667 $this->set_setting(cc_qti_tags::feedbacktype, $value);668 }669 public function set_linkrefid($value) {670 $this->set_setting(cc_qti_tags::linkrefid, $value);671 }672 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {673 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::displayfeedback);674 $this->generate_attributes($doc, $node, $namespace);675 }676}677class cc_assignment_setvartype extends cc_question_metadata_base {678 /**679 * @var integer680 */681 protected $tagvalue = null;682 public function __construct($tagvalue = 100) {683 $this->set_setting(cc_qti_tags::varname, cc_qti_values::SCORE);684 $this->set_setting(cc_qti_tags::action , cc_qti_values::Set );685 $this->tagvalue = $tagvalue;686 }687 public function set_varname($value) {688 $this->set_setting(cc_qti_tags::varname, $value);689 }690 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {691 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::setvar, $this->tagvalue);692 $this->generate_attributes($doc, $node, $namespace);693 }694}695class cc_assesment_respconditiontype extends cc_question_metadata_base {696 /**697 * @var cc_assignment_conditionvar698 */699 protected $conditionvar = null;700 protected $setvar = array();701 protected $displayfeedback = array();702 public function __construct() {703 $this->set_setting(cc_qti_tags::title);704 $this->set_setting(cc_qti_tags::continue_, cc_qti_values::No);705 }706 public function set_title($value) {707 $this->set_setting(cc_qti_tags::title, $value);708 }709 public function enable_continue($value = true) {710 $this->enable_setting_yesno(cc_qti_tags::continue_, $value);711 }712 public function set_conditionvar(cc_assignment_conditionvar $object) {713 $this->conditionvar = $object;714 }715 public function add_setvar(cc_assignment_setvartype $object) {716 $this->setvar[] = $object;717 }718 public function add_displayfeedback(cc_assignment_displayfeedbacktype $object) {719 $this->displayfeedback[] = $object;720 }721 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {722 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::respcondition);723 $this->generate_attributes($doc, $node, $namespace);724 if (!empty($this->conditionvar)) {725 $this->conditionvar->generate($doc, $node, $namespace);726 }727 if (!empty($this->setvar)) {728 foreach ($this->setvar as $setvar) {729 $setvar->generate($doc, $node, $namespace);730 }731 }732 if (!empty($this->displayfeedback)) {733 foreach ($this->displayfeedback as $displayfeedback) {734 $displayfeedback->generate($doc, $node, $namespace);735 }736 }737 }738}739class cc_assesment_resprocessingtype extends cc_question_metadata_base {740 /**741 * @var cc_assesment_decvartype742 */743 protected $decvar = null;744 /**745 * @var array746 */747 protected $respconditions = array();748 public function set_decvar(cc_assesment_decvartype $object) {749 $this->decvar = $object;750 }751 public function add_respcondition(cc_assesment_respconditiontype $object) {752 $this->respconditions[] = $object;753 }754 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {755 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::resprocessing);756 $outcomes = $doc->append_new_element_ns($node, $namespace, cc_qti_tags::outcomes);757 if (!empty($this->decvar)) {758 $this->decvar->generate($doc, $outcomes, $namespace);759 }760 if (!empty($this->respconditions)) {761 foreach ($this->respconditions as $rcond) {762 $rcond->generate($doc, $node, $namespace);763 }764 }765 }766}767class cc_assesment_itemfeedback_shintmaterial_base extends cc_question_metadata_base {768 /**769 * @var string770 */771 protected $tagname = null;772 /**773 * @var array774 */775 protected $flow_mats = array();776 /**777 * @var array778 */779 protected $materials = array();780 /**781 * @param cc_assesment_flow_mattype $object782 */783 public function add_flow_mat(cc_assesment_flow_mattype $object) {784 $this->flow_mats[] = $object;785 }786 /**787 * @param cc_assesment_material $object788 */789 public function add_material(cc_assesment_material $object) {790 $this->materials[] = $object;791 }792 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {793 $node = $doc->append_new_element_ns($item, $namespace, $this->tagname);794 if (!empty($this->flow_mats)) {795 foreach ($this->flow_mats as $flow_mat) {796 $flow_mat->generate($doc, $node, $namespace);797 }798 }799 if (!empty($this->materials)) {800 foreach ($this->materials as $material) {801 $material->generate($doc, $node, $namespace);802 }803 }804 }805}806class cc_assesment_itemfeedback_hintmaterial extends cc_assesment_itemfeedback_shintmaterial_base {807 public function __construct() {808 $this->tagname = cc_qti_tags::hint;809 }810}811class cc_assesment_itemfeedback_solutionmaterial extends cc_assesment_itemfeedback_shintmaterial_base {812 public function __construct() {813 $this->tagname = cc_qti_tags::solutionmaterial;814 }815}816class cc_assesment_itemfeedback_shintype_base extends cc_question_metadata_base {817 /**818 * @var string819 */820 protected $tagname = null;821 /**822 * @var array823 */824 protected $items = array();825 public function __construct() {826 $this->set_setting(cc_qti_tags::feedbackstyle, cc_qti_values::Complete);827 }828 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {829 $node = $doc->append_new_element_ns($item, $namespace, $this->tagname);830 $this->generate_attributes($doc, $node, $namespace);831 if (!empty($this->items)) {832 foreach ($this->items as $telement) {833 $telement->generate($doc, $node, $namespace);834 }835 }836 }837}838class cc_assesment_itemfeedback_solutiontype extends cc_assesment_itemfeedback_shintype_base {839 public function __construct() {840 parent::__construct();841 $this->tagname = cc_qti_tags::solution;842 }843 /**844 * @param cc_assesment_itemfeedback_solutionmaterial $object845 */846 public function add_solutionmaterial(cc_assesment_itemfeedback_solutionmaterial $object) {847 $this->items[] = $object;848 }849}850class cc_assesment_itemfeedbac_hinttype extends cc_assesment_itemfeedback_shintype_base {851 public function __construct() {852 parent::__construct();853 $this->tagname = cc_qti_tags::hint;854 }855 /**856 * @param cc_assesment_itemfeedback_hintmaterial $object857 */858 public function add_hintmaterial(cc_assesment_itemfeedback_hintmaterial $object) {859 $this->items[] = $object;860 }861}862class cc_assesment_itemfeedbacktype extends cc_question_metadata_base {863 /**864 * @var cc_assesment_flow_mattype865 */866 protected $flow_mat = null;867 /**868 * @var cc_assesment_material869 */870 protected $material = null;871 /**872 * @var cc_assesment_itemfeedback_solutiontype873 */874 protected $solution = null;875 protected $hint = null;876 public function __construct() {877 $this->set_setting(cc_qti_tags::ident, cc_helpers::uuidgen('I_'));878 $this->set_setting(cc_qti_tags::title);879 }880 /**881 * @param string $value882 */883 public function set_ident($value) {884 $this->set_setting(cc_qti_tags::ident, $value);885 }886 /**887 * @param string $value888 */889 public function set_title($value) {890 $this->set_setting(cc_qti_tags::title, $value);891 }892 /**893 * @param cc_assesment_flow_mattype $object894 */895 public function set_flow_mat(cc_assesment_flow_mattype $object) {896 $this->flow_mat = $object;897 }898 /**899 * @param cc_assesment_material $object900 */901 public function set_material(cc_assesment_material $object) {902 $this->material = $object;903 }904 /**905 * @param cc_assesment_itemfeedback_solutiontype $object906 */907 public function set_solution(cc_assesment_itemfeedback_solutiontype $object) {908 $this->solution = $object;909 }910 public function set_hint($object) {911 $this->hint = $object;912 }913 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {914 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::itemfeedback);915 $this->generate_attributes($doc, $node, $namespace);916 if (!empty($this->flow_mat) && empty($this->material)) {917 $this->flow_mat->generate($doc, $node, $namespace);918 }919 if (!empty($this->material) && empty($this->flow_mat)) {920 $this->material->generate($doc, $node, $namespace);921 }922 if (!empty($this->solution)) {923 $this->solution->generate($doc, $node, $namespace);924 }925 if (!empty($this->itemfeedback)) {926 $this->itemfeedback->generate($doc, $node, $namespace);927 }928 }929}930class cc_assesment_section_item extends cc_assesment_section {931 /**932 * @var cc_assesment_itemmetadata933 */934 protected $itemmetadata = null;935 /**936 * @var cc_assesment_presentation937 */938 protected $presentation = null;939 protected $resprocessing = array();940 protected $itemfeedback = array();941 public function set_itemmetadata(cc_assesment_itemmetadata $object) {942 $this->itemmetadata = $object;943 }944 public function set_presentation(cc_assesment_presentation $object) {945 $this->presentation = $object;946 }947 public function add_resprocessing(cc_assesment_resprocessingtype $object) {948 $this->resprocessing[] = $object;949 }950 public function add_itemfeedback(cc_assesment_itemfeedbacktype $object) {951 $this->itemfeedback[] = $object;952 }953 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {954 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::item);955 $this->generate_attributes($doc, $node, $namespace);956 if (!empty($this->itemmetadata)) {957 $this->itemmetadata->generate($doc, $node, $namespace);958 }959 if (!empty($this->presentation)) {960 $this->presentation->generate($doc, $node, $namespace);961 }962 if (!empty($this->resprocessing)) {963 foreach ($this->resprocessing as $resprocessing) {964 $resprocessing->generate($doc, $node, $namespace);965 }966 }967 if (!empty($this->itemfeedback)) {968 foreach ($this->itemfeedback as $itemfeedback) {969 $itemfeedback->generate($doc, $node, $namespace);970 }971 }972 }973}974class cc_assesment_render_choicetype extends cc_question_metadata_base {975 /**976 * @var array977 */978 protected $materials = array();979 /**980 * @var array981 */982 protected $material_refs = array();983 /**984 * @var array985 */986 protected $response_labels = array();987 /**988 * @var array989 */990 protected $flow_labels = array();991 public function __construct() {992 $this->set_setting(cc_qti_tags::shuffle, cc_qti_values::No);993 $this->set_setting(cc_qti_tags::minnumber);994 $this->set_setting(cc_qti_tags::maxnumber);995 }996 public function add_material(cc_assesment_material $object) {997 $this->materials[] = $object;998 }999 public function add_material_ref(cc_assesment_response_matref $object) {1000 $this->material_refs[] = $object;1001 }1002 public function add_response_label(cc_assesment_response_labeltype $object) {1003 $this->response_labels[] = $object;1004 }1005 public function add_flow_label($object) {1006 $this->flow_labels[] = $object;1007 }1008 public function enable_shuffle($value = true) {1009 $this->enable_setting_yesno(cc_qti_tags::shuffle, $value);1010 }1011 public function set_limits($min = null, $max = null) {1012 $this->set_setting(cc_qti_tags::minnumber, $min);1013 $this->set_setting(cc_qti_tags::maxnumber, $max);1014 }1015 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1016 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::render_choice);1017 $this->generate_attributes($doc, $node, $namespace);1018 if (!empty($this->materials)) {1019 foreach ($this->materials as $mattag) {1020 $mattag->generate($doc, $node, $namespace);1021 }1022 }1023 if (!empty($this->material_refs)) {1024 foreach ($this->material_refs as $matreftag) {1025 $matreftag->generate($doc, $node, $namespace);1026 }1027 }1028 if (!empty($this->response_labels)) {1029 foreach ($this->response_labels as $resplabtag) {1030 $resplabtag->generate($doc, $node, $namespace);1031 }1032 }1033 if (!empty($this->flow_labels)) {1034 foreach ($this->flow_labels as $flowlabtag) {1035 $flowlabtag->generate($doc, $node, $namespace);1036 }1037 }1038 }1039}1040class cc_assesment_flow_mattype extends cc_question_metadata_base {1041 /**1042 * @var cc_assesment_material1043 */1044 protected $material = null;1045 /**1046 * @var cc_assesment_response_matref1047 */1048 protected $material_ref = null;1049 /**1050 * @var cc_assesment_flow_mattype1051 */1052 protected $flow_mat = null;1053 public function __construct() {1054 $this->set_setting(cc_qti_tags::t_class);1055 }1056 public function set_class($value) {1057 $this->set_setting(cc_qti_tags::t_class, $value);1058 }1059 public function set_material(cc_assesment_material $object) {1060 $this->material = $object;1061 }1062 public function set_material_ref(cc_assesment_response_matref $object) {1063 $this->material_ref = $object;1064 }1065 public function set_flow_mat(cc_assesment_flow_mattype $object) {1066 $this->flow_mat = $object;1067 }1068 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1069 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::flow_mat);1070 $this->generate_attributes($doc, $node, $namespace);1071 if (!empty($this->flow_mat)) {1072 $this->flow_mat->generate($doc, $node, $namespace);1073 }1074 if (!empty($this->material)) {1075 $this->material->generate($doc, $node, $namespace);1076 }1077 if (!empty($this->material_ref)) {1078 $this->material_ref->generate($doc, $node, $namespace);1079 }1080 }1081}1082class cc_assesment_response_labeltype extends cc_question_metadata_base {1083 /**1084 * @var cc_assesment_material1085 */1086 protected $material = null;1087 /**1088 * @var cc_assesment_response_matref1089 */1090 protected $material_ref = null;1091 /**1092 * @var cc_assesment_flow_mattype1093 */1094 protected $flow_mat = null;1095 public function __construct() {1096 $this->set_setting(cc_qti_tags::ident, cc_helpers::uuidgen('I_'));1097 $this->set_setting(cc_qti_tags::labelrefid);1098 $this->set_setting(cc_qti_tags::rshuffle);1099 $this->set_setting(cc_qti_tags::match_group);1100 $this->set_setting(cc_qti_tags::match_max);1101 }1102 public function set_ident($value) {1103 $this->set_setting(cc_qti_tags::ident, $value);1104 }1105 public function get_ident() {1106 return $this->get_setting(cc_qti_tags::ident);1107 }1108 public function set_labelrefid($value) {1109 $this->set_setting(cc_qti_tags::labelrefid, $value);1110 }1111 public function enable_rshuffle($value = true) {1112 $this->enable_setting_yesno(cc_qti_tags::rshuffle, $value);1113 }1114 public function set_match_group($value) {1115 $this->set_setting(cc_qti_tags::match_group, $value);1116 }1117 public function set_match_max($value) {1118 $this->set_setting(cc_qti_tags::match_max, $value);1119 }1120 public function set_material(cc_assesment_material $object) {1121 $this->material = $object;1122 }1123 public function set_material_ref(cc_assesment_response_matref $object) {1124 $this->material_ref = $object;1125 }1126 public function set_flow_mat(cc_assesment_flow_mattype $object) {1127 $this->flow_mat = $object;1128 }1129 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1130 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::response_label);1131 $this->generate_attributes($doc, $node, $namespace);1132 if (!empty($this->material)) {1133 $this->material->generate($doc, $node, $namespace);1134 }1135 if (!empty($this->material_ref)) {1136 $this->material_ref->generate($doc, $node, $namespace);1137 }1138 if (!empty($this->flow_mat)) {1139 $this->flow_mat->generate($doc, $node, $namespace);1140 }1141 }1142}1143class cc_assesment_flow_labeltype extends cc_question_metadata_base {1144 /**1145 * @var cc_assesment_flow_labeltype1146 */1147 protected $flow_label = null;1148 /**1149 * @var cc_assesment_response_labeltype1150 */1151 protected $response_label = null;1152 public function __construct() {1153 $this->set_setting(cc_qti_tags::t_class);1154 }1155 public function set_class($value) {1156 $this->set_setting(cc_qti_tags::t_class, $value);1157 }1158 public function set_flow_label(cc_assesment_flow_labeltype $object) {1159 $this->flow_label = $object;1160 }1161 public function set_response_label(cc_assesment_response_labeltype $object) {1162 $this->response_label = $object;1163 }1164 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1165 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::flow_label);1166 $this->generate_attributes($doc, $node, $namespace);1167 if (!empty($this->material)) {1168 $this->material->generate($doc, $node, $namespace);1169 }1170 if (!empty($this->material_ref)) {1171 $this->material_ref->generate($doc, $node, $namespace);1172 }1173 if (!empty($this->response_label)) {1174 $this->response_label->generate($doc, $node, $namespace);1175 }1176 if (!empty($this->flow_label)) {1177 $this->flow_label->generate($doc, $node, $namespace);1178 }1179 }1180}1181class cc_assesment_render_fibtype extends cc_question_metadata_base {1182 /**1183 * @var cc_assesment_material1184 */1185 protected $material = null;1186 /**1187 * @var cc_assesment_response_matref1188 */1189 protected $material_ref = null;1190 /**1191 * @var cc_assesment_response_labeltype1192 */1193 protected $response_label = null;1194 /**1195 *1196 * Enter description here ...1197 * @var unknown_type1198 */1199 protected $flow_label = null;1200 public function __construct() {1201 $this->set_setting(cc_qti_tags::encoding );1202 $this->set_setting(cc_qti_tags::charset );1203 $this->set_setting(cc_qti_tags::rows );1204 $this->set_setting(cc_qti_tags::columns );1205 $this->set_setting(cc_qti_tags::maxchars );1206 $this->set_setting(cc_qti_tags::minnumber);1207 $this->set_setting(cc_qti_tags::maxnumber);1208 $this->set_setting(cc_qti_tags::prompt, cc_qti_values::Box);1209 $this->set_setting(cc_qti_tags::fibtype, cc_qti_values::String);1210 }1211 public function set_encoding($value) {1212 $this->set_setting(cc_qti_tags::encoding, $value);1213 }1214 public function set_charset($value) {1215 $this->set_setting(cc_qti_tags::charset, $value);1216 }1217 public function set_rows($value) {1218 $this->set_setting(cc_qti_tags::rows, $value);1219 }1220 public function set_columns($value) {1221 $this->set_setting(cc_qti_tags::columns, $value);1222 }1223 public function set_maxchars($value) {1224 $this->set_setting(cc_qti_tags::columns, $value);1225 }1226 public function set_limits($min = null, $max = null) {1227 $this->set_setting(cc_qti_tags::minnumber, $min);1228 $this->set_setting(cc_qti_tags::maxnumber, $max);1229 }1230 public function set_prompt($value) {1231 $this->set_setting(cc_qti_tags::prompt, $value);1232 }1233 public function set_fibtype($value) {1234 $this->set_setting(cc_qti_tags::fibtype, $value);1235 }1236 public function set_material(cc_assesment_material $object) {1237 $this->material = $object;1238 }1239 public function set_material_ref(cc_assesment_response_matref $object) {1240 $this->material_ref = $object;1241 }1242 public function set_response_label(cc_assesment_response_labeltype $object) {1243 $this->response_label = $object;1244 }1245 public function set_flow_label($object) {1246 $this->flow_label = $object;1247 }1248 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1249 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::render_fib);1250 $this->generate_attributes($doc, $node, $namespace);1251 if (!empty($this->material) && empty($this->material_ref)) {1252 $this->material->generate($doc, $node, $namespace);1253 }1254 if (!empty($this->material_ref) && empty($this->material)) {1255 $this->material_ref->generate($doc, $node, $namespace);1256 }1257 if (!empty($this->response_label)) {1258 $this->response_label->generate($doc, $node, $namespace);1259 }1260 if (!empty($this->flow_label)) {1261 $this->flow_label->generate($doc, $node, $namespace);1262 }1263 }1264}1265class cc_response_lidtype extends cc_question_metadata_base {1266 /**1267 * @var string1268 */1269 protected $tagname = null;1270 /**1271 * @var cc_assesment_material1272 */1273 protected $material = null;1274 /**1275 * @var cc_assesment_response_matref1276 */1277 protected $material_ref = null;1278 /**1279 * @var cc_assesment_render_choicetype1280 */1281 protected $render_choice = null;1282 /**1283 * @var cc_assesment_render_fibtype1284 */1285 protected $render_fib = null;1286 public function __construct() {1287 $this->set_setting(cc_qti_tags::rcardinality, cc_qti_values::Single);1288 $this->set_setting(cc_qti_tags::rtiming);1289 $this->set_setting(cc_qti_tags::ident, cc_helpers::uuidgen('I_'));1290 $this->tagname = cc_qti_tags::response_lid;1291 }1292 public function set_rcardinality($value) {1293 $this->set_setting(cc_qti_tags::rcardinality, $value);1294 }1295 public function enable_rtiming($value = true) {1296 $this->enable_setting_yesno(cc_qti_tags::rtiming, $value);1297 }1298 public function set_ident($value) {1299 $this->set_setting(cc_qti_tags::ident, $value);1300 }1301 public function get_ident() {1302 return $this->get_setting(cc_qti_tags::ident);1303 }1304 public function set_material_ref(cc_assesment_response_matref $object) {1305 $this->material_ref = $object;1306 }1307 public function set_material(cc_assesment_material $object) {1308 $this->material = $object;1309 }1310 public function set_render_choice(cc_assesment_render_choicetype $object) {1311 $this->render_choice = $object;1312 }1313 public function set_render_fib(cc_assesment_render_fibtype $object) {1314 $this->render_fib = $object;1315 }1316 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1317 $node = $doc->append_new_element_ns($item, $namespace, $this->tagname);1318 $this->generate_attributes($doc, $node, $namespace);1319 if (!empty($this->material) && empty($this->material_ref)) {1320 $this->material->generate($doc, $node, $namespace);1321 }1322 if (!empty($this->material_ref) && empty($this->material)) {1323 $this->material_ref->generate($doc, $node, $namespace);1324 }1325 if (!empty($this->render_choice) && empty($this->render_fib)) {1326 $this->render_choice->generate($doc, $node, $namespace);1327 }1328 if (!empty($this->render_fib) && empty($this->render_choice)) {1329 $this->render_fib->generate($doc, $node, $namespace);1330 }1331 }1332}1333class cc_assesment_response_strtype extends cc_response_lidtype {1334 public function __construct() {1335 $rtt = parent::__construct();1336 $this->tagname = cc_qti_tags::response_str;1337 }1338}1339class cc_assesment_flowtype extends cc_question_metadata_base {1340 /**1341 * @var cc_assesment_flowtype1342 */1343 protected $flow = null;1344 /**1345 * @var cc_assesment_material1346 */1347 protected $material = null;1348 /**1349 * @var cc_assesment_response_matref1350 */1351 protected $material_ref = null;1352 /**1353 * @var cc_response_lidtype1354 */1355 protected $response_lid = null;1356 /**1357 * @var cc_assesment_response_strtype1358 */1359 protected $response_str = null;1360 public function __construct() {1361 $this->set_setting(cc_qti_tags::t_class);1362 }1363 public function set_class($value) {1364 $this->set_setting(cc_qti_tags::t_class, $value);1365 }1366 public function set_flow(cc_assesment_flowtype $object) {1367 $this->flow = $object;1368 }1369 public function set_material(cc_assesment_material $object) {1370 $this->material = $object;1371 }1372 public function set_material_ref(cc_assesment_response_matref $object) {1373 $this->material_ref = $object;1374 }1375 public function set_response_lid(cc_response_lidtype $object) {1376 $this->response_lid = $object;1377 }1378 public function set_response_str(cc_assesment_response_strtype $object) {1379 $this->response_str = $object;1380 }1381 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1382 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::flow);1383 $this->generate_attributes($doc, $node, $namespace);1384 if (!empty($this->flow)) {1385 $this->flow->generate($doc, $node, $namespace);1386 }1387 if (!empty($this->material)) {1388 $this->material->generate($doc, $node, $namespace);1389 }1390 if (!empty($this->response_lid)) {1391 $this->response_lid->generate($doc, $node, $namespace);1392 }1393 if (!empty($this->response_str)) {1394 $this->response_str->generate($doc, $node, $namespace);1395 }1396 }1397}1398class cc_assesment_presentation extends cc_question_metadata_base {1399 /**1400 * @var cc_assesment_flowtype1401 */1402 protected $flow = null;1403 /**1404 * @var cc_assesment_material1405 */1406 protected $material = null;1407 /**1408 * @var cc_response_lidtype1409 */1410 protected $response_lid = null;1411 /**1412 * @var cc_assesment_response_strtype1413 */1414 protected $response_str = null;1415 public function __construct() {1416 $this->set_setting(cc_qti_tags::label);1417 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml);1418 $this->set_setting(cc_qti_tags::x0);1419 $this->set_setting(cc_qti_tags::y0);1420 $this->set_setting(cc_qti_tags::width);1421 $this->set_setting(cc_qti_tags::height);1422 }1423 public function set_label($value) {1424 $this->set_setting(cc_qti_tags::label, $value);1425 }1426 public function set_lang($value) {1427 $this->set_setting_wns(cc_qti_tags::xml_lang , cc_xml_namespace::xml, $value);1428 }1429 public function set_coor($x = null, $y = null) {1430 $this->set_setting(cc_qti_tags::x0, $x);1431 $this->set_setting(cc_qti_tags::y0, $y);1432 }1433 public function set_size($width = null, $height = null) {1434 $this->set_setting(cc_qti_tags::width, $width);1435 $this->set_setting(cc_qti_tags::height, $height);1436 }1437 public function set_flow(cc_assesment_flowtype $object) {1438 $this->flow = $object;1439 }1440 public function set_material(cc_assesment_material $object) {1441 $this->material = $object;1442 }1443 public function set_response_lid(cc_response_lidtype $object) {1444 $this->response_lid = $object;1445 }1446 public function set_response_str(cc_assesment_response_strtype $object) {1447 $this->response_str = $object;1448 }1449 public function generate(XMLGenericDocument &$doc, DOMNode &$item, $namespace) {1450 $node = $doc->append_new_element_ns($item, $namespace, cc_qti_tags::presentation);1451 $this->generate_attributes($doc, $node, $namespace);1452 if (!empty($this->flow)) {1453 $this->flow->generate($doc, $node, $namespace);1454 }1455 if (!empty($this->material) && empty($this->flow)) {1456 $this->material->generate($doc, $node, $namespace);1457 }1458 if (!empty($this->response_lid) && empty($this->flow)) {1459 $this->response_lid->generate($doc, $node, $namespace);1460 }1461 if (!empty($this->response_str) && empty($this->flow)) {1462 $this->response_str->generate($doc, $node, $namespace);1463 }1464 }1465}1466class assesment1_resurce_file extends general_cc_file {1467 const deafultname = 'assesment.xml';1468 protected $rootns = 'xmlns';1469 protected $rootname = cc_qti_tags::questestinterop;1470 protected $ccnamespaces = array('xmlns' => 'http://www.imsglobal.org/xsd/ims_qtiasiv1p2',1471 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance');1472 protected $ccnsnames = array('xmlns' => 'http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_4/ims_qtiasiv1p2_localised.xsd');1473 /**1474 * @var string1475 */1476 protected $assessment_title = 'Untitled';1477 /**1478 * @var cc_assesment_metadata1479 */1480 protected $metadata = null;1481 /**1482 * @var cc_assesment_rubric_base1483 */1484 protected $rubric = null;1485 /**1486 * @var cc_assesment_presentation_material_base1487 */1488 protected $presentation_material = null;1489 /**1490 * @var cc_assesment_section1491 */1492 protected $section = null;1493 public function set_metadata(cc_assesment_metadata $object) {1494 $this->metadata = $object;1495 }1496 public function set_rubric(cc_assesment_rubric_base $object) {1497 $this->rubric = $object;1498 }1499 public function set_presentation_material(cc_assesment_presentation_material_base $object) {1500 $this->presentation_material = $object;1501 }1502 public function set_section(cc_assesment_section $object) {1503 $this->section = $object;1504 }1505 public function set_title($value) {1506 $this->assessment_title = self::safexml($value);1507 }1508 protected function on_save() {1509 $rns = $this->ccnamespaces[$this->rootns];1510 //root assesment element - required1511 $assessment = $this->append_new_element_ns($this->root, $rns, cc_qti_tags::assessment);1512 $this->append_new_attribute_ns($assessment, $rns, cc_qti_tags::ident, cc_helpers::uuidgen('QDB_'));1513 $this->append_new_attribute_ns($assessment, $rns, cc_qti_tags::title, $this->assessment_title);1514 //metadata - optional1515 if (!empty($this->metadata)) {1516 $this->metadata->generate($this, $assessment, $rns);1517 }1518 //rubric - optional1519 if (!empty($this->rubric)) {1520 $this->rubric->generate($this, $assessment, $rns);1521 }1522 //presentation_material - optional1523 if (!empty($this->presentation_material)) {1524 $this->presentation_material->generate($this, $assessment, $rns);1525 }1526 //section - required1527 if (!empty($this->section)) {1528 $this->section->generate($this, $assessment, $rns);1529 }1530 return true;1531 }1532}1533class assesment11_resurce_file extends assesment1_resurce_file {1534 protected $ccnsnames = array('xmlns' => 'http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_qtiasiv1p2p1_v1p0.xsd');1535}1536abstract class cc_assesment_helper {1537 public static $correct_fb = null;1538 public static $incorrect_fb = null;1539 public static function add_feedback($qitem, $content, $content_type, $ident) {1540 if (empty($content)) {1541 return false;1542 }1543 $qitemfeedback = new cc_assesment_itemfeedbacktype();1544 $qitem->add_itemfeedback($qitemfeedback);1545 if (!empty($ident)) {1546 $qitemfeedback->set_ident($ident);1547 }1548 $qflowmat = new cc_assesment_flow_mattype();1549 $qitemfeedback->set_flow_mat($qflowmat);1550 $qmaterialfb = new cc_assesment_material();1551 $qflowmat->set_material($qmaterialfb);1552 $qmattext = new cc_assesment_mattext();1553 $qmaterialfb->set_mattext($qmattext);1554 $qmattext->set_content($content, $content_type);1555 return true;1556 }1557 public static function add_answer($qresponse_choice, $content, $content_type) {1558 $qresponse_label = new cc_assesment_response_labeltype();1559 $qresponse_choice->add_response_label($qresponse_label);1560 $qrespmaterial = new cc_assesment_material();1561 $qresponse_label->set_material($qrespmaterial);1562 $qrespmattext = new cc_assesment_mattext();1563 $qrespmaterial->set_mattext($qrespmattext);1564 $qrespmattext->set_content($content, $content_type);1565 return $qresponse_label;1566 }1567 public static function add_response_condition() {1568 }1569 public static function add_assesment_description($rt, $content, $contenttype) {1570 if (empty($rt) || empty($content)) {1571 return;1572 }1573 $activity_rubric = new cc_assesment_rubric_base();1574 $rubric_material = new cc_assesment_material();1575 $activity_rubric->set_material($rubric_material);1576 $rubric_mattext = new cc_assesment_mattext();1577 $rubric_material->set_label('Summary');1578 $rubric_material->set_mattext($rubric_mattext);1579 $rubric_mattext->set_content($content, $contenttype);1580 $rt->set_rubric($activity_rubric);1581 }1582 /**1583 *1584 * Enter description here ...1585 * @param unknown_type $qdoc1586 * @param unknown_type $manifest1587 * @param cc_assesment_section $section1588 * @param unknown_type $rootpath1589 * @param unknown_type $contextid1590 * @param unknown_type $outdir1591 */1592 public static function process_questions(&$qdoc, &$manifest, cc_assesment_section &$section, $rootpath, $contextid, $outdir) {1593 $question_file = $rootpath . DIRECTORY_SEPARATOR . 'questions.xml';1594 //load questions file1595 $questions = new XMLGenericDocument();1596 if (!$questions->load($question_file)) {1597 return false;1598 }1599 pkg_resource_dependencies::instance()->reset();1600 $qids = explode(',', $qdoc->nodeValue('/activity/quiz/questions'));1601 foreach ($qids as $value) {1602 if (intval($value) == 0) {1603 continue;1604 }1605 $question_node = $questions->node("//question_category/questions/question[@id='{$value}']");1606 if (empty($question_node)) {1607 continue;1608 }1609 //process question1610 //question type1611 $qtype = $questions->nodeValue('qtype', $question_node);1612 $question_processor = null;1613 switch ($qtype) {1614 case 'multichoice':1615 $single_correct_answer = (int)$questions->nodeValue('plugin_qtype_multichoice_question/multichoice/single', $question_node) > 0;1616 if ($single_correct_answer) {1617 $question_processor = new cc_assesment_question_multichoice($qdoc, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);1618 $question_processor->generate();1619 } else {1620 //TODO: implement1621 }1622 ;1623 break;1624 default:1625 ;1626 break;1627 }1628 }1629 //return dependencies1630 return pkg_resource_dependencies::instance()->get_deps();1631 }1632}1633class cc_assesment_question_proc_base {1634 /**1635 * @var XMLGenericDocument1636 */1637 protected $quiz = null;1638 /**1639 * @var XMLGenericDocument1640 */1641 protected $questions = null;1642 /**1643 * @var cc_manifest1644 */1645 protected $manifest = null;1646 /**1647 * @var cc_assesment_section1648 */1649 protected $section = null;1650 /**1651 * @var DOMElement1652 */1653 protected $question_node = null;1654 /**1655 * @var string1656 */1657 protected $rootpath = null;1658 /**1659 * @var string1660 */1661 protected $contextid = null;1662 /**1663 * @var string1664 */1665 protected $outdir = null;1666 /**1667 * @var string1668 */1669 protected $qtype = null;1670 /**1671 * @var cc_question_metadata1672 */1673 protected $qmetadata = null;1674 /**1675 * @var cc_assesment_section_item1676 */1677 protected $qitem = null;1678 /**1679 * @var cc_assesment_presentation1680 */1681 protected $qpresentation = null;1682 /**1683 * @var cc_response_lidtype1684 */1685 protected $qresponse_lid = null;1686 protected $qresprocessing = null;1687 protected $correct_grade_value = null;1688 protected $correct_answer_node_id = null;1689 protected $correct_answer_ident = null;1690 protected $total_grade_value = null;1691 protected $answerlist = null;1692 protected $general_feedback = null;1693 protected $correct_feedbacks = array();1694 protected $incorrect_feedbacks = array();1695 /**1696 * @param XMLGenericDocument $questions1697 * @param cc_manifest $manifest1698 * @param cc_assesment_section $section1699 * @param DOMElement $question_node1700 * @param string $rootpath1701 * @param string $contextid1702 * @param string $outdir1703 */1704 public function __construct(XMLGenericDocument &$quiz, XMLGenericDocument &$questions, cc_manifest &$manifest, cc_assesment_section &$section, &$question_node, $rootpath, $contextid, $outdir) {1705 $this->quiz = $quiz;1706 $this->questions = $questions;1707 $this->manifest = $manifest;1708 $this->section = $section;1709 $this->question_node = $question_node;1710 $this->rootpath = $rootpath;1711 $this->contextid = $contextid;1712 $this->outdir = $outdir;1713 //1714 $qitem = new cc_assesment_section_item();1715 $this->section->add_item($qitem);1716 $qitem->set_title($this->questions->nodeValue('name', $this->question_node));1717 $this->qitem = $qitem;1718 }1719 public function on_generate_metadata() {1720 if (empty($this->qmetadata)) {1721 $this->qmetadata = new cc_question_metadata($this->qtype);1722 //Get weighting value1723 $weighting_value = (int)$this->questions->nodeValue('defaultmark', $this->question_node);1724 if ($weighting_value > 1) {1725 $this->qmetadata->set_weighting($weighting_value);1726 }1727 $rts = new cc_assesment_itemmetadata();1728 $rts->add_metadata($this->qmetadata);1729 $this->qitem->set_itemmetadata($rts);1730 }1731 }1732 public function on_generate_presentation() {1733 if (empty($this->qpresentation)) {1734 $qpresentation = new cc_assesment_presentation();1735 $this->qitem->set_presentation($qpresentation);1736 //add question text1737 $qmaterial = new cc_assesment_material();1738 $qmattext = new cc_assesment_mattext();1739 $question_text = $this->questions->nodeValue('questiontext', $this->question_node);1740 $result = cc_helpers::process_linked_files( $question_text,1741 $this->manifest,1742 $this->rootpath,1743 $this->contextid,1744 $this->outdir);1745 $qmattext->set_content($result[0], cc_qti_values::htmltype);1746 $qmaterial->set_mattext($qmattext);1747 $qpresentation->set_material($qmaterial);1748 $this->qpresentation = $qpresentation;1749 pkg_resource_dependencies::instance()->add($result[1]);1750 }1751 }1752 public function on_generate_answers() {}1753 public function on_generate_feedbacks() {1754 $general_question_feedback = $this->questions->nodeValue('generalfeedback', $this->question_node);1755 if (empty($general_question_feedback)) {1756 return;1757 }1758 $name = 'general_fb';1759 //Add question general feedback - the one that should be always displayed1760 $result = cc_helpers::process_linked_files( $general_question_feedback,1761 $this->manifest,1762 $this->rootpath,1763 $this->contextid,1764 $this->outdir);1765 cc_assesment_helper::add_feedback($this->qitem,1766 $result[0],1767 cc_qti_values::htmltype,1768 $name);1769 pkg_resource_dependencies::instance()->add($result[1]);1770 $this->general_feedback = $name;1771 }1772 public function on_generate_response_processing() {1773 $qresprocessing = new cc_assesment_resprocessingtype();1774 $this->qitem->add_resprocessing($qresprocessing);1775 $qdecvar = new cc_assesment_decvartype();1776 $qresprocessing->set_decvar($qdecvar);1777 //according to the Common Cartridge 1.1 Profile: Implementation document1778 //this should always be set to 0, 100 in case of question type that is not essay1779 $qdecvar->set_limits(0,100);1780 $qdecvar->set_vartype(cc_qti_values::Decimal);1781 $this->qresprocessing = $qresprocessing;1782 }1783 public function generate() {1784 $this->on_generate_metadata();1785 $this->on_generate_presentation();1786 $this->on_generate_answers();1787 $this->on_generate_feedbacks();1788 $this->on_generate_response_processing();1789 }1790}1791class cc_assesment_question_multichoice extends cc_assesment_question_proc_base {1792 public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {1793 parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);1794 $this->qtype = cc_qti_profiletype::multiple_choice;1795 /**1796 *1797 * What is needed is a maximum grade value taken from the answer fraction1798 * It is supposed to always be between 1 and 0 in decimal representation,1799 * however that is not always the case so a change in test was needed1800 * but since we support here one correct answer type1801 * correct answer would always have to be 11802 */1803 $correct_answer_node = $this->questions->node("plugin_qtype_multichoice_question/answers/answer[fraction!=0.0000000]", $this->question_node);1804 if (empty($correct_answer_node)) {1805 throw new RuntimeException('No correct answer!');1806 }1807 $this->correct_answer_node_id = $this->questions->nodeValue('@id', $correct_answer_node);1808 $maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');1809 $this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';1810 }1811 public function on_generate_answers() {1812 //add responses holder1813 $qresponse_lid = new cc_response_lidtype();1814 $this->qresponse_lid = $qresponse_lid;1815 $this->qpresentation->set_response_lid($qresponse_lid);1816 $qresponse_choice = new cc_assesment_render_choicetype();1817 $qresponse_lid->set_render_choice($qresponse_choice);1818 //Mark that question has only one correct answer -1819 //which applies for multiple choice and yes/no questions1820 $qresponse_lid->set_rcardinality(cc_qti_values::Single);1821 //are we to shuffle the responses?1822 $shuffle_answers = (int)$this->quiz->nodeValue('/activity/quiz/shuffleanswers') > 0;1823 $qresponse_choice->enable_shuffle($shuffle_answers);1824 $answerlist = array();1825 $qa_responses = $this->questions->nodeList('plugin_qtype_multichoice_question/answers/answer', $this->question_node);1826 foreach ($qa_responses as $node) {1827 $answer_content = $this->questions->nodeValue('answertext', $node);1828 $id = ((int)$this->questions->nodeValue('@id', $node) == $this->correct_answer_node_id);1829 $result = cc_helpers::process_linked_files( $answer_content,1830 $this->manifest,1831 $this->rootpath,1832 $this->contextid,1833 $this->outdir);1834 $qresponse_label = cc_assesment_helper::add_answer( $qresponse_choice,1835 $result[0],1836 cc_qti_values::htmltype);1837 pkg_resource_dependencies::instance()->add($result[1]);1838 $answer_ident = $qresponse_label->get_ident();1839 $feedback_ident = $answer_ident.'_fb';1840 if (empty($this->correct_answer_ident) && $id) {1841 $this->correct_answer_ident = $answer_ident;1842 }1843 //add answer specific feedbacks if not empty1844 $content = $this->questions->nodeValue('feedback', $node);1845 if (!empty($content)) {1846 $result = cc_helpers::process_linked_files( $content,1847 $this->manifest,1848 $this->rootpath,1849 $this->contextid,1850 $this->outdir);1851 cc_assesment_helper::add_feedback( $this->qitem,1852 $result[0],1853 cc_qti_values::htmltype,1854 $feedback_ident);1855 pkg_resource_dependencies::instance()->add($result[1]);1856 $answerlist[$answer_ident] = $feedback_ident;1857 }1858 }1859 $this->answerlist = $answerlist;1860 }1861 public function on_generate_feedbacks() {1862 parent::on_generate_feedbacks();1863 //Question combined feedbacks1864 $correct_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/correctfeedback', $this->question_node);1865 $incorrect_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/incorrectfeedback', $this->question_node);1866 $proc = array('correct_fb' => $correct_question_fb, 'general_incorrect_fb' => $incorrect_question_fb);1867 foreach ($proc as $ident => $content) {1868 if (empty($content)) {1869 continue;1870 }1871 $result = cc_helpers::process_linked_files( $content,1872 $this->manifest,1873 $this->rootpath,1874 $this->contextid,1875 $this->outdir);1876 cc_assesment_helper::add_feedback( $this->qitem,1877 $result[0],1878 cc_qti_values::htmltype,1879 $ident);1880 pkg_resource_dependencies::instance()->add($result[1]);1881 if ($ident == 'correct_fb') {1882 $this->correct_feedbacks[] = $ident;1883 } else {1884 $this->incorrect_feedbacks[] = $ident;1885 }1886 }1887 }1888 public function on_generate_response_processing() {1889 parent::on_generate_response_processing();1890 //respconditions1891 /**1892 * General unconditional feedback must be added as a first respcondition1893 * without any condition and just displayfeedback (if exists)1894 */1895 if (!empty($this->general_feedback)) {1896 $qrespcondition = new cc_assesment_respconditiontype();1897 $qrespcondition->set_title('General feedback');1898 $this->qresprocessing->add_respcondition($qrespcondition);1899 $qrespcondition->enable_continue();1900 //define the condition for success1901 $qconditionvar = new cc_assignment_conditionvar();1902 $qrespcondition->set_conditionvar($qconditionvar);1903 $qother = new cc_assignment_conditionvar_othertype();...

Full Screen

Full Screen

GeneratorTest.php

Source:GeneratorTest.php Github

copy

Full Screen

...37 protected $_ioObject;38 /**39 * @var Filesystem\Directory\Write40 */41 private $generatedDirectory;42 /**43 * @var Filesystem\Directory\Read44 */45 private $logDirectory;46 /**47 * @var string48 */49 private $testRelativePath = './Magento/Framework/Code/GeneratorTest/';50 /**51 * @inheritdoc52 */53 protected function setUp(): void54 {55 $objectManager = Bootstrap::getObjectManager();56 /** @var Filesystem $filesystem */57 $filesystem = $objectManager->get(Filesystem::class);58 $this->generatedDirectory = $filesystem->getDirectoryWrite(DirectoryList::GENERATED_CODE);59 $this->generatedDirectory->create($this->testRelativePath);60 $this->logDirectory = $filesystem->getDirectoryRead(DirectoryList::LOG);61 $generatedDirectoryAbsolutePath = $this->generatedDirectory->getAbsolutePath();62 $this->_ioObject = new Generator\Io(new Filesystem\Driver\File(), $generatedDirectoryAbsolutePath);63 $this->_generator = $objectManager->create(64 Generator::class,65 [66 'ioObject' => $this->_ioObject,67 'generatedEntities' => [68 ExtensionAttributesInterfaceFactoryGenerator::ENTITY_TYPE =>69 ExtensionAttributesInterfaceFactoryGenerator::class,70 DIGenerator\Factory::ENTITY_TYPE => DIGenerator\Factory::class,71 DIGenerator\Proxy::ENTITY_TYPE => DIGenerator\Proxy::class,72 InterceptionGenerator\Interceptor::ENTITY_TYPE => InterceptionGenerator\Interceptor::class,73 ]74 ]75 );76 $this->_generator->setObjectManager($objectManager);77 }78 /**79 * @inheritdoc80 */81 protected function tearDown(): void82 {83 $this->_generator = null;84 if ($this->generatedDirectory->isExist($this->testRelativePath)) {85 if (!$this->generatedDirectory->isWritable($this->testRelativePath)) {86 $this->generatedDirectory->changePermissionsRecursively($this->testRelativePath, 0775, 0664);87 }88 $this->generatedDirectory->delete($this->testRelativePath);89 }90 }91 protected function _clearDocBlock($classBody)92 {93 return preg_replace('/(\/\*[\w\W]*)\nclass/', 'class', $classBody);94 }95 /**96 * Generates a new class Factory file and compares with the sample.97 *98 * @param $className99 * @param $generateType100 * @param $expectedDataPath101 * @dataProvider generateClassFactoryDataProvider102 */103 public function testGenerateClassFactory($className, $generateType, $expectedDataPath)104 {105 $factoryClassName = $className . $generateType;106 $this->assertEquals(Generator::GENERATION_SUCCESS, $this->_generator->generateClass($factoryClassName));107 $factory = Bootstrap::getObjectManager()->create($factoryClassName);108 $this->assertInstanceOf($className, $factory->create());109 $content = $this->_clearDocBlock(110 file_get_contents($this->_ioObject->generateResultFileName($factoryClassName))111 );112 $expectedContent = $this->_clearDocBlock(113 file_get_contents(__DIR__ . $expectedDataPath)114 );115 $this->assertEquals($expectedContent, $content);116 }117 /**118 * DataProvider for testGenerateClassFactory119 *120 * @return array121 */122 public function generateClassFactoryDataProvider()123 {124 return [125 'factory_with_namespace' => [126 'className' => self::CLASS_NAME_WITH_NAMESPACE,127 'generateType' => 'Factory',128 'expectedDataPath' => '/_expected/SourceClassWithNamespaceFactory.php.sample'129 ],130 'factory_with_nested_namespace' => [131 'classToGenerate' => self::CLASS_NAME_WITH_NESTED_NAMESPACE,132 'generateType' => 'Factory',133 'expectedDataPath' => '/_expected/SourceClassWithNestedNamespaceFactory.php.sample'134 ],135 'ext_interface_factory_with_namespace' => [136 'classToGenerate' => self::EXTENSION_CLASS_NAME_WITH_NAMESPACE,137 'generateType' => 'InterfaceFactory',138 'expectedDataPath' => '/_expected/SourceClassWithNamespaceExtensionInterfaceFactory.php.sample'139 ],140 'ext_interface_factory_with_nested_namespace' => [141 'classToGenerate' => self::EXTENSION_CLASS_NAME_WITH_NESTED_NAMESPACE,142 'generateType' => 'InterfaceFactory',143 'expectedDataPath' => '/_expected/SourceClassWithNestedNamespaceExtensionInterfaceFactory.php.sample'144 ],145 ];146 }147 /**148 * @param $className149 * @param $generateType150 * @param $expectedDataPath151 * @dataProvider generateClassDataProvider152 */153 public function testGenerateClass($className, $generateType, $expectedDataPath)154 {155 $generateClassName = $className . $generateType;156 $this->assertEquals(Generator::GENERATION_SUCCESS, $this->_generator->generateClass($generateClassName));157 $instance = Bootstrap::getObjectManager()->create($generateClassName);158 $this->assertInstanceOf($className, $instance);159 $content = $this->_clearDocBlock(160 file_get_contents($this->_ioObject->generateResultFileName($generateClassName))161 );162 $expectedContent = $this->_clearDocBlock(163 file_get_contents(__DIR__ . $expectedDataPath)164 );165 $this->assertEquals($expectedContent, $content);166 }167 /**168 * DataProvider for testGenerateClass169 *170 * @return array171 */172 public function generateClassDataProvider()173 {174 return [175 'proxy' => [176 'className' => self::CLASS_NAME_WITH_NAMESPACE,177 'generateType' => '\Proxy',178 'expectedDataPath' => '/_expected/SourceClassWithNamespaceProxy.php.sample'179 ],180 'interceptor' => [181 'className' => self::CLASS_NAME_WITH_NAMESPACE,182 'generateType' => '\Interceptor',183 'expectedDataPath' => '/_expected/SourceClassWithNamespaceInterceptor.php.sample'184 ]185 ];186 }187 /**188 * It tries to generate a new class file when the generated directory is read-only189 */190 public function testGeneratorClassWithErrorSaveClassFile()191 {192 $factoryClassName = self::CLASS_NAME_WITH_NAMESPACE . 'Factory';193 $msgPart = 'Class ' . $factoryClassName . ' generation error: The requested class did not generate properly, '194 . 'because the \'generated\' directory permission is read-only.';195 $regexpMsgPart = preg_quote($msgPart);196 $this->expectException(\RuntimeException::class);197 $this->expectExceptionMessageMatches("/.*$regexpMsgPart.*/");198 $this->generatedDirectory->changePermissionsRecursively($this->testRelativePath, 0555, 0444);199 $generatorResult = $this->_generator->generateClass($factoryClassName);200 $this->assertFalse($generatorResult);201 $pathToSystemLog = $this->logDirectory->getAbsolutePath('system.log');202 $this->assertContains($msgPart, file_get_contents($pathToSystemLog));203 }204}...

Full Screen

Full Screen

MockGeneratorTest.php

Source:MockGeneratorTest.php Github

copy

Full Screen

...14 */15 public function throwWhenFunctionNameNotStringWhileGeneration($invalidFunctionName)16 {17 $generator = new MockGenerator();18 $generator->generate('namespace', $invalidFunctionName);19 }20 /**21 * @test22 *23 * @dataProvider provideEmpties24 *25 * @expectedException InvalidArgumentException26 * @expectedExceptionMessage Given function name is empty27 */28 public function throwWhenFunctionEmptyWhileGeneration($emptyFunctionName)29 {30 $generator = new MockGenerator();31 $generator->generate('namespace', $emptyFunctionName);32 }33 /**34 * @test35 *36 * @dataProvider provideNotStringTypes37 *38 * @expectedException InvalidArgumentException39 * @expectedExceptionMessage Invalid namespace provided40 */41 public function throwWhenNamespaceNotStringWhileGeneration($invalidNamespace)42 {43 $generator = new MockGenerator();44 $generator->generate($invalidNamespace, 'function');45 }46 /**47 * @test48 *49 * @dataProvider provideEmpties50 *51 * @expectedException LogicException52 * @expectedExceptionMessage Given namespace is empty53 */54 public function throwWhenNamespaceEmptyWhileGeneration($emptyNamespace)55 {56 $generator = new MockGenerator();57 $generator->generate($emptyNamespace, 'function');58 }59 /**60 * @test61 */62 public function shouldAllowToCheckWhetherFunctionMocked()63 {64 $generator = new MockGenerator();65 $this->assertTrue($generator->hasGenerated(__NAMESPACE__, 'mocked_function'), 'Should be mocked function');66 }67 /**68 * @test69 */70 public function shouldAllowToCheckWhetherFunctionMockedOrUserDefined()71 {72 $generator = new MockGenerator();73 $this->assertFalse($generator->hasGenerated(__NAMESPACE__, 'user_defined_function'), 'Should be user defined function');74 }75 /**76 * @test77 *78 * @expectedException LogicException79 * @expectedExceptionMessage The function `user_defined_function` in the namespace `Fumocker\Tests` has already been defined by a user80 */81 public function throwIfUserAlreadyDefineFunctionInTheNamespace()82 {83 $generator = new MockGenerator();84 $generator->generate(__NAMESPACE__, 'user_defined_function');85 }86 /**87 * @test88 *89 * @expectedException LogicException90 * @expectedExceptionMessage The function `mocked_function` in the namespace `Fumocker\Tests` has been already mocked91 */92 public function throwIfMockedFunctionAlreadyGeneratedInTheNamespace()93 {94 $generator = new MockGenerator();95 $generator->generate(__NAMESPACE__, 'mocked_function');96 }97 /**98 * @test99 */100 public function shouldGenerateMockedFunction()101 {102 //guard103 $this->assertFunctionNotExists(__NAMESPACE__, 'test_generate_function_mock');104 $generator = new MockGenerator();105 $generator->generate(__NAMESPACE__, 'test_generate_function_mock');106 $this->assertFunctionExists(__NAMESPACE__, 'test_generate_function_mock');107 $this->assertTrue($generator->hasGenerated(__NAMESPACE__, 'test_generate_function_mock'));108 }109 /**110 * @test111 */112 public function shouldGenerateConstantWhileGeneratingFunctionMock()113 {114 //guard115 $this->assertFunctionNotExists(__NAMESPACE__, 'test_set_identifier');116 $generator = new MockGenerator();117 $generator->generate(__NAMESPACE__, 'test_set_identifier');118 $mockedFunctionConstant = __NAMESPACE__ . '\\' . '__FUMOCKER_TEST_SET_IDENTIFIER';119 $this->assertTrue(defined($mockedFunctionConstant));120 }121 /**122 * @test123 */124 public function shouldRedirectMockedFunctionCallToAssignedCallable()125 {126 //guard127 $this->assertFunctionNotExists(__NAMESPACE__, 'test_redirect_call_to_callable');128 $mockCallable = $this->getMock('\stdClass', array('__invoke'));129 $mockCallable130 ->expects($this->once())131 ->method('__invoke')132 ;133 $generator = new MockGenerator();134 $generator->generate(__NAMESPACE__, 'test_redirect_call_to_callable');135 CallbackRegistry::getInstance()->set(__NAMESPACE__, 'test_redirect_call_to_callable', $mockCallable);136 $this->assertFunctionExists(__NAMESPACE__, 'test_redirect_call_to_callable');137 test_redirect_call_to_callable();138 }139 /**140 * @test141 */142 public function shouldProxyMockedFunctionArgumentsToCallable()143 {144 //guard145 $this->assertFunctionNotExists(__NAMESPACE__, 'test_proxy_arguments_to_callable');146 $expectedFirstArgument = 'foo';147 $expectedSecondArgument = array('bar');148 $expectedThirdArgument = new \stdClass();149 $mockCallable = $this->getMock('\stdClass', array('__invoke'));150 $mockCallable151 ->expects($this->once())152 ->method('__invoke')153 ->with(154 $this->equalTo($expectedFirstArgument),155 $this->equalTo($expectedSecondArgument),156 $this->equalTo($expectedThirdArgument)157 )158 ;159 $generator = new MockGenerator();160 $generator->generate(__NAMESPACE__, 'test_proxy_arguments_to_callable');161 CallbackRegistry::getInstance()->set(__NAMESPACE__, 'test_proxy_arguments_to_callable', $mockCallable);162 $this->assertFunctionExists(__NAMESPACE__, 'test_proxy_arguments_to_callable');163 test_proxy_arguments_to_callable($expectedFirstArgument, $expectedSecondArgument, $expectedThirdArgument);164 }165 /**166 * @test167 */168 public function shouldReturnCallableResultAsMockedFunction()169 {170 //guard171 $this->assertFunctionNotExists(__NAMESPACE__, 'test_return_callable_result');172 $expectedResult = 'foo';173 $mockCallable = $this->getMock('\stdClass', array('__invoke'));174 $mockCallable175 ->expects($this->once())176 ->method('__invoke')177 ->will($this->returnValue($expectedResult))178 ;179 $generator = new MockGenerator();180 $generator->generate(__NAMESPACE__, 'test_return_callable_result');181 CallbackRegistry::getInstance()->set(__NAMESPACE__, 'test_return_callable_result' ,$mockCallable);182 $this->assertFunctionExists(__NAMESPACE__, 'test_return_callable_result');183 $this->assertEquals($expectedResult, test_return_callable_result());184 }185 public function assertFunctionExists($namespace, $functionName)186 {187 $this->assertTrue(function_exists($namespace . '\\' . $functionName));188 }189 public function assertFunctionNotExists($namesppace, $functionName)190 {191 $this->assertFalse(function_exists($namesppace . '\\' . $functionName));192 }193 /**194 * @static...

Full Screen

Full Screen

generate

Using AI Code Generation

copy

Full Screen

1echo namespace\generate();2echo namespace\generate();3echo namespace\generate();4echo namespace\generate();5echo namespace\generate();6echo namespace\generate();7echo namespace\generate();8echo namespace\generate();9echo namespace\generate();10echo namespace\generate();11echo namespace\generate();12echo namespace\generate();13echo namespace\generate();14echo namespace\generate();15echo namespace\generate();16echo namespace\generate();17echo namespace\generate();18echo namespace\generate();19echo namespace\generate();20echo namespace\generate();21echo namespace\generate();22echo namespace\generate();23echo namespace\generate();

Full Screen

Full Screen

generate

Using AI Code Generation

copy

Full Screen

1use My\Full\Classname as Another;2use My\Full\NSname;3namespace My\Full;4use My\Full\NSname as NSname;5namespace My\Full\NSname;6use My\Full\Classname as Another;7namespace My\Full\NSname\subns;8use My\Full\NSname as NSname;9namespace My\Full\NSname\subns;10use My\Full\NSname\Classname as Cls;11namespace My\Full\NSname\subns;12use My\Full\NSname\Classname;13namespace My\Full\NSname\subns;14use My\Full\NSname\Classname as Another;15namespace My\Full;16use My\Full\NSname\Classname as Another, My\Full\NSname\subns\Classname;17namespace My\Full\NSname\subns;18use My\Full\NSname\Classname as Another, My\Full\NSname\subns\Classname;

Full Screen

Full Screen

generate

Using AI Code Generation

copy

Full Screen

1$namespace = new namespace\Class();2$namespace->generate();3$namespace = new namespace\Class();4$namespace->generate();5$namespace = new namespace\Class();6$namespace->generate();7$namespace = new namespace\Class();8$namespace->generate();9$namespace = new namespace\Class();10$namespace->generate();11$namespace = new namespace\Class();12$namespace->generate();13$namespace = new namespace\Class();14$namespace->generate();15$namespace = new namespace\Class();16$namespace->generate();17$namespace = new namespace\Class();18$namespace->generate();19$namespace = new namespace\Class();20$namespace->generate();21$namespace = new namespace\Class();22$namespace->generate();23$namespace = new namespace\Class();24$namespace->generate();25$namespace = new namespace\Class();26$namespace->generate();27$namespace = new namespace\Class();28$namespace->generate();29$namespace = new namespace\Class();30$namespace->generate();31$namespace = new namespace\Class();32$namespace->generate();33$namespace = new namespace\Class();34$namespace->generate();

Full Screen

Full Screen

generate

Using AI Code Generation

copy

Full Screen

1$gen = new \namespace\class();2$gen->generate();3$gen = new \namespace\class();4$gen->generate();5$gen = new \namespace\class();6$gen->generate();7$gen = new \namespace\class();8$gen->generate();9$gen = new \namespace\class();10$gen->generate();11$gen = new \namespace\class();

Full Screen

Full Screen

generate

Using AI Code Generation

copy

Full Screen

1$namespace->generate($path, $name);2$namespace->generate($path, $name);3$namespace->generate($path, $name);4$namespace->generate($path, $name);5$namespace->generate($path, $name);6$namespace->generate($path, $name);7$namespace->generate($path, $name);8$namespace->generate($path, $name);9$namespace->generate($path, $name);10$namespace->generate($path, $name);11$namespace->generate($path, $name);12$namespace->generate($path, $name);13$namespace->generate($path, $name);14$namespace->generate($path, $name);15$namespace->generate($path, $name);16$namespace->generate($path, $name);17$namespace->generate($path, $name);18$namespace->generate($path, $name);19$namespace->generate($path, $name);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful