2016-11-28 00:15:06 +01:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 01:30:12 +01:00
|
|
|
namespace Tests\Wallabag\Tools;
|
2016-11-28 00:15:06 +01:00
|
|
|
|
2017-12-16 22:17:42 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-11-28 00:15:06 +01:00
|
|
|
use Symfony\Component\Finder\Finder;
|
2024-02-19 01:30:12 +01:00
|
|
|
use Wallabag\Tools\Utils;
|
2016-11-28 00:15:06 +01:00
|
|
|
|
2017-12-16 22:17:42 +01:00
|
|
|
class UtilsTest extends TestCase
|
2016-11-28 00:15:06 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider examples
|
|
|
|
*/
|
2019-01-04 11:22:43 +01:00
|
|
|
public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
|
2016-11-28 00:15:06 +01:00
|
|
|
{
|
2019-01-04 11:22:43 +01:00
|
|
|
static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename);
|
2016-11-28 00:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function examples()
|
|
|
|
{
|
|
|
|
$examples = [];
|
2017-07-01 09:52:38 +02:00
|
|
|
$finder = (new Finder())->in(__DIR__ . '/samples');
|
2016-11-28 00:15:06 +01:00
|
|
|
foreach ($finder->getIterator() as $file) {
|
2019-01-04 11:22:43 +01: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-28 00:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $examples;
|
|
|
|
}
|
|
|
|
}
|