You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/Website/tests/testGateways/testAnswers.php

60 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
use PHPUnit\Framework\TestCase;
use gateways\GatewayAnswer;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertNotEquals;
class testAnswers extends TestCase
{
public function testAddAnswer()
{
$gateway = new GatewayAnswer();
$answer = array(
'content' => 'This is a test answer',
'idquestion' => 1
);
$answerId = $gateway->addAnswer($answer);
assertNotEquals($answerId, null);
$gateway->deleteAnswer($answerId);
$answerId = $gateway->getAnswerByID($answerId);
assertEquals($answerId, null);
}
public function testGetAnswerByID()
{
$gateway = new GatewayAnswer();
$answer = $gateway->getAnswerByID(5);
assertEquals($answer['content'], '4');
}
public function testGetAnswersByIDQuestions()
{
$gateway = new GatewayAnswer();
$answers = $gateway->getAnswersByIDQuestions(1);
assertEquals($answers[0]['content'], '4log_2(1)');
assertEquals($answers[1]['content'], '1 log_2(4)');
assertEquals($answers[2]['content'], '-2');
assertEquals($answers[3]['content'], '{log_2(1)}/{log_2(4)}');
}
public function testUpdateAnswer()
{
$gateway = new GatewayAnswer();
$answer = array(
'content' => 'This is a test answer',
'idquestion' => 1
);
$answerId = $gateway->addAnswer($answer);
$answer = array(
'id' => $answerId,
'content' => 'This is a test answer updated',
'idquestion' => 1
);
$gateway->updateAnswer($answerId, $answer);
$answer = $gateway->getAnswerByID($answerId);
assertEquals($answer['content'], 'This is a test answer updated');
$gateway->deleteAnswer($answerId);
}
}