Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testSetBackgroundColor()
- {
- // Get the test image
- $image = $this->getTestImage();
- // Validate default background color
- $this->assertEquals(NULL, $image->getBackgroundColor());
- // Test invalid background colors
- $invalidBackgroundColors = array(
- NULL,
- true,
- false,
- array(),
- '',
- 'red',
- 'green',
- '255,255,255',
- 12
- );
- foreach($invalidBackgroundColors as $invalidBackgroundColor)
- {
- try
- {
- $image->setBackgroundColor($invalidBackgroundColor);
- }
- catch(SM_Image_Exception $e) { continue; }
- $this->fail('An invalid background color did not throw an expected SM_Image_Exception.');
- }
- // Set the background color (SM_Image_Exception would be thrown if error)
- $image->setBackgroundColor(array(100,150,200));
- // Validate the background color was set
- $backgroundColor = $image->getBackgroundColor();
- $this->assertType('array', $backgroundColor);
- $this->assertArrayHasKey('red', $backgroundColor);
- $this->assertArrayHasKey('green', $backgroundColor);
- $this->assertArrayHasKey('blue', $backgroundColor);
- $this->assertEquals(100, $backgroundColor['red']);
- $this->assertEquals(150, $backgroundColor['green']);
- $this->assertEquals(200, $backgroundColor['blue']);
- // Try and set the background color again, fail as you shouldn't be able to
- try
- {
- $image->setBackgroundColor(array(150,50,120));
- }
- catch (SM_Image_Exception $e2) {}
- if (isset($e2))
- {
- $this->fail('Trying to set the background color again did not throw an expected SM_Image_Exception (1).');
- }
- // Clean-up
- unset($image);
- // Get the test image
- $image = $this->getTestImage(IMAGETYPE_PNG);
- // Set the background color to transparent
- $image->setBackgroundColor(IMG_COLOR_TRANSPARENT);
- // Validate the background color was set
- $this->assertEquals(IMG_COLOR_TRANSPARENT, $image->getBackgroundColor());
- // Try and set the background color again, fail as you shouldn't be able to
- try
- {
- $image->setBackgroundColor(IMG_COLOR_TRANSPARENT);
- }
- catch (SM_Image_Exception $e3) {}
- if (isset($e3))
- {
- $this->fail('Trying to set the background color again did not throw an expected SM_Image_Exception (2).');
- }
- // Clean-up
- unset($image);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement