grav = $grav();
}
protected function _after()
{
}
public function testStartsWith()
{
$this->assertTrue(Utils::startsWith('english', 'en'));
$this->assertTrue(Utils::startsWith('English', 'En'));
$this->assertTrue(Utils::startsWith('ENGLISH', 'EN'));
$this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'EN'));
$this->assertFalse(Utils::startsWith('english', 'En'));
$this->assertFalse(Utils::startsWith('English', 'EN'));
$this->assertFalse(Utils::startsWith('ENGLISH', 'en'));
$this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'e'));
}
public function testEndsWith()
{
$this->assertTrue(Utils::endsWith('english', 'sh'));
$this->assertTrue(Utils::endsWith('EngliSh', 'Sh'));
$this->assertTrue(Utils::endsWith('ENGLISH', 'SH'));
$this->assertTrue(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::endsWith('english', 'de'));
$this->assertFalse(Utils::endsWith('EngliSh', 'sh'));
$this->assertFalse(Utils::endsWith('ENGLISH', 'Sh'));
$this->assertFalse(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testContains()
{
$this->assertTrue(Utils::contains('english', 'nglis'));
$this->assertTrue(Utils::contains('EngliSh', 'gliSh'));
$this->assertTrue(Utils::contains('ENGLISH', 'ENGLI'));
$this->assertTrue(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::contains('EngliSh', 'GLI'));
$this->assertFalse(Utils::contains('EngliSh', 'English'));
$this->assertFalse(Utils::contains('ENGLISH', 'SCH'));
$this->assertFalse(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testSubstrToString()
{
$this->assertEquals('en', Utils::substrToString('english', 'glish'));
$this->assertEquals('english', Utils::substrToString('english', 'test'));
$this->assertNotEquals('en', Utils::substrToString('english', 'lish'));
}
public function testMergeObjects()
{
$obj1 = new stdClass();
$obj1->test1 = 'x';
$obj2 = new stdClass();
$obj2->test2 = 'y';
$objMerged = Utils::mergeObjects($obj1, $obj2);
$this->assertObjectHasAttribute('test1', $objMerged);
$this->assertObjectHasAttribute('test2', $objMerged);
}
public function testDateFormats()
{
$dateFormats = Utils::dateFormats();
$this->assertTrue(is_array($dateFormats));
$this->assertContainsOnly('string', $dateFormats);
$default_format = $this->grav['config']->get('system.pages.dateformat.default');
if ($default_format !== null) {
$this->assertTrue(isset($dateFormats[$default_format]));
}
}
public function testTruncate()
{
$this->assertEquals('engli' . '…', Utils::truncate('english', 5));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('Th' . '…', Utils::truncate('This is a string to truncate', 2));
$this->assertEquals('engli' . '...', Utils::truncate('english', 5, true, " ", "..."));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('This ', Utils::truncate('This is a string to truncate', 3, true));
$this->assertEquals('', 6, true));
}
public function testSafeTruncate()
{
$this->assertEquals('This ', Utils::safeTruncate('This is a string to truncate', 1));
$this->assertEquals('This ', Utils::safeTruncate('This is a string to truncate', 4));
$this->assertEquals('This is ', Utils::safeTruncate('This is a string to truncate', 5));
}
public function testTruncateHtml()
{
$this->assertEquals('