Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-basic-requirements
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-basic-requirements
Commits
66dc74af
Commit
66dc74af
authored
7 years ago
by
dyszczo
Browse files
Options
Downloads
Patches
Plain Diff
requirement tests for wp, php, module, wp_plugin
parent
f2f40fc3
No related branches found
No related tags found
1 merge request
!3
testy jednostkowe + trochę fixów + wsparcie dla openssl
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
composer.json
+1
-1
1 addition, 1 deletion
composer.json
phpunit-unit.xml
+1
-1
1 addition, 1 deletion
phpunit-unit.xml
tests/unit/Test_Basic_Requirement_Checker.php
+111
-0
111 additions, 0 deletions
tests/unit/Test_Basic_Requirement_Checker.php
with
113 additions
and
2 deletions
composer.json
+
1
−
1
View file @
66dc74af
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
},
},
"autoload-dev"
:
{
"autoload-dev"
:
{
"classmap"
:
[
"src"
]
"classmap"
:
[
"src"
,
"tests"
]
},
},
"scripts"
:
{
"scripts"
:
{
"phpcs"
:
"phpcs"
,
"phpcs"
:
"phpcs"
,
...
...
This diff is collapsed.
Click to expand it.
phpunit-unit.xml
+
1
−
1
View file @
66dc74af
<phpunit
bootstrap=
"tests/unit/bootstrap.php"
>
<phpunit
bootstrap=
"tests/unit/bootstrap.php"
>
<testsuites>
<testsuites>
<testsuite>
<testsuite>
<directory
prefix=
"
t
est
-
"
suffix=
".php"
>
./tests/unit/
</directory>
<directory
prefix=
"
T
est
_
"
suffix=
".php"
>
./tests/unit/
</directory>
</testsuite>
</testsuite>
</testsuites>
</testsuites>
...
...
This diff is collapsed.
Click to expand it.
tests/unit/Test_Basic_Requirement_Checker.php
0 → 100644
+
111
−
0
View file @
66dc74af
<?php
class
Test_Basic_Requirement_Checker
extends
PHPUnit\Framework\TestCase
{
const
RANDOM_PLUGIN_FILE
=
'file'
;
const
RANDOM_PLUGIN_NAME
=
'name'
;
const
RANDOM_PLUGIN_TEXTDOMAIN
=
'text'
;
const
ALWAYS_VALID_PHP_VERSION
=
'5.2'
;
const
ALWAYS_VALID_WP_VERSION
=
'4.0'
;
public
function
setUp
()
{
WP_Mock
::
setUp
();
WP_Mock
::
wpFunction
(
'get_bloginfo'
)
->
andReturn
(
self
::
ALWAYS_VALID_WP_VERSION
);
}
public
function
tearDown
()
{
WP_Mock
::
tearDown
();
}
/**
* @param string $php
* @param string $wp
*
* @return WPDesk_Basic_Requirement_Checker
*/
public
function
create_requirements_for_php_wp
(
$php
,
$wp
)
{
return
new
WPDesk_Basic_Requirement_Checker
(
self
::
RANDOM_PLUGIN_FILE
,
self
::
RANDOM_PLUGIN_NAME
,
self
::
RANDOM_PLUGIN_TEXTDOMAIN
,
$php
,
$wp
);
}
public
function
test_php_version_check
()
{
$known_PHP_versions
=
[
'7.3'
,
'7.2'
,
'7.1'
,
'7.0'
,
'5.6'
,
'5.5'
,
'5.4'
,
'5.3'
,
'5.2'
];
$requirements
=
$this
->
create_requirements_for_php_wp
(
self
::
ALWAYS_VALID_PHP_VERSION
,
self
::
ALWAYS_VALID_WP_VERSION
);
foreach
(
$known_PHP_versions
as
$version
)
{
$requirements
->
set_min_php_require
(
$version
);
if
(
version_compare
(
PHP_VERSION
,
$version
,
'>='
)
)
{
$this
->
assertTrue
(
$requirements
->
are_requirements_met
(),
'Should be ok because WP is OK and PHP is OK'
);
}
else
{
$this
->
assertFalse
(
$requirements
->
are_requirements_met
(),
'Should fail because required PHP should be at least '
.
$version
);
}
}
}
public
function
test_wp_version_check
()
{
$wp_version_fail
=
'4.1'
;
$requirements
=
$this
->
create_requirements_for_php_wp
(
self
::
ALWAYS_VALID_PHP_VERSION
,
self
::
ALWAYS_VALID_WP_VERSION
);
$this
->
assertTrue
(
$requirements
->
are_requirements_met
(),
'Should be ok because WP is OK and PHP is OK'
);
$requirements
->
set_min_wp_require
(
$wp_version_fail
);
$this
->
assertFalse
(
$requirements
->
are_requirements_met
(),
'Should fail because required WP should be at least '
.
$wp_version_fail
);
}
/**
* @requires extension curl
*/
public
function
test_module_check
()
{
$requirements
=
$this
->
create_requirements_for_php_wp
(
self
::
ALWAYS_VALID_PHP_VERSION
,
self
::
ALWAYS_VALID_WP_VERSION
);
$requirements
->
add_php_module_require
(
'curl'
);
$this
->
assertTrue
(
$requirements
->
are_requirements_met
(),
'Curl should exists'
);
}
public
function
test_plugin_check_with_multisite
()
{
$multisite
=
true
;
$exising_plugin_name
=
'WooCommerce'
;
$exising_multisite_plugin_name
=
'Multisite'
;
$not_existing_plugin_name
=
'Whatever'
;
WP_Mock
::
wpFunction
(
'get_option'
)
->
withArgs
(
[
'active_plugins'
,
[]
]
)
->
andReturn
(
[
$exising_plugin_name
]
);
WP_Mock
::
wpFunction
(
'is_multisite'
)
->
andReturn
(
$multisite
);
WP_Mock
::
wpFunction
(
'get_site_option'
)
->
withArgs
(
[
'active_sitewide_plugins'
,
[]
]
)
->
andReturn
(
[
$exising_multisite_plugin_name
]
);
$requirements
=
$this
->
create_requirements_for_php_wp
(
self
::
ALWAYS_VALID_PHP_VERSION
,
self
::
ALWAYS_VALID_WP_VERSION
);
$requirements
->
add_plugin_require
(
$exising_plugin_name
);
$this
->
assertTrue
(
$requirements
->
are_requirements_met
(),
'Plugin should exists'
);
$requirements
->
add_plugin_require
(
$exising_multisite_plugin_name
);
$this
->
assertTrue
(
$requirements
->
are_requirements_met
(),
'Multisite plugin should exists'
);
$requirements
->
add_plugin_require
(
$not_existing_plugin_name
);
$this
->
assertFalse
(
$requirements
->
are_requirements_met
(),
'Plugin should not exists'
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment