Skip to content

Commit

Permalink
Revert assertion changes in AnnotationSessionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
lehecht committed Nov 13, 2024
1 parent 6199857 commit c862628
Showing 1 changed file with 34 additions and 43 deletions.
77 changes: 34 additions & 43 deletions tests/php/AnnotationSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testGetVolumeFileAnnotationsHideOwnImage()
$al12 = ImageAnnotationLabelTest::create([
'annotation_id' => $a1->id,
'user_id' => $otherUser->id,
'created_at' => '2022-09-05',
'created_at' => '2016-09-05',
]);

// this should be shown completely
Expand All @@ -116,14 +116,14 @@ public function testGetVolumeFileAnnotationsHideOwnImage()

$yieldAnnotations = $session->getVolumeFileAnnotations($image, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertFalse($this->isPresent($al11, $labels));
$this->assertTrue($this->isPresent($al12, $labels));
$this->assertTrue($annotations->contains('points', [20, 30, 40]));
$this->assertFalse($annotations->contains('labels', [$al11->toArray()]));
$this->assertTrue($annotations->contains('labels', [$al12->toArray()]));

$this->assertTrue($annotations->contains('points', [30, 40, 50]));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideOwnVideo()
Expand Down Expand Up @@ -171,14 +171,14 @@ public function testGetVolumeFileAnnotationsHideOwnVideo()

$yieldAnnotations = $session->getVolumeFileAnnotations($video, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');

$this->assertFalse($this->isPresent($al11, $labels));
$this->assertTrue($this->isPresent($al12, $labels));
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [[20, 30, 40]]));
$this->assertFalse($annotations->contains('labels', [$al11->toArray()]));
$this->assertTrue($annotations->contains('labels', [$al12->toArray()]));

$this->assertTrue($annotations->contains('points', [[30, 40, 50]]));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideOtherImage()
Expand Down Expand Up @@ -214,12 +214,11 @@ public function testGetVolumeFileAnnotationsHideOtherImage()

$yieldAnnotations = $session->getVolumeFileAnnotations($image, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [20, 30, 40]));
$this->assertFalse($this->isPresent($al1, $labels));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertFalse($annotations->contains('labels', [$al1->toArray()]));
$this->assertTrue($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideOtherVideo()
Expand Down Expand Up @@ -255,12 +254,11 @@ public function testGetVolumeFileAnnotationsHideOtherVideo()

$yieldAnnotations = $session->getVolumeFileAnnotations($video, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [[20, 30, 40]]));
$this->assertFalse($this->isPresent($al1, $labels));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertFalse($annotations->contains('labels', [$al1->toArray()]));
$this->assertTrue($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideBothImage()
Expand Down Expand Up @@ -296,12 +294,11 @@ public function testGetVolumeFileAnnotationsHideBothImage()

$yieldAnnotations = $session->getVolumeFileAnnotations($image, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [40, 50, 60]));
$this->assertTrue($this->isPresent($al1, $labels));
$this->assertFalse($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [$al1->toArray()]));
$this->assertFalse($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideBothVideo()
Expand Down Expand Up @@ -337,12 +334,11 @@ public function testGetVolumeFileAnnotationsHideBothVideo()

$yieldAnnotations = $session->getVolumeFileAnnotations($video, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [[40, 50, 60]]));
$this->assertTrue($this->isPresent($al1, $labels));
$this->assertFalse($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [$al1->toArray()]));
$this->assertFalse($annotations->contains('labels', [$al2->toArray()]));
}

public function testGetVolumeFileAnnotationsHideNothingImage()
Expand Down Expand Up @@ -377,12 +373,13 @@ public function testGetVolumeFileAnnotationsHideNothingImage()

$yieldAnnotations = $session->getVolumeFileAnnotations($image, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [40, 50, 60]));
$this->assertTrue($this->isPresent($al1, $labels));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [
$al1->toArray(),
$al2->toArray(),
]));
}

public function testGetVolumeFileAnnotationsHideNothingVideo()
Expand Down Expand Up @@ -417,12 +414,13 @@ public function testGetVolumeFileAnnotationsHideNothingVideo()

$yieldAnnotations = $session->getVolumeFileAnnotations($video, $ownUser);
// expand the models in the collection so we can make assertions
$annotations = collect($yieldAnnotations());
$labels = $annotations->pluck('labels');
$annotations = collect(collect($yieldAnnotations())->toArray());

$this->assertTrue($annotations->contains('points', [[40, 50, 60]]));
$this->assertTrue($this->isPresent($al1, $labels));
$this->assertTrue($this->isPresent($al2, $labels));
$this->assertTrue($annotations->contains('labels', [
$al1->toArray(),
$al2->toArray(),
]));
}

public function testAllowsAccessImageAnnotation()
Expand Down Expand Up @@ -734,11 +732,4 @@ public function testAnnotationsVideo()
$this->assertFalse($session->annotations()->where('id', $a3->id)->exists());
$this->assertFalse($session->annotations()->where('id', $a4->id)->exists());
}

private function isPresent($needle, $haystack)
{
$needle = collect($needle)->sortKeys();
$haystack = $haystack->flatten()->map(fn ($l) => collect($l)->sortKeys());
return $haystack->contains($needle);
}
}

0 comments on commit c862628

Please sign in to comment.