mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Added Popular books list with relevant tests
This commit is contained in:
38
tests/ActivityTrackingTest.php
Normal file
38
tests/ActivityTrackingTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ActivityTrackingTest extends TestCase
|
||||
{
|
||||
|
||||
public function testRecentlyViewedBooks()
|
||||
{
|
||||
$books = \BookStack\Book::all()->take(10);
|
||||
|
||||
$this->asAdmin()->visit('/books')
|
||||
->dontSeeInElement('#recents', $books[0]->name)
|
||||
->dontSeeInElement('#recents', $books[1]->name)
|
||||
->visit($books[0]->getUrl())
|
||||
->visit($books[1]->getUrl())
|
||||
->visit('/books')
|
||||
->seeInElement('#recents', $books[0]->name)
|
||||
->seeInElement('#recents', $books[1]->name);
|
||||
}
|
||||
|
||||
public function testPopularBooks()
|
||||
{
|
||||
$books = \BookStack\Book::all()->take(10);
|
||||
|
||||
$this->asAdmin()->visit('/books')
|
||||
->dontSeeInElement('#popular', $books[0]->name)
|
||||
->dontSeeInElement('#popular', $books[1]->name)
|
||||
->visit($books[0]->getUrl())
|
||||
->visit($books[1]->getUrl())
|
||||
->visit($books[0]->getUrl())
|
||||
->visit('/books')
|
||||
->seeInNthElement('#popular .book', 0, $books[0]->name)
|
||||
->seeInNthElement('#popular .book', 1, $books[1]->name);
|
||||
}
|
||||
}
|
@ -48,4 +48,31 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
$settings->put($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a given string is seen inside an element.
|
||||
*
|
||||
* @param bool|string|null $element
|
||||
* @param integer $position
|
||||
* @param string $text
|
||||
* @param bool $negate
|
||||
* @return $this
|
||||
*/
|
||||
protected function seeInNthElement($element, $position, $text, $negate = false)
|
||||
{
|
||||
$method = $negate ? 'assertNotRegExp' : 'assertRegExp';
|
||||
|
||||
$rawPattern = preg_quote($text, '/');
|
||||
|
||||
$escapedPattern = preg_quote(e($text), '/');
|
||||
|
||||
$content = $this->crawler->filter($element)->eq($position)->html();
|
||||
|
||||
$pattern = $rawPattern == $escapedPattern
|
||||
? $rawPattern : "({$rawPattern}|{$escapedPattern})";
|
||||
|
||||
$this->$method("/$pattern/i", $content);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user