72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?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 it’s 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 doesn’t 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);
|
||
|
||
}
|
||
}
|