Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(NFC) dev/core#2029 - Make assertions in PrevNextTest more skimmable #18822

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions tests/phpunit/E2E/Core/PrevNextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ public function testFillArray() {
$this->assertEquals(4, $this->prevNext->getCount($this->cacheKey));
$this->assertEquals(0, $this->prevNext->getCount('not-a-key-' . $this->cacheKey));

$all = $this->prevNext->getSelection($this->cacheKey, 'getall')[$this->cacheKey];
$this->assertEquals([100, 400, 200, 300], array_keys($all));
$all = $this->assertSelections([100, 400, 200, 300], 'getall', $this->cacheKey);
$this->assertEquals([1], array_unique(array_values($all)));

$this->assertSelections([]);
$this->assertSelections([], 'get', $this->cacheKey);
}

public function testFetch() {
Expand Down Expand Up @@ -250,20 +249,15 @@ public function testDeleteByCacheKey() {
// Add some data that we're actually working with.
$this->testFillArray();

$all = $this->prevNext->getSelection($this->cacheKey, 'getall')[$this->cacheKey];
$this->assertEquals([100, 400, 200, 300], array_keys($all), 'selected cache not correct for ' . $this->cacheKey
. ' defined keys are ' . $this->cacheKey . 'and ' . $this->cacheKeyB
. ' the prevNext cache is ' . print_r($this->prevNext, TRUE)
);
$all = $this->assertSelections([100, 400, 200, 300], 'getall', $this->cacheKey);

list ($id1, $id2, $id3) = array_keys($all);
$this->prevNext->markSelection($this->cacheKey, 'select', [$id1, $id3]);
$this->assertSelections([$id1, $id3]);
$this->assertSelections([$id1, $id3], 'get', $this->cacheKey);

$this->prevNext->deleteItem(NULL, $this->cacheKey);
$all = $this->prevNext->getSelection($this->cacheKey, 'getall')[$this->cacheKey];
$this->assertEquals([], array_keys($all));
$this->assertSelections([]);
$this->assertSelections([], 'getall', $this->cacheKey);
$this->assertSelections([], 'get', $this->cacheKey);

// Ensure background data was untouched.
$this->assertSelections([100], 'get', $this->cacheKeyB);
Expand Down Expand Up @@ -329,6 +323,8 @@ public function testDeleteAll() {
* Contact IDs that should be selected.
* @param string $action
* @param string|NULL $cacheKey
* @return array
* Contact IDs that were returned by getSelection($cacheKey, $action)
*/
protected function assertSelections($ids, $action = 'get', $cacheKey = NULL) {
if ($cacheKey === NULL) {
Expand All @@ -342,6 +338,7 @@ protected function assertSelections($ids, $action = 'get', $cacheKey = NULL) {
);

$this->assertCount(count($ids), $selected);
return $selected;
}

}