Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EcomDev_PHPUnit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Open
EcomDev_PHPUnit
Commits
68f9fe81
Commit
68f9fe81
authored
May 05, 2011
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ New assertion for configuration tests.
parent
00008320
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1078 additions
and
5 deletions
+1078
-5
app/code/community/EcomDev/PHPUnit/Model/App.php
app/code/community/EcomDev/PHPUnit/Model/App.php
+3
-0
app/code/community/EcomDev/PHPUnit/Model/Config.php
app/code/community/EcomDev/PHPUnit/Model/Config.php
+20
-0
app/code/community/EcomDev/PHPUnit/Model/Design/Package.php
app/code/community/EcomDev/PHPUnit/Model/Design/Package.php
+73
-0
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
+335
-0
lib/EcomDev/PHPUnit/Constraint/Config.php
lib/EcomDev/PHPUnit/Constraint/Config.php
+16
-0
lib/EcomDev/PHPUnit/Constraint/Config/Abstract.php
lib/EcomDev/PHPUnit/Constraint/Config/Abstract.php
+23
-1
lib/EcomDev/PHPUnit/Constraint/Config/ClassAlias.php
lib/EcomDev/PHPUnit/Constraint/Config/ClassAlias.php
+140
-0
lib/EcomDev/PHPUnit/Constraint/Config/EventObserver.php
lib/EcomDev/PHPUnit/Constraint/Config/EventObserver.php
+178
-0
lib/EcomDev/PHPUnit/Constraint/Config/Interface.php
lib/EcomDev/PHPUnit/Constraint/Config/Interface.php
+16
-0
lib/EcomDev/PHPUnit/Constraint/Config/Layout.php
lib/EcomDev/PHPUnit/Constraint/Config/Layout.php
+192
-0
lib/EcomDev/PHPUnit/Constraint/Config/Layout/Design/Package/Interface.php
...nit/Constraint/Config/Layout/Design/Package/Interface.php
+37
-0
lib/EcomDev/PHPUnit/Constraint/Config/Module.php
lib/EcomDev/PHPUnit/Constraint/Config/Module.php
+24
-3
lib/EcomDev/PHPUnit/Constraint/Config/Node.php
lib/EcomDev/PHPUnit/Constraint/Config/Node.php
+21
-1
No files found.
app/code/community/EcomDev/PHPUnit/Model/App.php
View file @
68f9fe81
...
...
@@ -32,6 +32,9 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
// Admin store code
const
ADMIN_STORE_CODE
=
'admin'
;
const
AREA_ADMINHTML
=
'adminhtml'
;
const
AREA_FRONTEND
=
'frontend'
;
const
REGISTRY_PATH_LAYOUT_SINGLETON
=
'_singleton/core/layout'
;
const
XML_PATH_LAYOUT_MODEL_FOR_TEST
=
'phpunit/suite/layout/model'
;
...
...
app/code/community/EcomDev/PHPUnit/Model/Config.php
View file @
68f9fe81
...
...
@@ -110,6 +110,26 @@ class EcomDev_PHPUnit_Model_Config extends Mage_Core_Model_Config
return
$this
->
_replaceInstanceCreation
[
'resource_model'
][
$modelClass
];
}
/**
* Retrieves real resource model class alias
*
* @param string $classAlias
* @return string
*/
public
function
getRealResourceModelClassAlias
(
$classAlias
)
{
list
(
$classAliasPrefix
,)
=
explode
(
'/'
,
$classAlias
,
2
);
if
(
isset
(
$this
->
_xml
->
global
->
models
->
$classAliasPrefix
->
resourceModel
))
{
$realClassAliasPrefix
=
$this
->
_xml
->
global
->
models
->
$classAliasPrefix
->
resourceModel
;
$classAlias
=
$realClassAliasPrefix
.
substr
(
$classAlias
,
strlen
(
$classAliasPrefix
)
);
}
return
$classAlias
;
}
/**
* Loads scope snapshot
*
...
...
app/code/community/EcomDev/PHPUnit/Model/Design/Package.php
0 → 100644
View file @
68f9fe81
<?php
class
EcomDev_PHPUnit_Model_Design_Package
extends
Mage_Core_Model_Design_Package
implements
EcomDev_PHPUnit_Constraint_Config_Layout_Design_Package_Interface
{
/**
* Asserts layout file existance in design packages,
* and returns actual and expected filenames as result
*
* @param string $fileName
* @param string $area
* @param string|null $designPackage if not specified any theme will be used
* @param string|null $theme if not specified any theme will be used
* @return array of 'expected' and 'actual' file names
*/
public
function
getLayoutFileAssertion
(
$fileName
,
$area
,
$designPackage
=
null
,
$theme
=
null
)
{
$this
->
reset
();
$this
->
setArea
(
$area
);
if
(
$area
==
EcomDev_PHPUnit_Model_App
::
AREA_ADMINHTML
)
{
$this
->
setStore
(
EcomDev_PHPUnit_Model_App
::
ADMIN_STORE_CODE
);
}
else
{
$this
->
setStore
(
Mage
::
app
()
->
getAnyStoreView
()
->
getCode
());
}
$this
->
setPackageName
(
$designPackage
);
$this
->
setTheme
(
$theme
);
$actualFileName
=
$this
->
getLayoutFilename
(
$fileName
,
$params
);
if
(
$theme
!==
null
||
$designPackage
!==
null
)
{
$expectedTheme
=
$this
->
getTheme
(
'layout'
);
$expectedDesignPackage
=
$this
->
getPackageName
();
$params
=
array
(
'_type'
=>
'layout'
,
'_theme'
=>
$expectedTheme
,
'_package'
=>
$expectedDesignPackage
);
$expectedFileName
=
Mage
::
getBaseDir
(
'design'
)
.
DS
.
$this
->
_renderFilename
(
$fileName
,
$params
);
}
else
{
$expectedFileName
=
$actualFileName
;
if
(
!
file_exists
(
$actualFileName
))
{
$actualFileName
=
false
;
}
}
return
array
(
'actual'
=>
$actualFileName
,
'expected'
=>
$expectedFileName
);
}
/**
* Resets design data
*
* @return EcomDev_PHPUnit_Model_Design_Package
*/
public
function
reset
()
{
$this
->
_store
=
null
;
$this
->
_area
=
null
;
$this
->
_name
=
null
;
$this
->
_theme
=
null
;
$this
->
_config
=
null
;
$this
->
_rootDir
=
null
;
$this
->
_callbackFileDir
=
null
;
return
$this
;
}
}
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
View file @
68f9fe81
...
...
@@ -62,6 +62,60 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
);
}
/**
* A new constraint for checking module node
*
* @param string $moduleName
* @param string $type
* @param string|null $expectedValue
*/
public
static
function
configClassAlias
(
$group
,
$classAlias
,
$expectedClassName
,
$type
=
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
TYPE_CLASS_ALIAS
)
{
return
self
::
config
(
new
EcomDev_PHPUnit_Constraint_Config_ClassAlias
(
$group
,
$classAlias
,
$expectedClassName
,
$type
)
);
}
/**
* Creates layout constraint
*
* @param string $area
* @param string $expectedFile
* @param string $type
* @param string|null $layoutUpdate
* @param string|null $theme
* @param string|null $designPackage
*/
public
static
function
configLayout
(
$area
,
$expectedFile
,
$type
,
$layoutUpdate
=
null
,
$theme
=
null
,
$designPackage
=
null
)
{
if
(
!
EcomDev_PHPUnit_Constraint_Config_Layout
::
getDesignPackageModel
())
{
EcomDev_PHPUnit_Constraint_Config_Layout
::
setDesignPackageModel
(
Mage
::
getModel
(
'ecomdev_phpunit/design_package'
));
}
return
self
::
config
(
new
EcomDev_PHPUnit_Constraint_Config_Layout
(
$area
,
$expectedFile
,
$type
,
$layoutUpdate
,
$theme
,
$designPackage
)
);
}
/**
* Constraint for testing observer
* event definitions in configuration
*
* @param string $area
* @param string $eventName
* @param string $observerClassAlias
* @param string $observerMethod
* @param string|null $observerName
*/
public
static
function
configEventObserver
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
$type
=
EcomDev_PHPUnit_Constraint_Config_EventObserver
::
TYPE_DEFINDED
,
$observerName
=
null
)
{
return
self
::
config
(
new
EcomDev_PHPUnit_Constraint_Config_EventObserver
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
$type
,
$observerName
)
);
}
/**
* Executes configuration constraint
*
...
...
@@ -578,4 +632,285 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
$message
);
}
/**
* Assert that grouped class alias is mapped to expected class name
*
* @param string $group
* @param string $classAlias
* @param string $expectedClassName
*/
public
static
function
assertGroupedClassAlias
(
$group
,
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
configClassAlias
(
$group
,
$classAlias
,
$expectedClassName
),
$message
);
}
/**
* Assert that grouped class alias is not mapped to expected class name
*
* @param string $group
* @param string $classAlias
* @param string $expectedClassName
*/
public
static
function
assertGroupedClassAliasNot
(
$group
,
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
logicalNot
(
self
::
configClassAlias
(
$group
,
$classAlias
,
$expectedClassName
)
),
$message
);
}
/**
* Assert that block alias is mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertBlockAlias
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAlias
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_BLOCK
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that block alias is not mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertBlockAliasNot
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAliasNot
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_BLOCK
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that model alias is mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertModelAlias
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAlias
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_MODEL
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that model alias is not mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertModelAliasNot
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAliasNot
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_MODEL
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that resource model alias is mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertResourceModelAlias
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
$classAlias
=
Mage
::
getConfig
()
->
getRealResourceModelClassAlias
(
$classAlias
);
self
::
assertGroupedClassAlias
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_MODEL
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that resource model alias is not mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertResourceModelAliasNot
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
$classAlias
=
Mage
::
getConfig
()
->
getRealResourceModelClassAlias
(
$classAlias
);
self
::
assertGroupedClassAliasNot
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_MODEL
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that helper alias is mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertHelperAlias
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAlias
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_HELPER
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that helper alias is not mapped to expected class name
*
* @param string $classAlias
* @param string $expectedClassName
* @param string $message
*/
public
static
function
assertHelperAliasNot
(
$classAlias
,
$expectedClassName
,
$message
=
''
)
{
self
::
assertGroupedClassAliasNot
(
EcomDev_PHPUnit_Constraint_Config_ClassAlias
::
GROUP_HELPER
,
$classAlias
,
$expectedClassName
);
}
/**
* Assert that configuration has definition of the layout file.
* If layout update name is specified, then it will restrict assertion by it.
*
* @param string $area (frontend|adminhtml)
* @param string $expectedFileName
* @param string $layoutUpdate
* @param string $message
*/
public
static
function
assertLayoutFileDefined
(
$area
,
$expectedFileName
,
$layoutUpdate
=
null
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
configLayout
(
$area
,
$expectedFileName
,
EcomDev_PHPUnit_Constraint_Config_Layout
::
TYPE_LAYOUT_DEFINITION
,
$layoutUpdateName
),
$message
);
}
/**
* Asserts that layout file exists in current design package
*
* @param string $area (frontend|adminhtml)
* @param string $expectedFileName
* @param string $message
*/
public
static
function
assertLayoutFileExists
(
$area
,
$expectedFileName
,
$message
=
''
)
{
self
::
assertLayoutFileDefined
(
$area
,
$expectedFileName
,
null
,
$message
);
self
::
assertThatConfig
(
self
::
configLayout
(
$area
,
$expectedFileName
,
EcomDev_PHPUnit_Constraint_Config_Layout
::
TYPE_LAYOUT_FILE
),
$message
);
}
/**
* Asserts that layout file exists in a particular theme and design package
*
* @param string $area (frontend|adminhtml)
* @param string $expectedFileName
* @param string $message
*/
public
static
function
assertLayoutFileExistsInTheme
(
$area
,
$expectedFileName
,
$theme
,
$designPackage
=
null
,
$message
=
''
)
{
self
::
assertLayoutFileDefined
(
$area
,
$expectedFileName
,
null
,
$message
);
self
::
assertThatConfig
(
self
::
configLayout
(
$area
,
$expectedFileName
,
EcomDev_PHPUnit_Constraint_Config_Layout
::
TYPE_LAYOUT_FILE
,
null
,
$theme
,
$designPackage
),
$message
);
}
/**
* Asserts that event observer is defined for an event
* and not disabled. If observer name is defined, it additionaly checks it.
*
* @param string $area
* @param string $eventName
* @param string $observerClassAlias
* @param string $observerMethod
* @param string|null $observerName
* @param string $message
*/
public
static
function
assertEventObserverDefined
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
$observerName
=
null
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
configEventObserver
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
EcomDev_PHPUnit_Constraint_Config_EventObserver
::
TYPE_DEFINDED
,
$observerName
),
$message
);
}
/**
* Asserts that event observer is not defined for an event
* or disabled.
* If observer name is defined, it additionaly checks it.
*
* @param string $area
* @param string $eventName
* @param string $observerClassAlias
* @param string $observerMethod
* @param string|null $observerName
* @param string $message
*/
public
static
function
assertEventObserverNotDefined
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
$observerName
=
null
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
logicalNot
(
self
::
configEventObserver
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
EcomDev_PHPUnit_Constraint_Config_EventObserver
::
TYPE_DEFINDED
,
$observerName
)
),
$message
);
}
}
lib/EcomDev/PHPUnit/Constraint/Config.php
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Constraint for testing the configuration values
...
...
lib/EcomDev/PHPUnit/Constraint/Config/Abstract.php
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Abstract class for constraints based on configuration
...
...
@@ -200,8 +216,14 @@ abstract class EcomDev_PHPUnit_Constraint_Config_Abstract
$description
);
}
else
{
if
(
!
$this
->
_useActualValue
)
{
$actualValue
=
$other
->
asNiceXml
();
}
else
{
$actualValue
=
$this
->
_actualValue
;
}
throw
new
EcomDev_PHPUnit_Constraint_Exception
(
$failureDescription
,
$
other
->
asNiceXml
()
,
$description
$failureDescription
,
$
actualValue
,
$description
);
}
}
...
...
lib/EcomDev/PHPUnit/Constraint/Config/ClassAlias.php
0 → 100644
View file @
68f9fe81
<?php
/**
* Class alias constraint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_ClassAlias
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_CLASS_ALIAS
=
'global/%s/%s'
;
const
GROUP_BLOCK
=
'blocks'
;
const
GROUP_MODEL
=
'models'
;
const
GROUP_HELPER
=
'helpers'
;
const
TYPE_CLASS_ALIAS
=
'class_alias'
;
/**
* Mapping of the text that represents
* class alias group in fail message
*
* @var array
*/
protected
$_textByGroup
=
array
(
self
::
GROUP_BLOCK
=>
'block alias'
,
self
::
GROUP_MODEL
=>
'model alias'
,
self
::
GROUP_HELPER
=>
'helper alias'
);
/**
* Class alias name, e.g. the name of the model
*
* @var string
*/
protected
$_classAliasName
=
null
;
/**
* Class alias prefix,
* e.g. the prefix for models of a particular module
*
* @var string
*/
protected
$_classAliasPrefix
=
null
;
/**
* Class alias group
*
* @var string
*/
protected
$_group
=
null
;
/**
* Constraint for evaluation of grouped class alias (block, model, helper)
*
* @param string $group
* @param string $classAlias
* @param string $expectedClassName
* @param string $type
*/
public
function
__construct
(
$group
,
$classAlias
,
$expectedClassName
,
$type
=
self
::
TYPE_CLASS_ALIAS
)
{
if
(
!
isset
(
$this
->
_textByGroup
[
$group
]))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
1
,
implode
(
'|'
,
array_keys
(
$this
->
_textByGroup
)
),
$group
);
}
$this
->
_group
=
$group
;
if
(
$group
===
self
::
GROUP_HELPER
&&
strpos
(
$classAlias
,
'/'
)
===
false
)
{
$classAlias
.=
'/data'
;
}
if
(
!
strpos
(
$classAlias
,
'/'
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
2
,
'class/alias'
,
$classAlias
);
}
list
(
$this
->
_classAliasPrefix
,
$this
->
_classAliasName
)
=
explode
(
'/'
,
$classAlias
,
2
);
$nodePath
=
sprintf
(
self
::
XML_PATH_CLASS_ALIAS
,
$group
,
$this
->
_classAliasPrefix
);
$this
->
_expectedValueValidation
+=
array
(
self
::
TYPE_CLASS_ALIAS
=>
array
(
true
,
'is_string'
,
'string'
)
);
$this
->
_typesWithDiff
[]
=
self
::
TYPE_CLASS_ALIAS
;
parent
::
__construct
(
$nodePath
,
$type
,
$expectedClassName
);
}
/**
* Evaluates class alias is mapped to expected class name
*
* @param Varien_Simplexml_Element $other
* @return boolean
*/
protected
function
evaluateClassAlias
(
$other
)
{
$classPrefix
=
$other
->
class
;
if
(
isset
(
$other
->
rewrite
->
{
$this
->
_classAliasName
}))
{
$className
=
(
string
)
$other
->
rewrite
->
{
$this
->
_classAliasName
};
}
else
{
$className
=
$classPrefix
.
'_'
.
uc_words
(
$this
->
_classAliasName
);
}
$this
->
setActualValue
(
$className
);
return
$this
->
_actualValue
===
$this
->
_expectedValue
;
}
/**
* Text representation of class alias constaint
*
* @return string
*/
protected
function
textClassAlias
()
{
return
'is mapped to expected class name'
;
}
/**
* Custom failure description for showing config related errors
* (non-PHPdoc)
* @see PHPUnit_Framework_Constraint::customFailureDescription()
*/
protected
function
customFailureDescription
(
$other
,
$description
,
$not
)
{
return
sprintf
(
'Failed asserting that %s "%s/%s" %s.'
,
$this
->
_textByGroup
[
$this
->
_group
],
$this
->
_classAliasPrefix
,
$this
->
_classAliasName
,
$this
->
toString
()
);
}
}
lib/EcomDev/PHPUnit/Constraint/Config/EventObserver.php
0 → 100644
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Constraint for testing event observer definition
* in the configuration
*
*/
class
EcomDev_PHPUnit_Constraint_Config_EventObserver
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_EVENTS
=
'%s/events'
;
const
TYPE_DEFINDED
=
'defined'
;
const
OBSERVER_TYPE_DISABLED
=
'disabled'
;
const
OBSERVER_TYPE_SINGLETON
=
'singleton'
;
const
OBSERVER_TYPE_MODEL
=
'model'
;
/**
* Event area (frontend, adminhtml, global, cron)
*
* @var string
*/
protected
$_area
=
null
;
/**
* Observer name for additional restriction
*
* @var string|null
*/
protected
$_observerName
=
null
;
/**
* Observer class alias
*
* @var string
*/
protected
$_observerClassAlias
=
null
;
/**
* Observer method
*
* @var string
*/
protected
$_observerMethod
=
null
;
/**
* Name of the event that should be observed
*
* @var string
*/
protected
$_eventName
=
null
;
/**
* Constraint for testing observer
* event definitions in configuration
*
* @param string $area
* @param string $eventName
* @param string $observerClassAlias
* @param string $observerMethod
* @param string|null $observerName
*/
public
function
__construct
(
$area
,
$eventName
,
$observerClassAlias
,
$observerMethod
,
$type
=
self
::
TYPE_DEFINDED
,
$observerName
=
null
)
{
if
(
empty
(
$area
)
||
!
is_string
(
$area
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
1
,
'string'
,
$area
);
}
if
(
empty
(
$eventName
)
||
!
is_string
(
$eventName
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
2
,
'string'
,
$eventName
);
}
if
(
empty
(
$observerClassAlias
)
||
!
is_string
(
$observerClassAlias
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
3
,
'string'
,
$observerClassAlias
);
}
if
(
empty
(
$observerMethod
)
||
!
is_string
(
$observerMethod
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
4
,
'string'
,
$observerMethod
);
}
if
(
$observerName
!==
null
&&
!
is_string
(
$observerName
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
6
,
'string'
,
$observerName
);
}
$this
->
_area
=
$area
;
$this
->
_eventName
=
$eventName
;
$this
->
_observerClassAlias
=
$observerClassAlias
;
$this
->
_observerMethod
=
$observerMethod
;
$this
->
_observerName
=
$observerName
;
$expectedValue
=
$this
->
_observerClassAlias
.
'::'
.
$this
->
_observerMethod
;
$nodePath
=
sprintf
(
self
::
XML_PATH_EVENTS
,
$this
->
_area
,
$this
->
_eventName
);
parent
::
__construct
(
$nodePath
,
$type
,
$expectedValue
);
}
/**
* Evaluates that observer is defined and enabled
*
* @param Varien_Simplexml_Element $other
* @return boolean
*/
protected
function
evaluateDefined
(
$other
)
{
$this
->
setActualValue
(
false
);
if
(
!
isset
(
$other
->
{
$this
->
_eventName
}
->
observers
))
{
return
false
;
}
$observers
=
$other
->
{
$this
->
_eventName
}
->
observers
;
foreach
(
$observers
->
children
()
as
$observer
)
{
if
((
string
)
$observer
->
type
===
self
::
OBSERVER_TYPE_DISABLED
||
(
$this
->
_observerName
!==
null
&&
$this
->
_observerName
!==
$observer
->
getName
()))
{
continue
;
}
$classAlias
=
(
isset
(
$observer
->
class
)
?
(
string
)
$observer
->
class
:
$observer
->
getClassName
());
$method
=
(
string
)
$observer
->
method
;
if
(
$classAlias
===
$this
->
_observerClassAlias
&&
$method
==
$this
->
_observerMethod
)
{
$this
->
setActualValue
(
$classAlias
.
'::'
.
$method
);
return
true
;
}
}
return
false
;
}
/**
* Text representation of event observer definition evaluation
*
* @return string
*/
protected
function
textDefined
()
{
$text
=
'is defined'
;
if
(
$this
->
_observerName
!==
null
)
{
$text
.=
sprintf
(
' as %s observer name'
,
$this
->
_observerName
);
}
return
$text
;
}
/**
* Custom failure description for showing config related errors
* (non-PHPdoc)
* @see PHPUnit_Framework_Constraint::customFailureDescription()
*/
protected
function
customFailureDescription
(
$other
,
$description
,
$not
)
{
return
sprintf
(
'Failed asserting that %s "%s" event observer %s.'
,
$this
->
_area
,
$this
->
_expectedValue
,
$this
->
toString
()
);
}
}
lib/EcomDev/PHPUnit/Constraint/Config/Interface.php
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Interface for configuration constraints
...
...
lib/EcomDev/PHPUnit/Constraint/Config/Layout.php
0 → 100644
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Layout configuration constraint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_Layout
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_LAYOUT
=
'%s/layout/updates'
;
const
TYPE_LAYOUT_DEFINITION
=
'layout_definition'
;
const
TYPE_LAYOUT_FILE
=
'layout_file'
;
/**
* Design area (frontend, adminhtml)
*
* @var string
*/
protected
$_area
=
null
;
/**
* Name of layout update,
* if specified, constraint
* will be additionally checked by this parameter
*
* @var string
*/
protected
$_layoutUpdate
=
null
;
/**
* Restriction by theme name
*
* @var string
*/
protected
$_theme
=
null
;
/**
* Restriction by design package name
*
* @var string
*/
protected
$_designPackage
=
null
;
/**
* Model for assertion of the data
*
* @var EcomDev_PHPUnit_Constraint_Config_Design_Package_Interface
*/
protected
static
$_designPackageModel
=
null
;
/**
* Configuration constraint for cheking the existance of
* layout file in configuration and a particular theme as well
*
* @param string $area design area (frontend|adminhtml)
* @param string $expectedFile layout file name that should be checked
* @param string $type type of assertion
* @param string|null $layoutUpdate additional check for layout update name for assertion of configuration
* @param string|null $theme additional check for layout file existance in a particular theme
* @param string|null $designPackage additional check for layout file existance in a particular theme
*/
public
function
__construct
(
$area
,
$expectedFile
,
$type
,
$layoutUpdate
=
null
,
$theme
=
null
,
$designPackage
=
null
)
{
$this
->
_area
=
$area
;
$this
->
_layoutUpdate
=
$layoutUpdate
;
$this
->
_designPackage
=
$designPackage
;
$this
->
_theme
=
$theme
;
$this
->
_expectedValueValidation
+=
array
(
self
::
TYPE_LAYOUT_FILE
=>
array
(
true
,
'is_string'
,
'string'
),
self
::
TYPE_LAYOUT_DEFINITION
=>
array
(
true
,
'is_string'
,
'string'
)
);
$this
->
_typesWithDiff
[]
=
self
::
TYPE_LAYOUT_FILE
;
$nodePath
=
sprintf
(
self
::
XML_PATH_LAYOUT
,
$area
);
parent
::
__construct
(
$nodePath
,
$type
,
$expectedFile
);
}
/**
* Sets design package model for assertions
*
* @param EcomDev_PHPUnit_Constraint_Config_Design_Package_Interface $model
*/
public
static
function
setDesignPackageModel
(
EcomDev_PHPUnit_Constraint_Config_Design_Package_Interface
$model
)
{
self
::
$_designPackageModel
=
$model
;
}
/**
* Retrieves design package model that was set before
*
* @return EcomDev_PHPUnit_Constraint_Config_Design_Package_Interface
*/
public
static
function
getDesignPackageModel
()
{
return
self
::
$_designPackageModel
;
}
/**
* Checks layout definititions for expected file defined in the configuration
*
* @param Varien_Simplexml_Element $other
* @return boolean
*/
protected
function
evaluateLayoutDefinition
(
$other
)
{
foreach
(
$other
->
children
()
as
$layoutUpdate
)
{
if
((
string
)
$layoutUpdate
->
file
===
$this
->
_expectedValue
&&
(
$this
->
_layoutUpdate
===
null
||
$this
->
_layoutUpdate
===
$layoutUpdate
->
getName
()))
{
return
true
;
}
}
return
false
;
}
/**
* Layout defition assertion text
*
* @return string
*/
protected
function
textLayoutDefition
()
{
$text
=
sprintf
(
'file "%s" is defined in configuration for %s area'
,
$this
->
_expectedValue
,
$this
->
_area
);
if
(
$this
->
_layoutUpdate
!==
null
)
{
$text
.=
sprintf
(
' in "%s" layout update'
,
$this
->
_layoutUpdate
);
}
return
$text
;
}
/**
* Evaluates layout file existance
*
* @param Varien_Simplexml_Element $other
* @return boolean
*/
protected
function
evaluateLayoutFile
(
$other
)
{
$assertion
=
self
::
getDesignPackageModel
()
->
getLayoutFileAssertion
(
$this
->
_expectedValue
,
$this
->
_area
,
$this
->
_designPackage
,
$this
->
_theme
);
$this
->
setActualValue
(
$assertion
[
'actual'
]);
$this
->
_expectedValue
=
$assertin
[
'expected'
];
return
$this
->
_actualValue
!==
$this
->
_expectedValue
;
}
/**
* Text representation of layout file existance constraint
*
* @return string
*/
protected
function
textLayoutFile
()
{
return
'file is the same as expected and exists'
;
}
/**
* Custom failure description for showing config related errors
* (non-PHPdoc)
* @see PHPUnit_Framework_Constraint::customFailureDescription()
*/
protected
function
customFailureDescription
(
$other
,
$description
,
$not
)
{
return
sprintf
(
'Failed asserting that layout %s.'
,
$this
->
toString
()
);
}
}
lib/EcomDev/PHPUnit/Constraint/Config/Layout/Design/Package/Interface.php
0 → 100644
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Interface for assertions in layout configuration
*
*/
interface
EcomDev_PHPUnit_Constraint_Config_Layout_Design_Package_Interface
{
/**
* Asserts layout file existance in design packages,
* and returns actual and expected filenames as result
*
* @param string $fileName
* @param string $area
* @param string|null $designPackage if not specified any theme will be used
* @param string|null $theme if not specified any theme will be used
* @return array of 'expected' and 'actual' file names
*/
public
function
getLayoutFileAssertion
(
$fileName
,
$area
,
$designPackage
=
null
,
$theme
=
null
);
}
lib/EcomDev/PHPUnit/Constraint/Config/Module.php
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
class
EcomDev_PHPUnit_Constraint_Config_Module
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
/**
* Module configuration constraint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_Module
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_MODULE_NODE
=
'modules/%s'
;
...
...
@@ -19,7 +40,7 @@ class EcomDev_PHPUnit_Constraint_Config_Module extends EcomDev_PHPUnit_Constrain
protected
$_moduleName
=
null
;
/**
* Contraint for evaluation of config node
* Contraint for evaluation of
module
config node
*
* @param string $nodePath
* @param string $type
...
...
lib/EcomDev/PHPUnit/Constraint/Config/Node.php
View file @
68f9fe81
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2011 Ecommerce Developers (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Configuration node constaint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_Node
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment