Skip to content

Commit

Permalink
moar
Browse files Browse the repository at this point in the history
  • Loading branch information
cmb69 committed Mar 22, 2023
1 parent 966393b commit 4622b3b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 57 deletions.
83 changes: 26 additions & 57 deletions tests/VisualCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,72 +78,50 @@ public function testCreateErrorImage()
{
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', self::CONFIG);
$actual = $sut->createErrorImage('Cookies must be enabled!');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('error_image', $actual);
}

public function testNoiseAbove()
{
$config = array_merge(self::CONFIG, ['noise_above' => 'true']);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('noise_above', $actual);
}

public function testCryptGrayScale()
{
$config = array_merge(self::CONFIG, ['crypt_gray_scale' => 'true']);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('gray_scale', $actual);
}

public function testCryptGaussianBlur()
{
$config = array_merge(self::CONFIG, ['crypt_gaussian_blur' => 'true']);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('gaussian_blur', $actual);
}

public function testBgImagePng()
/** @dataProvider bgImages */
public function testBgImage(string $type)
{
$config = array_merge(self::CONFIG, ['bg_image' => "bg.png"]);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$this->createYellowBackgroundImage("png");
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('bg_image', $actual);
}

public function testBgImageGif()
public function bgImages(): array
{
$config = array_merge(self::CONFIG, ['bg_image' => "bg.gif"]);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$this->createYellowBackgroundImage("gif");
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
}

public function testBgImageJpeg()
{
$config = array_merge(self::CONFIG, ['bg_image' => "bg.jpeg"]);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$this->createYellowBackgroundImage("jpeg");
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
return [
['png'],
['gif'],
['jpeg']
];
}

public function testBgImages()
Expand All @@ -153,9 +131,7 @@ public function testBgImages()
$this->createYellowBackgroundImage('png');
$this->createYellowBackgroundImage('gif');
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('bg_images', $actual);
}

/**
Expand All @@ -169,25 +145,21 @@ private function createYellowBackgroundImage($type)
$writeImage($backgroundImage, vfsStream::url("test/images/bg.$type"));
}

public function testNoiseColor1()
/** @dataProvider noiseColors */
public function testNoiseColor(string $kind, string $expected)
{
$this->markTestSkipped("underlying bug needs to be fixed");
$config = array_merge(self::CONFIG, ['noise_color' => "1"]);
$config = array_merge(self::CONFIG, ['noise_color' => $kind]);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals($expected, $actual);
}

public function testNoiseColor2()
public function noiseColors(): array
{
$config = array_merge(self::CONFIG, ['noise_color' => "2"]);
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', $config);
$actual = $sut->createImage('ABCD');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
return [
// ['1', 'noise_color_1'], // fix underlying bug
['2', 'noise_color_2']
];
}

/**
Expand All @@ -197,9 +169,7 @@ public function testWordwrapInErrorImage()
{
$sut = new FakeVisualCaptcha(vfsStream::url('test/images/'), '../cryptographp/fonts', self::CONFIG);
$actual = $sut->createErrorImage('Перезагрузка слишком быстро!');
ob_start();
imagegif($actual);
Approvals::verifyStringWithFileExtension(ob_get_clean(), "gif");
$this->assertImageEquals('word_wrap_in_error', $actual);
}

/**
Expand All @@ -218,9 +188,8 @@ private function assertImageEquals($expected, $actual)
$w2 = imagesx($im2);
$h2 = imagesy($im2);

if ($w1 !== $w2 || $h1 !== $h2) {
$this->assertTrue(false);
}
$this->assertEquals($w1, $w2);
$this->assertEquals($h1, $h2);

$im3 = imagecreatetruecolor($w1, $h1);
imagealphablending($im3, false);
Expand Down
Binary file modified tests/images/bg_image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/bg_images.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/gaussian_blur.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/gray_scale.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/noise_above.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/images/noise_color_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4622b3b

Please sign in to comment.