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

improve some tests and keep it working: #66

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion dev/tests/unit/framework/Magento/Test/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ class Magento_Test_Environment
*
* @param Magento_Test_Environment $instance
*/
public static function setInstance(Magento_Test_Environment $instance)
public static function setInstance($instance)
{
if(!is_null($instance) && !($instance instanceof Magento_Test_Environment)) {
throw new Magento_Exception("Instance Parameter must be an Instance of Magento_Test_Environtment");
}

self::$_instance = $instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,37 @@ protected function setUp()
$this->_environment = new Magento_Test_Environment(self::$_tmpDir);
}

public function testSetGetInstance()
{
Magento_Test_Environment::setInstance($this->_environment);
$this->assertSame($this->_environment, Magento_Test_Environment::getInstance());
}

/**
* @expectedException Magento_Exception
*/
public function testGetInstance()
{
Magento_Test_Environment::setInstance(null);
Magento_Test_Environment::getInstance();
}

/**
* @depends testGetInstance
* @expectedException Magento_Exception
*/
public function testSetGetInstance()
public function testSetInstanceWithNull()
{
Magento_Test_Environment::setInstance($this->_environment);
$this->assertSame($this->_environment, Magento_Test_Environment::getInstance());
Magento_Test_Environment::setInstance(null);
$instance = Magento_Test_Environment::getInstance();
}

/**
* @expectedException Magento_Exception
*/
public function testSetInstanceThrowExceptionIfParamNotValid()
{
Magento_Test_Environment::setInstance(new stdClass());
}

public function testGetTmpDir()
Expand Down Expand Up @@ -104,4 +120,12 @@ public function testCleanDir()
throw $e;
}
}

/**
*
*/
public function tearDown()
{
Magento_Test_Environment::setInstance($this->_environment);
}
}
75 changes: 67 additions & 8 deletions dev/tests/unit/testsuite/Varien/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,41 @@ class Varien_DateTest extends PHPUnit_Framework_TestCase
/**
* @covers Varien_Date::convertZendToStrftime
* @todo Implement testConvertZendToStrftime().
* @dataProvider dp_convertZendToStrfTime
*/
public function testConvertZendToStrftime()
public function testConvertZendToStrftime($zendDateFormat, $expectedOutput)
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
$actual = Varien_Date::convertZendToStrftime($zendDateFormat);
$this->assertEquals($expectedOutput, $actual);
}

public function dp_convertZendToStrfTime()
{
return array(
'Year' => array(
Zend_Date::YEAR,
"%Y"
),
'Month' => array(
Zend_Date::MONTH,
"%m"
),
'Month Name' => array(
Zend_Date::MONTH_NAME,
"%B"
),
'Hour' => array(
Zend_Date::HOUR,
"%H"
),
'Combined Date and Time' => array(
"yyyy-MM-ddTHH:mm:ssZZZZ",
"%c"
),
'German Date and Time' => array(
Zend_Date::DAY . "." . Zend_Date::MONTH . "." . Zend_Date::YEAR . " " . Zend_Date::HOUR . ":" . Zend_Date::MINUTE,
"%d.%m.%Y %H:%M"
),
);
}

Expand Down Expand Up @@ -68,12 +97,42 @@ public function testNow()
/**
* @covers Varien_Date::formatDate
* @todo Implement testFormatDate().
* @dataProvider dp_formatDate
*/
public function testFormatDate()
public function testFormatDate($date, $includeTime, $expectedResult)
{
$actual = Varien_Date::formatDate($date, $includeTime);
$this->assertEquals($expectedResult, $actual);
}

public function dp_formatDate()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
return array(
'null' => array(
null,
false,
""
),
'Bool true' => array(
true,
false,
date("Y-m-d")
),
'Bool false' => array(
false,
false,
""
),
'Zend Date' => array(
new Zend_Date(),
false,
date("Y-m-d")
),
'Zend Date including Time' => array(
new Zend_Date(),
true,
date("Y-m-d H:i:s")
),
);
}
}
15 changes: 11 additions & 4 deletions dev/tests/unit/testsuite/Varien/Image/Adapter/ImageMagickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class Varien_Image_Adapter_ImageMagickTest extends PHPUnit_Framework_TestCase
*/
protected $_object;

public function setUp()
{
if (DIRECTORY_SEPARATOR == "\\") {
$this->markTestSkipped("Used touch function in watermarkDataProvider will not work on windows systems");
}
}

public function tearDown()
{
Magento_Test_Environment::getInstance()->cleanTmpDirOnShutdown();
Expand All @@ -50,7 +57,7 @@ public function testWatermark($imagePath, $expectedResult)
$this->_object->watermark($imagePath);
$this->fail('An expected exception has not been raised.');
} catch (Exception $e) {
$this->assertContains($e->getMessage(), $expectedResult);
$this->assertContains($expectedResult, $e->getMessage());
}
}

Expand All @@ -62,9 +69,9 @@ public function watermarkDataProvider()
touch($imageExists);

return array(
array('', Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT),
array($imageAbsent, Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT),
array($imageExists, Varien_Image_Adapter_ImageMagick::ERROR_WRONG_IMAGE),
'Empty Image Path' => array('', Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT),
'Image Absent' => array($imageAbsent, Varien_Image_Adapter_ImageMagick::ERROR_WATERMARK_IMAGE_ABSENT),
'Image already Exist should result in Wrong Image Exception' => array($imageExists, Varien_Image_Adapter_ImageMagick::ERROR_WRONG_IMAGE),
);
}
}
Expand Down