Exemplo n.º 1
0
 public function tryToTest(AcceptanceTester $I)
 {
     $this->allTests = loadFromJson(__DIR__ . '/../tests.json');
     $this->currentTest = [];
     //idčka první odpovědi k otázkám v testu
     $I->wantTo('fill test and download results');
     $I->amOnPage('/login.php?id=127');
     $I->click('input[type="submit"]');
     $I->seeInCurrentUrl('test');
     $I->see('testu stiskem');
     for ($i = 1; $i <= 30; $i++) {
         $questionText = $I->grabTextFrom("~{$i}.<\\/b> otázka \\(.*?\\) - +<b>(.*?)<\\/b>~");
         $answer1number = $I->grabTextFrom("~<TD VALIGN=\"MIDDLE\"><INPUT TYPE=\"radio\" VALUE=\"(\\d+)\" NAME=\"a{$i}\" \\/><\\/TD><TD>(.*?)<BR /></TD>~i");
         $this->currentTest[] = $answer1number;
         if (array_key_exists($answer1number, $this->allTests)) {
         } else {
             /** @var Answer[] $answers */
             $answers = [];
             $answersCount = $I->getNumberOfElements("input[name=a{$i}]");
             for ($j = 0; $j < $answersCount; $j++) {
                 $number = $answer1number + $j;
                 $answerText = $I->grabTextFrom("~<TD VALIGN=\"MIDDLE\"><INPUT TYPE=\"radio\" VALUE=\"{$number}\" NAME=\"a{$i}\" \\/><\\/TD><TD>(.*?)<BR /></TD>~i");
                 $answers[] = new Answer($answerText, null, $number, false);
             }
             $this->allTests[$answer1number] = new Question($questionText, $answers);
         }
     }
     //naklikání nevyzkoušených odpovědí
     foreach ($this->currentTest as $answer1number) {
         /** @var Question $question */
         $question = $this->allTests[$answer1number];
         $I->wantTo('select correct answer of ' . json_encode($question));
         if ($question->hasCorrectAnswer()) {
             $id = $question->correctAnswer->id;
             $I->click("input[value=\"{$id}\"]");
             continue;
         }
         foreach ($question->answers as $answer) {
             if (!$answer->tried) {
                 //první nevyzkoušená otázka
                 $id = $answer->id;
                 $I->click("input[value=\"{$id}\"]");
                 $question->selected = $answer;
                 $answer->tried = true;
                 break;
             }
         }
     }
     //submit formuláře
     $I->click('input[type=button]');
     //přečtení správnosti
     $i = 0;
     foreach ($this->currentTest as $answer1number) {
         /** @var Question $question */
         $question = $this->allTests[$answer1number];
         $i++;
         //číslo otázky
         if (!$question->hasCorrectAnswer()) {
             $image = $I->grabTextFrom("~<img alt=\"status\" src=\"(.*?)\"(.*?)</td><td><b>{$i}\\.~i");
             if ($image == 'img/icon_good.jpg') {
                 $question->selected->correct = true;
                 $question->correctAnswer = $question->selected;
             }
         }
     }
     foreach ($this->allTests as $questionText => $question) {
         $question->selected = null;
     }
     file_put_contents('tests.json', json_encode($this->allTests, JSON_PRETTY_PRINT));
 }
Exemplo n.º 2
0
/**
 * Created by PhpStorm.
 * User: Azathoth
 * Date: 2. 1. 2016
 * Time: 18:49
 */
require_once 'utils.php';
//if (preg_match("~php~i", "PHP is the web scripting language of choice.", $matches)) {
//	echo var_dump($matches);
//} else {
//	echo "A match was not found.";
//}
//$test = []; //question => correct answer
//$test = json_decode(file_get_contents(__DIR__ . '/../tests.json'), true);
//var_dump($test);
//$array1 = array("id1" => "value1");
//
//$array2 = array("id2" => "value2", "id3" => "value3", "id4" => "value4");
//
//$array3 = array_merge($array1, $array2/*, $arrayN, $arrayN*/);
//$array4 = $array1 + $array2;
//
//echo '<pre>';
//var_dump($array3);
//var_dump($array4);
//echo '</pre>';
/** @var Question[] $allTests */
$allTests = loadFromJson(__DIR__ . '/../tests.json');
ksort($allTests);
file_put_contents(__DIR__ . '/../testsSorted.json', json_encode($allTests, JSON_PRETTY_PRINT));