Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

improve some tests and keep it working: #66

Closed
wants to merge 2 commits into from

2 participants

@Forestsoft-de

Test/EnvironmentTest.php

  • getInstance will not throw an exception if all tests are running.
  • make set instance null possible and check for type magento_environtment.

  • implement skipped Varien_Date tests.
    is it correct that %s property will be ignored? the test failed yet.

Implementation of ImageMagickTest will not work under windows because touch is an unix command.
check for environtment and skip these tests.

you should think about using of vfsStream for file system tests.

Forestsoft-de added some commits
@Forestsoft-de Forestsoft-de improve some tests and keep it working:
Test/EnvironmentTest.php
getInstance will not throw an exception if all tests are running.
make set instance null possible and check for type magento_environtment.

implement skipped Varien_Date tests.
is it correct that %s property will be ignored? the test failed yet.

Implementation of ImageMagickTest will not work under windows because touch is an unix command.
check for environtment and skip these tests.

you should think about using of vfsStream for file system tests.
c78704b
@Forestsoft-de Forestsoft-de Merge branch 'master' of git://github.com/magento/magento2 752a4cf
@mage2-team
Collaborator

@Forestsoft-de
Sebastian, thank you for valuable contribution. Let's dissect it and see what was done in result:

  • dev/tests/unit/framework/Magento/Test/Environment.php and related tests. After careful inspection we decided to remove it at all. After this change the unit testing framework happens to not have any other classes, so we removed the framework as well. With this change the unit tests in Magento become implemented using "out of the box" features of PHPUnit.
  • dev/tests/unit/testsuite/Varien/DateTest.php
    • Didn't accept contribution for convertZendToStrfTime(), because this method was eliminated during refactoring of calendar to jQuery. The change is stuck in one of development branches though, but we'll incorporate it into master branch in near future.
    • Accepted testFormatDate() as is -- thank you
  • dev/tests/unit/testsuite/Varien/Image/Adapter/ImageMagickTest.php -- partially accepted your contribution and also refactored the test to not create any files in the first place.
@mage2-team mage2-team closed this
@mage2-team mage2-team referenced this pull request from a commit
@mage2-team mage2-team 2.0.0.0-dev30
* Framework changes
  * Added dependency injection of framework capability
    * Adopted Zend\Di component of Zend Framework 2 library
    * Implemented object manager in Magento application
    * Refactored multiple base classes to dependency injection principle (dependencies are declared in constructor)
  * Themes/View
    * Implemented storing themes registry in database, basic CRUD of themes, automatic registration of themes in database from file system out of the box
    * Renamed `Mage_Core_Model_Layout_Update` into `Mage_Core_Model_Layout_Merge`, the former becomes an entity domain model. Similar changes with `Mage_Core_Model_Resource_Layout` -> `Mage_Core_Model_Resource_Layout_Update`, `Mage_Core_Model_Layout_Data` -> `Mage_Core_Model_Layout_Update`
* Performance tests
  * Improved indexers running script `dev/shell/indexer.php` to return appropriate exit code upon success/failure
  * Implemented running the same performance scenario file with different parameters
  * Slightly refactored framework class `Magento_Performance_Testsuite_Optimizer` for better visibility of algorithm
* Visual design editor
  * Added ability to remove elements in editor UI
  * Revised history of changes VDE toolbar and algorithm of "compacting" operations (moving, removing elements) as a layout update XML
  * Added selection of themes to VDE launcher page
* Refactored JavaScript of some UI elements to jQuery:
  * "Simple" and "configurable" product view pages
  * "Create Account" page
  * "Shopping Cart" page
  * CAPTCHA
  * Newsletter subscription
* Tax management UX improvements
  * Split Basic and Advanced Settings for Tax Rule Management UI
  * Moved the Import/Export functionality to Tax Rate page
  * Moved Tax menu to System from Sales
* Implemented the editable multiselect JavaScript component
* Added mentioning sitemap in `robots.txt` after generation
* Removed creation of DB backup in integration testing framework
* Fixed logic of order of loading ACL resources in backend
* Fixed JavaScript error during installation when one of files in `pub/media` is not writable
* Fixed structure of legacy test fixtures that allowed ambiguous keys in declaration
* Fixed inability to restore admin password when CAPTCHA is enabled
* Various minor UX fixes (labels, buttons, redirects, etc...)
* GitHub requests:
  * [#59](#59) -- implemented handling of unexpected situations in admin/dashboard/tunnel action
  * [#66](#66)
    * refactored ImageMagick adapter unit test to avoid system operation
    * simplified unit testing framework -- removed unused classes, simplified handling logic of directory `dev/tests/unit/tmp` and removed it from VCS
  * [#73](#73), [#74](#74) -- fixes in docblock tags
  * [#75](#75), [#96](#96) -- fixed translation module contexts in a few places
  * [#80](#80) -- fixed some runtime errors in import/export module
  * [#81](#81) -- removed usage of "remove" directive in places where it is overridden by setting root template anyway
  * [#87](#87) -- changed paths of files to include from relative into absolute in `dev/shell/indexer.php` and `log.php`
  * [#88](#88) -- provided comments for values that can be configured in `app/etc/local.xml` file
  * [#90](#90) -- slightly optimized logic of implementation of loading configurable product attributes
0f2900a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 17, 2012
  1. @Forestsoft-de

    improve some tests and keep it working:

    Forestsoft-de authored
    Test/EnvironmentTest.php
    getInstance will not throw an exception if all tests are running.
    make set instance null possible and check for type magento_environtment.
    
    implement skipped Varien_Date tests.
    is it correct that %s property will be ignored? the test failed yet.
    
    Implementation of ImageMagickTest will not work under windows because touch is an unix command.
    check for environtment and skip these tests.
    
    you should think about using of vfsStream for file system tests.
Commits on Sep 6, 2012
  1. @Forestsoft-de
This page is out of date. Refresh to see the latest.
View
6 dev/tests/unit/framework/Magento/Test/Environment.php
@@ -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;
}
View
30 dev/tests/unit/framework/tests/unit/testsuite/Magento/Test/EnvironmentTest.php
@@ -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()
@@ -104,4 +120,12 @@ public function testCleanDir()
throw $e;
}
}
+
+ /**
+ *
+ */
+ public function tearDown()
+ {
+ Magento_Test_Environment::setInstance($this->_environment);
+ }
}
View
75 dev/tests/unit/testsuite/Varien/DateTest.php
@@ -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"
+ ),
);
}
@@ -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")
+ ),
);
}
}
View
15 dev/tests/unit/testsuite/Varien/Image/Adapter/ImageMagickTest.php
@@ -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();
@@ -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());
}
}
@@ -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),
);
}
}
Something went wrong with that request. Please try again.