-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💚 more unittests
- Loading branch information
Showing
7 changed files
with
205 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Kirby\Cms\Page; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class BoostTest extends TestCase | ||
{ | ||
public function randomPage(): ?Page | ||
{ | ||
return site()->index()->notTemplate('home')->shuffle()->first(); | ||
} | ||
|
||
public function randomPageWithChildren(): ?Page | ||
{ | ||
$page = null; | ||
while(!$page) { | ||
$rp = $this->randomPage(); | ||
if ($rp->hasChildren()) { | ||
$page = $rp; | ||
} | ||
} | ||
return $page; | ||
} | ||
|
||
public function testHelperBolt() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$randomPage->boost(); | ||
$this->assertEquals($randomPage->id(), bolt($randomPage->diruri())->id()); | ||
} | ||
|
||
public function testHelperModified() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$randomPage->boost(); | ||
$this->assertEquals($randomPage->modified(), modified($randomPage->id())); | ||
} | ||
|
||
public function testHelperBoost() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$randomPage->boost(); | ||
$this->assertEquals($randomPage->id(), boost($randomPage->boostid()->value())->id()); | ||
} | ||
|
||
public function testPageMethodBolt() | ||
{ | ||
$randomPage = $this->randomPageWithChildren(); | ||
$lastChild = $randomPage->children()->last(); | ||
$this->assertEquals( | ||
$lastChild->id(), | ||
$randomPage->bolt($lastChild->slug())->id() | ||
); | ||
} | ||
|
||
public function testPageMethodBoost() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$this->assertTrue($randomPage->boost()); | ||
} | ||
|
||
public function testPageMethodIsBoosted() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$randomPage->deleteContentCache(); | ||
|
||
$this->assertFalse($randomPage->isBoosted()); | ||
$this->assertTrue($randomPage->boost()); | ||
$this->assertTrue($randomPage->isBoosted()); | ||
} | ||
|
||
public function testPageMethodBoostIDField() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$this->assertEquals($randomPage->boostid()->value(), $randomPage->boostIDField()->value()); | ||
|
||
$this->assertEquals($randomPage->boostid()->value(), $randomPage->BOOSTID()); | ||
} | ||
|
||
public function testPageMethodTinyUrl() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$this->assertStringEndsWith('/x/' . $randomPage->boostid()->value(), $randomPage->tinyUrl()); | ||
} | ||
|
||
public function testPagesMethodBoost() | ||
{ | ||
$randomPage = $this->randomPageWithChildren(); | ||
|
||
\Bnomei\BoostIndex::singleton()->index(true); | ||
$before = \Bnomei\BoostIndex::singleton()->count(); | ||
$this->assertIsFloat($randomPage->children()->boostIndexRemove()); | ||
$after = \Bnomei\BoostIndex::singleton()->count(); | ||
$this->assertEquals($after, $before - $randomPage->children()->count()); | ||
|
||
$before = \Bnomei\BoostIndex::singleton()->count(); | ||
$this->assertIsFloat($randomPage->children()->boostIndexAdd()); | ||
$after = \Bnomei\BoostIndex::singleton()->count(); | ||
$this->assertEquals($after, $before + $randomPage->children()->count()); | ||
|
||
$this->assertIsFloat($randomPage->children()->boost()); | ||
$this->assertIsFloat(site()->boost()); | ||
} | ||
|
||
public function testPagesMethodBoostmark() | ||
{ | ||
$randomPage = $this->randomPageWithChildren(); | ||
|
||
\Bnomei\BoostIndex::singleton()->index(true); | ||
\Bnomei\BoostIndex::singleton()->flush(); | ||
$this->assertIsFloat($randomPage->children()->unboost()); | ||
$before = \Bnomei\BoostIndex::singleton()->count(); | ||
$boostmark = $randomPage->children()->boostmark(); | ||
$this->assertIsArray($boostmark); | ||
$this->assertEquals($randomPage->children()->count(), $boostmark['count']); | ||
$after = \Bnomei\BoostIndex::singleton()->count(); | ||
$this->assertEquals($after, $before + $randomPage->children()->count()); | ||
$boostmark2 = $randomPage->children()->boostmark(); | ||
$this->assertEquals($boostmark2['checksum'], $boostmark['checksum']); | ||
|
||
// trigger file write | ||
kirby()->impersonate('kirby'); | ||
$randomPage->update([ | ||
'title' => $randomPage->title()->value(), | ||
]); | ||
$boostmark3 = site()->boostmark(); | ||
$this->assertIsArray($boostmark3); | ||
$this->assertNotEquals($boostmark3['checksum'], $boostmark['checksum']); | ||
} | ||
|
||
public function testFieldMethodsBoost() | ||
{ | ||
$randomPage = $this->randomPage(); | ||
$many = $randomPage->related()->fromBoostIDs(); | ||
$this->assertNotNull($many); | ||
|
||
kirby()->impersonate('kirby'); | ||
$randomPage = $randomPage->update([ | ||
'related' => $randomPage->related()->split()[0], | ||
]); | ||
$one = $randomPage->related()->fromBoostID(); | ||
$this->assertNotNull($many); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters