From b1199c8cdda4535739557b6a536e08a2c8772f30 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 9 Aug 2025 04:15:44 +0000 Subject: [PATCH] Improve QR code image testing with pixel-level comparison Co-authored-by: jakeb994 --- tests/e2e/Services/Avatars/AvatarsBase.php | 8 +++---- tests/extensions/ImageAssertions.php | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/extensions/ImageAssertions.php diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index ac2f0cba34..09a30f39d5 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -347,7 +347,7 @@ trait AvatarsBase $this->assertEquals(400, $image->getImageWidth()); $this->assertEquals(400, $image->getImageHeight()); $this->assertEquals('PNG', $image->getImageFormat()); - $this->assertEquals(9086, strlen($response['body'])); + \Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-default.png', $response['body']); $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], @@ -365,7 +365,7 @@ trait AvatarsBase $this->assertEquals(200, $image->getImageWidth()); $this->assertEquals(200, $image->getImageHeight()); $this->assertEquals('PNG', $image->getImageFormat()); - $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200.png')), strlen($response['body'])); + \Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200.png', $response['body']); $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], @@ -384,7 +384,7 @@ trait AvatarsBase $this->assertEquals(200, $image->getImageWidth()); $this->assertEquals(200, $image->getImageHeight()); $this->assertEquals('PNG', $image->getImageFormat()); - $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body'])); + \Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png', $response['body']); $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], @@ -400,7 +400,7 @@ trait AvatarsBase $this->assertEquals(200, $image->getImageWidth()); $this->assertEquals(200, $image->getImageHeight()); $this->assertEquals('PNG', $image->getImageFormat()); - $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body'])); + \Appwrite\Tests\ImageAssertions::assertSamePixels(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png', $response['body']); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']); diff --git a/tests/extensions/ImageAssertions.php b/tests/extensions/ImageAssertions.php new file mode 100644 index 0000000000..7efdfb99ca --- /dev/null +++ b/tests/extensions/ImageAssertions.php @@ -0,0 +1,25 @@ +readImageBlob($actualImageBlob); + + foreach ([$expected, $actual] as $image) { + // Normalize to PNG and strip metadata to avoid nondeterministic chunks + $image->setImageFormat('PNG'); + $image->stripImage(); + // Exclude time and profile chunks that vary between builds + $image->setOption('png:exclude-chunks', 'date,time,iCCP,sRGB,gAMA,cHRM'); + } + + Assert::assertSame($expected->getImageSignature(), $actual->getImageSignature()); + } +} \ No newline at end of file