<?php
// This file is part of Stack - http://stack.maths.ed.ac.uk//
//
// Stack is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Stack is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Stack.  If not, see <http://www.gnu.org/licenses/>.

namespace qtype_stack;

use qtype_stack_testcase;
use stack_answertest_test_data;

defined('MOODLE_INTERNAL') || die();

/**
 * Add in all the tests from answertestsfixtures.class into the unit testing framework.
 * These are exposed to users as documentation and google-ci should also run all the tests.
 *
 * @package    qtype_stack
 * @copyright  2016 The University of Edinburgh.
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
 */

require_once(__DIR__ . '/../locallib.php');
require_once(__DIR__ . '/../stack/answertest/controller.class.php');
require_once(__DIR__ . '/../stack/options.class.php');
require_once(__DIR__ . '/fixtures/test_base.php');
require_once(__DIR__ . '/fixtures/answertestfixtures.class.php');

/**
 * Add description here.
 * @group qtype_stack
 * @covers \stack_answertest_general_cas
 * @covers \stack_anstest
 */
final class answertest_general_fixtures_test extends qtype_stack_testcase {

    /**
     * Add description
     * @dataProvider answertest_fixtures
     */
    public function test_answertest($name, $test): void {
        list($passed, $error, $rawmark, $feedback, $ansnote, $anomalynote) = stack_answertest_test_data::run_test($test);

        $this->assertEquals($test->ansnote, $ansnote);
        $this->assertTrue($passed, $anomalynote);
    }

    // phpcs:ignore moodle.Commenting.MissingDocblock.MissingTestcaseMethodDescription
    public static function answertest_fixtures(): array {

        $tests = stack_answertest_test_data::get_all();
        $testdata = [];
        foreach ($tests as $test) {
            $testname = 'AT' . $test->name .
                    '( ' . $test->studentanswer . ', ' . $test->teacheranswer. ')';
            if ($test->options != '') {
                $testname .= ' Options: ' . $test->options;
            }
            $testdata[] = [$testname, $test];
        }
        return $testdata;
    }
}
