Added tests to vocabulary and ability to print by key press

This commit is contained in:
kplaczek
2018-05-18 21:47:43 +02:00
parent 625193e99e
commit db3f7772a6
5 changed files with 202 additions and 12 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace Tests\Unit;
use App\Paper\Vocabulary;
use Tests\TestCase;
class VocabularyTest extends TestCase
{
public function testGetExistingWordData()
{
$voc = new Vocabulary();
$data = $voc->getWordData('random');
$this->assertNotEmpty($data);
$element = $data->find('.wordPage[data-word="random"]');
$this->assertCount(1, $element);
}
public function testGetNonExistingWordData()
{
$nonExistingWord = time();
$voc = new Vocabulary();
$data = $voc->getWordData($nonExistingWord);
$this->assertNotEmpty($data);
$element = $data->find('.wordPage[data-word="random"]');
$this->assertCount(0, $element);
$elementNotFound = $data->find('.noresults[data-search="' . $nonExistingWord . '"]');
$this->assertCount(1, $elementNotFound);
}
public function testGetExistingWord()
{
$dummyWord = 'dummy';
$vot = new Vocabulary();
$word = $vot->getWord($dummyWord);
$this->assertEquals('en', $word->lang);
$this->assertEquals('dummy', $word->word);
$this->assertEquals('dump', $word->next);
$this->assertEquals('dumbstruck', $word->prev);
$this->assertEquals('Have you ever seen an entertainer make a doll look like its talking? The entertainer is using a dummy — a doll made to look like a person.', $word->short);
$this->assertEquals("A dummy is a type of doll that looks like a person. Entertainers called ventriloquists can make dummies appear to talk. The automobile industry uses dummies in cars to study how safe cars are during a crash. A dummy can also be anything that looks real but doesnt work: a fake. Actors in a play might use certain props that are dummies, such as a dummy laptop. Dummy is also an insult used to mean “an ignorant person.”", $word->long);
}
public function testGetRandomWord()
{
$vot = new Vocabulary();
$word = $vot->getRandomWord();
$this->assertNotNull($word);
}
public function testGetRandomWordData()
{
$vot = new Vocabulary();
$word = $vot->getRandomWord();
$this->assertNotNull($word);
$wordData = $vot->getWord($word);
$this->assertEquals('en', $wordData->lang);
$this->assertNotEmpty($wordData->word);
$this->assertNotEmpty($wordData->next);
$this->assertNotEmpty($wordData->prev);
$this->assertNotEmpty($wordData->short);
$this->assertNotEmpty($wordData->long);
}
}