2016-11-27 23:15:06 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Tools;
|
2016-11-27 23:15:06 +00:00
|
|
|
|
2017-12-16 21:17:42 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-11-27 23:15:06 +00:00
|
|
|
use Symfony\Component\Finder\Finder;
|
2024-02-19 00:30:12 +00:00
|
|
|
use Wallabag\Tools\Utils;
|
2016-11-27 23:15:06 +00:00
|
|
|
|
2017-12-16 21:17:42 +00:00
|
|
|
class UtilsTest extends TestCase
|
2016-11-27 23:15:06 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider examples
|
|
|
|
*/
|
2019-01-04 10:22:43 +00:00
|
|
|
public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
|
2016-11-27 23:15:06 +00:00
|
|
|
{
|
2019-01-04 10:22:43 +00:00
|
|
|
static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename);
|
2016-11-27 23:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function examples()
|
|
|
|
{
|
|
|
|
$examples = [];
|
2017-07-01 07:52:38 +00:00
|
|
|
$finder = (new Finder())->in(__DIR__ . '/samples');
|
2016-11-27 23:15:06 +00:00
|
|
|
foreach ($finder->getIterator() as $file) {
|
2019-01-04 10:22:43 +00:00
|
|
|
preg_match('/-----CONTENT-----\s*(.*?)\s*-----READING_TIME-----\s*(.*)/sx', $file->getContents(), $match);
|
|
|
|
|
|
|
|
if (3 !== \count($match)) {
|
|
|
|
throw new \Exception('Sample file "' . $file->getRelativePathname() . '" as wrong definition, see README.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$examples[] = [
|
|
|
|
$file->getRelativePathname(),
|
|
|
|
$match[1], // content
|
|
|
|
$match[2], // reading time
|
|
|
|
];
|
2016-11-27 23:15:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $examples;
|
|
|
|
}
|
|
|
|
}
|