-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
api/tests/unit/src/Markdown/Parser/CorrectAnswerExtractorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Tests\unit\src\Markdown\Parser; | ||
|
||
use App\Markdown\Parser\DocumentExtractor; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CorrectAnswerExtractorTest extends TestCase | ||
{ | ||
private string $document = ''; | ||
|
||
public function setUp(): void | ||
{ | ||
$filePath = '/var/www/html/tests/unit/src/Markdown/TestFixtures/question.html'; | ||
$this->document = file_get_contents($filePath); | ||
parent::setUp(); | ||
} | ||
|
||
public function testAnswerElement() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$questionNodes = $parser->getCorrectAnswerNodes(); | ||
|
||
self::assertSame('p', $questionNodes[4]->nodeName); | ||
} | ||
|
||
public function testAnswerValue() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$questionNodes = $parser->getCorrectAnswerNodes(); | ||
|
||
self::assertSame('Answer: 5', trim($questionNodes[4]->nodeValue)); | ||
} | ||
|
||
|
||
} |
75 changes: 75 additions & 0 deletions
75
api/tests/unit/src/Markdown/Parser/PossibleAnswerExtractorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace App\Tests\unit\src\Markdown\Parser; | ||
|
||
use App\Markdown\Parser\DocumentExtractor; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PossibleAnswerExtractorTest extends TestCase | ||
{ | ||
private string $document = ''; | ||
|
||
public function setUp(): void | ||
{ | ||
$filePath = '/var/www/html/tests/unit/src/Markdown/TestFixtures/question.html'; | ||
$this->document = file_get_contents($filePath); | ||
parent::setUp(); | ||
} | ||
|
||
public function testHeadingValue() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
|
||
self::assertSame('Possible answers', $nodes[0]->nodeValue); | ||
} | ||
|
||
public function testHeadingElement() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
|
||
self::assertSame('h2', $nodes[0]->nodeName); | ||
} | ||
|
||
public function testFirstPossibleAnswerValue() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
|
||
self::assertSame('[ ] 3', $nodes[2]->nodeValue); | ||
} | ||
|
||
public function testFirstPossibleAnswerElement() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
|
||
self::assertSame('li', $nodes[2]->nodeName); | ||
} | ||
|
||
|
||
public function testLastPossibleAnswerValue() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
$lastIndex = count($nodes) -1; | ||
|
||
self::assertSame('[ ] 5', $nodes[$lastIndex]->nodeValue); | ||
} | ||
|
||
public function testLastPossibleAnswerElement() | ||
{ | ||
$parser = new DocumentExtractor($this->document); | ||
$parser->extract(); | ||
$nodes = $parser->getPossibleAnswerNodes(); | ||
$lastIndex = count($nodes) -1; | ||
|
||
self::assertSame('li', $nodes[$lastIndex]->nodeName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<h1>This is the question</h1> | ||
<p>An example</p> | ||
<pre><code class="language-php"><?php echo "hello world"; | ||
// Hello</code></pre> | ||
<p>Another example</p> | ||
<pre><code class="language-php"><?php echo "hello world";</code></pre> | ||
<h2>Possible answers</h2> | ||
<ul> | ||
<li>[ ] 3</li> | ||
<li>[ ] 4</li> | ||
<li>[ ] 5</li> | ||
</ul> | ||
<details id="answer"> | ||
<summary> | ||
<b>Answer</b> | ||
</summary> | ||
<div> | ||
<p> | ||
Answer: <strong>5</strong> | ||
</p> | ||
</div> | ||
</details> |