Version Description
Download this release
Release Info
Developer | vasyltech |
Plugin | Advanced Access Manager |
Version | 6.0.0-beta.1 |
Comparing to | |
See all releases |
Code changes from version 6.0.0-alpha.2 to 6.0.0-beta.1
- aam.php +1 -1
- application/Addon/Repository.php +5 -5
- application/Backend/Feature/Abstract.php +2 -2
- application/Backend/Feature/Main/Jwt.php +26 -7
- application/Backend/Feature/Main/Post.php +14 -7
- application/Backend/Feature/Settings/Content.php +2 -2
- application/Backend/Feature/Settings/Core.php +2 -2
- application/Backend/Feature/Settings/Security.php +2 -2
- application/Backend/Feature/Settings/Service.php +2 -2
- application/Backend/Feature/Subject/User.php +20 -3
- application/Backend/Manager.php +57 -6
- application/Backend/View/Localization.php +1 -0
- application/Backend/tmpl/index.php +3 -0
- application/Backend/tmpl/partial/post-access-form.php +1 -1
- application/Core/API.php +1 -0
- application/Core/Contract/MigrationInterface.php +2 -2
- application/Core/Gateway.php +54 -1
- application/Core/Jwt/Issuer.php +14 -6
- application/Core/Migration.php +110 -19
- application/Core/Migration/2019_06_30-migrate-settings-to-6.0.0.php +0 -384
- application/Core/Object.php +13 -1
- application/Core/Object/Menu.php +0 -1
- application/Core/Object/Route.php +1 -3
- application/Core/Policy/Resource.php +7 -0
- application/Core/Policy/Token.php +23 -0
- application/Core/Subject/User.php +11 -24
- application/Migration/2019_06_30-base.php +916 -0
- application/Service/AccessPolicy.php +81 -56
- application/Service/AdminMenu.php +17 -15
- application/Service/Compatibility.php +31 -5
- application/Service/Content.php +3 -3
- application/Service/Core.php +1 -1
- application/Service/ExtendedCapabilities.php +20 -29
- application/Service/Jwt.php +45 -22
- application/Service/UserLevelFilter.php +7 -5
- lang/advanced-access-manager-en_US.po +207 -191
- media/css/aam.css +1 -0
- media/js/aam.js +64 -55
- readme.txt +0 -1069
- tests/Addon/IpCheck/IpCheckTest.php +0 -343
- tests/Addon/PlusPackage/ContentAccessTest.php +0 -451
- tests/Addon/PlusPackage/ContentVisibilityTest.php +0 -204
- tests/Addon/PlusPackage/DefaultCategoryTest.php +0 -226
- tests/Addon/PlusPackage/TermRESTfulAccessTest.php +0 -221
- tests/Addon/PlusPackage/UriAccessTest.php +0 -101
- tests/Addon/RoleHierarchy/RoleHierarchyTest.php +0 -58
- tests/Core/GatewayTest.php +0 -90
- tests/Core/SubjectLoadTest.php +0 -32
- tests/Libs/AuthManagerUserTrait.php +0 -36
- tests/Libs/AuthMultiRoleUserTrait.php +0 -57
- tests/Libs/AuthUserTrait.php +0 -37
- tests/Libs/MultiRoleOptionInterface.php +0 -17
- tests/Libs/ResetTrait.php +0 -92
- tests/Service/AccessPolicy/PolicyConditionTest.php +0 -543
- tests/Service/AccessPolicy/PolicyManagerTest.php +0 -170
- tests/Service/AccessPolicy/PolicyServiceIntegrationTest.php +0 -413
- tests/Service/AccessPolicy/PolicyTokenTest.php +0 -236
- tests/Service/AccessPolicy/PolicyUserRoleIntegrationTest.php +0 -143
- tests/Service/AccessPolicy/PolicyValidationTest.php +0 -125
- tests/Service/AccessPolicy/policies/admin-menu.json +0 -11
- tests/Service/AccessPolicy/policies/capability-changes.json +0 -17
- tests/Service/AccessPolicy/policies/dynamic-param.json +0 -9
- tests/Service/AccessPolicy/policies/dynamic-resource.json +0 -12
- tests/Service/AccessPolicy/policies/metabox.json +0 -12
- tests/Service/AccessPolicy/policies/option-override-policy.json +0 -9
- tests/Service/AccessPolicy/policies/plugins.json +0 -8
- tests/Service/AccessPolicy/policies/post-complex-actions.json +0 -18
- tests/Service/AccessPolicy/policies/post-hidden.json +0 -10
- tests/Service/AccessPolicy/policies/post-redirect-callback.json +0 -16
- tests/Service/AccessPolicy/policies/post-redirect-page-id.json +0 -17
- tests/Service/AccessPolicy/policies/post-redirect-page-slug.json +0 -17
- tests/Service/AccessPolicy/policies/post-redirect-url.json +0 -14
- tests/Service/AccessPolicy/policies/post-restricted.json +0 -10
- tests/Service/AccessPolicy/policies/post-simple-actions.json +0 -10
- tests/Service/AccessPolicy/policies/role-add.json +0 -11
- tests/Service/AccessPolicy/policies/role-remove.json +0 -11
- tests/Service/AccessPolicy/policies/simple-policy-with-action.json +0 -12
- tests/Service/AccessPolicy/policies/simple-policy.json +0 -9
- tests/Service/AccessPolicy/policies/single-plugin.json +0 -10
- tests/Service/AccessPolicy/policies/toolbar.json +0 -11
- tests/Service/AccessPolicy/policies/uri.json +0 -57
- tests/Service/AdminMenu/MultipleRoleInheritanceTest.php +0 -182
- tests/Service/AdminMenu/SingleRoleInheritanceTest.php +0 -226
- tests/Service/Capabilities/CapabilityManagerTest.php +0 -345
- tests/Service/Content/Callback.php +0 -13
- tests/Service/Content/MultipleRoleInheritanceTest.php +0 -190
- tests/Service/Content/RESTfulSingleRoleAccessControlTest.php +0 -579
- tests/Service/Content/SingleRoleAccessControlTest.php +0 -602
- tests/Service/Content/SingleRoleInheritanceTest.php +0 -221
- tests/Service/Content/VisitorAccessControlTest.php +0 -432
- tests/Service/Core/CoreServiceTest.php +0 -43
- tests/Service/DeniedRedirect/Callback.php +0 -14
- tests/Service/DeniedRedirect/DeniedRedirectTest.php +0 -189
- tests/Service/Jwt/JwtTest.php +0 -360
- tests/Service/LoginRedirect/Callback.php +0 -14
- tests/Service/LoginRedirect/LoginRedirectTest.php +0 -215
- tests/Service/LogoutRedirect/Callback.php +0 -14
- tests/Service/LogoutRedirect/LogoutRedirectTest.php +0 -115
- tests/Service/Metabox/MultipleRoleInheritanceTest.php +0 -192
- tests/Service/Metabox/SingleRoleInheritanceTest.php +0 -231
- tests/Service/Metabox/VisitorInheritanceTest.php +0 -187
- tests/Service/NotFoundRedirect/Callback.php +0 -14
- tests/Service/NotFoundRedirect/NotFoundRedirectTest.php +0 -141
- tests/Service/Route/RouteTest.php +0 -99
- tests/Service/SecureLogin/SecureLoginTest.php +0 -151
- tests/Service/Toolbar/MultipleRoleInheritanceTest.php +0 -179
- tests/Service/Toolbar/SingleRoleInheritanceTest.php +0 -225
- tests/Service/Uri/Callback.php +0 -14
- tests/Service/Uri/UriTest.php +0 -177
- tests/Service/UserLevelFilter/UserLevelFilterTest.php +0 -151
- tests/bootstrap.php +0 -27
aam.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
/**
|
4 |
* Plugin Name: Advanced Access Manager
|
5 |
* Description: Collection of features to manage your WordPress website authentication, authorization and monitoring
|
6 |
-
* Version: 6.0.0-
|
7 |
* Author: Vasyl Martyniuk <vasyl@vasyltech.com>
|
8 |
* Author URI: https://vasyltech.com
|
9 |
* Text Domain: advanced-access-manager
|
3 |
/**
|
4 |
* Plugin Name: Advanced Access Manager
|
5 |
* Description: Collection of features to manage your WordPress website authentication, authorization and monitoring
|
6 |
+
* Version: 6.0.0-beta.1
|
7 |
* Author: Vasyl Martyniuk <vasyl@vasyltech.com>
|
8 |
* Author URI: https://vasyltech.com
|
9 |
* Text Domain: advanced-access-manager
|
application/Addon/Repository.php
CHANGED
@@ -25,7 +25,7 @@ class AAM_Addon_Repository
|
|
25 |
*
|
26 |
* @version 6.0.0
|
27 |
*/
|
28 |
-
const
|
29 |
|
30 |
/**
|
31 |
* Constructor
|
@@ -52,7 +52,7 @@ class AAM_Addon_Repository
|
|
52 |
*/
|
53 |
public function getRegistry()
|
54 |
{
|
55 |
-
return AAM_Core_API::getOption(self::
|
56 |
}
|
57 |
|
58 |
/**
|
@@ -88,7 +88,7 @@ class AAM_Addon_Repository
|
|
88 |
);
|
89 |
|
90 |
// Update the registry
|
91 |
-
AAM_Core_API::updateOption(self::
|
92 |
}
|
93 |
|
94 |
/**
|
@@ -107,12 +107,12 @@ class AAM_Addon_Repository
|
|
107 |
'plus-package',
|
108 |
__('Manage access to your WordPress website posts, pages, media, custom post types, categories, tags and custom taxonomies for any role, individual user, visitors or even define default access for everybody; and do this separately for frontend, backend or API levels.', AAM_KEY)
|
109 |
),
|
110 |
-
'aam-' => $this->buildAddonObject(
|
111 |
'IP Check',
|
112 |
'ip-check',
|
113 |
__('Manage access to your WordPress website by users IP address or referred host and completely lock down the entire website if necessary. Define the unlimited number of whitelisted or blacklisted IPs or hosts.', AAM_KEY)
|
114 |
),
|
115 |
-
'aam-' => $this->buildAddonObject(
|
116 |
'Role Hierarchy',
|
117 |
'role-hierarchy',
|
118 |
__('Define and manage complex WordPress role hierarchy where all the access settings are propagated down the tree with the ability to override any settings for any specific role.', AAM_KEY)
|
25 |
*
|
26 |
* @version 6.0.0
|
27 |
*/
|
28 |
+
const DB_OPTION = 'aam_addons';
|
29 |
|
30 |
/**
|
31 |
* Constructor
|
52 |
*/
|
53 |
public function getRegistry()
|
54 |
{
|
55 |
+
return AAM_Core_API::getOption(self::DB_OPTION, array(), 'site');
|
56 |
}
|
57 |
|
58 |
/**
|
88 |
);
|
89 |
|
90 |
// Update the registry
|
91 |
+
AAM_Core_API::updateOption(self::DB_OPTION, $list);
|
92 |
}
|
93 |
|
94 |
/**
|
107 |
'plus-package',
|
108 |
__('Manage access to your WordPress website posts, pages, media, custom post types, categories, tags and custom taxonomies for any role, individual user, visitors or even define default access for everybody; and do this separately for frontend, backend or API levels.', AAM_KEY)
|
109 |
),
|
110 |
+
'aam-ip-check' => $this->buildAddonObject(
|
111 |
'IP Check',
|
112 |
'ip-check',
|
113 |
__('Manage access to your WordPress website by users IP address or referred host and completely lock down the entire website if necessary. Define the unlimited number of whitelisted or blacklisted IPs or hosts.', AAM_KEY)
|
114 |
),
|
115 |
+
'aam-role-hierarchy' => $this->buildAddonObject(
|
116 |
'Role Hierarchy',
|
117 |
'role-hierarchy',
|
118 |
__('Define and manage complex WordPress role hierarchy where all the access settings are propagated down the tree with the ability to override any settings for any specific role.', AAM_KEY)
|
application/Backend/Feature/Abstract.php
CHANGED
@@ -51,8 +51,8 @@ abstract class AAM_Backend_Feature_Abstract
|
|
51 |
*/
|
52 |
public function save()
|
53 |
{
|
54 |
-
$param =
|
55 |
-
$value =
|
56 |
|
57 |
$object = $this->getSubject()->getObject(static::OBJECT_TYPE, null, true);
|
58 |
|
51 |
*/
|
52 |
public function save()
|
53 |
{
|
54 |
+
$param = $this->getFromPost('param');
|
55 |
+
$value = $this->getFromPost('value');
|
56 |
|
57 |
$object = $this->getSubject()->getObject(static::OBJECT_TYPE, null, true);
|
58 |
|
application/Backend/Feature/Main/Jwt.php
CHANGED
@@ -62,9 +62,10 @@ class AAM_Backend_Feature_Main_Jwt
|
|
62 |
$result = array('status' => 'failure');
|
63 |
|
64 |
if (current_user_can('aam_manage_jwt')) {
|
65 |
-
$expires
|
66 |
-
$refresh
|
67 |
-
$
|
|
|
68 |
|
69 |
// Determine maximum user level
|
70 |
$max = AAM::getUser()->getMaxLevel();
|
@@ -87,8 +88,19 @@ class AAM_Backend_Feature_Main_Jwt
|
|
87 |
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(
|
88 |
$claims, $expires
|
89 |
);
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
} else {
|
93 |
$result['reason'] = 'You are not allowed to generate JWT for this user';
|
94 |
}
|
@@ -178,13 +190,20 @@ class AAM_Backend_Feature_Main_Jwt
|
|
178 |
$issuer = AAM_Core_Jwt_Issuer::getInstance();
|
179 |
|
180 |
foreach ($tokens as $token) {
|
181 |
-
$claims
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
$response['data'][] = array(
|
184 |
$token,
|
185 |
add_query_arg('aam-jwt', $token, site_url()),
|
186 |
$claims->isValid,
|
187 |
-
$
|
188 |
'view,delete'
|
189 |
);
|
190 |
}
|
62 |
$result = array('status' => 'failure');
|
63 |
|
64 |
if (current_user_can('aam_manage_jwt')) {
|
65 |
+
$expires = $this->getFromPost('expires');
|
66 |
+
$refresh = $this->getFromPost('refreshable', FILTER_VALIDATE_BOOLEAN);
|
67 |
+
$register = $this->getFromPost('register', FILTER_VALIDATE_BOOLEAN);
|
68 |
+
$trigger = $this->getFromPost('trigger', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
|
69 |
|
70 |
// Determine maximum user level
|
71 |
$max = AAM::getUser()->getMaxLevel();
|
88 |
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(
|
89 |
$claims, $expires
|
90 |
);
|
91 |
+
|
92 |
+
if ($register === true) {
|
93 |
+
$status = AAM_Service_Jwt::getInstance()->registerToken(
|
94 |
+
$user->ID, $jwt->token
|
95 |
+
);
|
96 |
+
} else {
|
97 |
+
$status = true;
|
98 |
+
}
|
99 |
+
|
100 |
+
$result = array(
|
101 |
+
'status' => (!empty($status) ? 'success' : 'failure'),
|
102 |
+
'jwt' => $jwt->token
|
103 |
+
);
|
104 |
} else {
|
105 |
$result['reason'] = 'You are not allowed to generate JWT for this user';
|
106 |
}
|
190 |
$issuer = AAM_Core_Jwt_Issuer::getInstance();
|
191 |
|
192 |
foreach ($tokens as $token) {
|
193 |
+
$claims = $issuer->validateToken($token);
|
194 |
+
|
195 |
+
if ($claims->isValid) {
|
196 |
+
$expires = new DateTime('@' . $claims->exp, new DateTimeZone('UTC'));
|
197 |
+
$details = $expires->format('m/d/Y, H:i O');
|
198 |
+
} else {
|
199 |
+
$details = __('Token is no longer valid', AAM_KEY);
|
200 |
+
}
|
201 |
|
202 |
$response['data'][] = array(
|
203 |
$token,
|
204 |
add_query_arg('aam-jwt', $token, site_url()),
|
205 |
$claims->isValid,
|
206 |
+
$details,
|
207 |
'view,delete'
|
208 |
);
|
209 |
}
|
application/Backend/Feature/Main/Post.php
CHANGED
@@ -407,7 +407,7 @@ class AAM_Backend_Feature_Main_Post
|
|
407 |
$id = $this->getFromPost('objectId');
|
408 |
|
409 |
if ($type === 'post') {
|
410 |
-
$result =
|
411 |
$this->getSubject()->getId(),
|
412 |
sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, $id)
|
413 |
);
|
@@ -717,7 +717,11 @@ class AAM_Backend_Feature_Main_Post
|
|
717 |
{
|
718 |
// Prepare list of actions
|
719 |
$actions = apply_filters(
|
720 |
-
'aam_term_row_actions',
|
|
|
|
|
|
|
|
|
721 |
);
|
722 |
|
723 |
// Prepare row id
|
@@ -805,8 +809,8 @@ class AAM_Backend_Feature_Main_Post
|
|
805 |
|
806 |
// Retrieve filters
|
807 |
$s = AAM_Core_Request::post('search.value');
|
808 |
-
$length =
|
809 |
-
$start =
|
810 |
|
811 |
// Calculate how many term and/or posts we need to fetch
|
812 |
$paging = $this->getFetchPagination($type, $s, $start, $length);
|
@@ -858,7 +862,7 @@ class AAM_Backend_Feature_Main_Post
|
|
858 |
{
|
859 |
$result = array('terms' => 0, 'posts' => 0, 'term_offset' => $offset);
|
860 |
|
861 |
-
//
|
862 |
$taxonomy = get_object_taxonomies($type);
|
863 |
|
864 |
if (!empty($taxonomy)) {
|
@@ -873,7 +877,7 @@ class AAM_Backend_Feature_Main_Post
|
|
873 |
$terms = 0;
|
874 |
}
|
875 |
|
876 |
-
//
|
877 |
$posts = $this->getPostCount($type, $search);
|
878 |
|
879 |
if ($offset < $terms) {
|
@@ -887,8 +891,11 @@ class AAM_Backend_Feature_Main_Post
|
|
887 |
$result['posts'] = $limit;
|
888 |
}
|
889 |
|
|
|
|
|
|
|
890 |
$result['total'] = $terms + $posts;
|
891 |
-
$result['post_offset'] = ($
|
892 |
|
893 |
return $result;
|
894 |
}
|
407 |
$id = $this->getFromPost('objectId');
|
408 |
|
409 |
if ($type === 'post') {
|
410 |
+
$result = delete_user_option(
|
411 |
$this->getSubject()->getId(),
|
412 |
sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, $id)
|
413 |
);
|
717 |
{
|
718 |
// Prepare list of actions
|
719 |
$actions = apply_filters(
|
720 |
+
'aam_term_row_actions',
|
721 |
+
array('manage', 'edit'),
|
722 |
+
$this->getSubject(),
|
723 |
+
$term,
|
724 |
+
$type
|
725 |
);
|
726 |
|
727 |
// Prepare row id
|
809 |
|
810 |
// Retrieve filters
|
811 |
$s = AAM_Core_Request::post('search.value');
|
812 |
+
$length = $this->getFromPost('length', FILTER_VALIDATE_INT);
|
813 |
+
$start = $this->getFromPost('start', FILTER_VALIDATE_INT);
|
814 |
|
815 |
// Calculate how many term and/or posts we need to fetch
|
816 |
$paging = $this->getFetchPagination($type, $s, $start, $length);
|
862 |
{
|
863 |
$result = array('terms' => 0, 'posts' => 0, 'term_offset' => $offset);
|
864 |
|
865 |
+
// Get terms count
|
866 |
$taxonomy = get_object_taxonomies($type);
|
867 |
|
868 |
if (!empty($taxonomy)) {
|
877 |
$terms = 0;
|
878 |
}
|
879 |
|
880 |
+
// Get posts count
|
881 |
$posts = $this->getPostCount($type, $search);
|
882 |
|
883 |
if ($offset < $terms) {
|
891 |
$result['posts'] = $limit;
|
892 |
}
|
893 |
|
894 |
+
// Calculate post offset
|
895 |
+
$post_offset = ($offset ? $offset - $terms : 0);
|
896 |
+
|
897 |
$result['total'] = $terms + $posts;
|
898 |
+
$result['post_offset'] = ($post_offset < 0 ? 0 : $post_offset);
|
899 |
|
900 |
return $result;
|
901 |
}
|
application/Backend/Feature/Settings/Content.php
CHANGED
@@ -37,10 +37,10 @@ class AAM_Backend_Feature_Settings_Content extends AAM_Backend_Feature_Abstract
|
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
-
* @access
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
-
|
44 |
{
|
45 |
return apply_filters('aam_settings_list_filter', array(), 'content');
|
46 |
}
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
+
* @access public
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
+
public static function getList()
|
44 |
{
|
45 |
return apply_filters('aam_settings_list_filter', array(), 'content');
|
46 |
}
|
application/Backend/Feature/Settings/Core.php
CHANGED
@@ -37,10 +37,10 @@ class AAM_Backend_Feature_Settings_Core extends AAM_Backend_Feature_Abstract
|
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
-
* @access
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
-
|
44 |
{
|
45 |
$settings = array(
|
46 |
'core.settings.editCapabilities' => array(
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
+
* @access public
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
+
public static function getList()
|
44 |
{
|
45 |
$settings = array(
|
46 |
'core.settings.editCapabilities' => array(
|
application/Backend/Feature/Settings/Security.php
CHANGED
@@ -37,10 +37,10 @@ class AAM_Backend_Feature_Settings_Security extends AAM_Backend_Feature_Abstract
|
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
-
* @access
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
-
|
44 |
{
|
45 |
$settings = array(
|
46 |
'service.secureLogin.feature.singleSession' => array(
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
+
* @access public
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
+
public static function getList()
|
44 |
{
|
45 |
$settings = array(
|
46 |
'service.secureLogin.feature.singleSession' => array(
|
application/Backend/Feature/Settings/Service.php
CHANGED
@@ -37,10 +37,10 @@ class AAM_Backend_Feature_Settings_Service extends AAM_Backend_Feature_Abstract
|
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
-
* @access
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
-
|
44 |
{
|
45 |
$response = apply_filters('aam_service_list_filter', array());
|
46 |
|
37 |
*
|
38 |
* @return array
|
39 |
*
|
40 |
+
* @access public
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
+
public static function getList()
|
44 |
{
|
45 |
$response = apply_filters('aam_service_list_filter', array());
|
46 |
|
application/Backend/Feature/Subject/User.php
CHANGED
@@ -115,13 +115,28 @@ class AAM_Backend_Feature_Subject_User
|
|
115 |
*/
|
116 |
protected function prepareRow(AAM_Core_Subject_User $user)
|
117 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
return array(
|
119 |
$user->ID,
|
120 |
implode(', ', $this->prepareUserRoles($user->roles)),
|
121 |
$user->getName(),
|
122 |
implode(',', $this->prepareRowActions($user)),
|
123 |
AAM_Core_API::maxLevel($user->getMaxLevel()),
|
124 |
-
|
125 |
);
|
126 |
}
|
127 |
|
@@ -192,12 +207,14 @@ class AAM_Backend_Feature_Subject_User
|
|
192 |
private function _saveExpiration()
|
193 |
{
|
194 |
$userId = $this->getFromPost('user');
|
195 |
-
$expires = $this->getFromPost('expires');
|
196 |
$action = $this->getFromPost('after');
|
197 |
$role = $this->getFromPost('role');
|
|
|
|
|
|
|
198 |
|
199 |
$result = AAM::api()->getUser($userId)->setUserExpiration(array(
|
200 |
-
'expires' => $expires,
|
201 |
'action' => $action,
|
202 |
'meta' => (!empty($role) ? $role : null)
|
203 |
));
|
115 |
*/
|
116 |
protected function prepareRow(AAM_Core_Subject_User $user)
|
117 |
{
|
118 |
+
$attributes = array();
|
119 |
+
$expiration = get_user_option(
|
120 |
+
AAM_Core_Subject_User::EXPIRATION_OPTION, $user->ID
|
121 |
+
);
|
122 |
+
|
123 |
+
if (!empty($expiration)) {
|
124 |
+
$expires = new DateTime(
|
125 |
+
'@' . $expiration['expires'], new DateTimeZone('UTC')
|
126 |
+
);
|
127 |
+
|
128 |
+
$attributes[] = $expires->format('m/d/Y, H:i O');
|
129 |
+
$attributes[] = $expiration['action'];
|
130 |
+
$attributes[] = (!empty($expiration['meta']) ? $expiration['meta'] : null);
|
131 |
+
}
|
132 |
+
|
133 |
return array(
|
134 |
$user->ID,
|
135 |
implode(', ', $this->prepareUserRoles($user->roles)),
|
136 |
$user->getName(),
|
137 |
implode(',', $this->prepareRowActions($user)),
|
138 |
AAM_Core_API::maxLevel($user->getMaxLevel()),
|
139 |
+
implode('|', $attributes)
|
140 |
);
|
141 |
}
|
142 |
|
207 |
private function _saveExpiration()
|
208 |
{
|
209 |
$userId = $this->getFromPost('user');
|
|
|
210 |
$action = $this->getFromPost('after');
|
211 |
$role = $this->getFromPost('role');
|
212 |
+
$expires = DateTime::createFromFormat(
|
213 |
+
'm/d/Y, H:i O', $this->getFromPost('expires'), new DateTimeZone('UTC')
|
214 |
+
);
|
215 |
|
216 |
$result = AAM::api()->getUser($userId)->setUserExpiration(array(
|
217 |
+
'expires' => $expires->getTimestamp(),
|
218 |
'action' => $action,
|
219 |
'meta' => (!empty($role) ? $role : null)
|
220 |
));
|
application/Backend/Manager.php
CHANGED
@@ -71,6 +71,53 @@ class AAM_Backend_Manager
|
|
71 |
|
72 |
// Control admin area
|
73 |
add_action('admin_init', array($this, 'adminInit'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
|
76 |
/**
|
@@ -245,12 +292,16 @@ class AAM_Backend_Manager
|
|
245 |
*/
|
246 |
public function adminMenu()
|
247 |
{
|
248 |
-
$
|
|
|
|
|
|
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
254 |
}
|
255 |
|
256 |
$hasManagerCap = AAM_Core_API::capExists('aam_manager');
|
@@ -258,7 +309,7 @@ class AAM_Backend_Manager
|
|
258 |
// Register the menu
|
259 |
add_menu_page(
|
260 |
'AAM',
|
261 |
-
'AAM' . $
|
262 |
($hasManagerCap ? 'aam_manager' : 'administrator'),
|
263 |
'aam',
|
264 |
function() {
|
71 |
|
72 |
// Control admin area
|
73 |
add_action('admin_init', array($this, 'adminInit'));
|
74 |
+
|
75 |
+
// Check for pending migration scripts
|
76 |
+
if (current_user_can('update_plugins')) {
|
77 |
+
$this->checkMigrationStatus();
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Check if there are any pending settings and if so, trigger migration
|
83 |
+
*
|
84 |
+
* @return void
|
85 |
+
*
|
86 |
+
* @access protected
|
87 |
+
* @version 6.0.0
|
88 |
+
*/
|
89 |
+
protected function checkMigrationStatus()
|
90 |
+
{
|
91 |
+
if (AAM_Core_Migration::hasPending()) {
|
92 |
+
$results = array('errors' => array(), 'dumps' => array());
|
93 |
+
|
94 |
+
foreach(AAM_Core_Migration::getPending() as $filename) {
|
95 |
+
$executed = AAM_Core_Migration::executeScript($filename);
|
96 |
+
|
97 |
+
if (!empty($executed['errors'])) {
|
98 |
+
$results['errors'] = array_merge(
|
99 |
+
$results['errors'], $executed['errors']
|
100 |
+
);
|
101 |
+
$results['dumps'][basename($filename)] = $executed['dump'];
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
// If there are any errors, store the entire log so user can be notified
|
106 |
+
if (!empty($results['errors'])) {
|
107 |
+
AAM_Core_Migration::storeFailureLog($results);
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
// Check if there are any errors captured during the last migration process
|
112 |
+
$log = AAM_Core_Migration::getFailureLog();
|
113 |
+
|
114 |
+
if (!empty($log['errors'])) {
|
115 |
+
AAM_Core_Console::add(sprintf(
|
116 |
+
__('There was at least one error detected with the automated migration script. %sDownload the log%s for more details and contact our support at %ssupport@aamplugin.com%s for further assistance.', AAM_KEY),
|
117 |
+
'<a href="#" id="download-migration-log">', '</a>',
|
118 |
+
'<a href="mailto:support@aamplugin.com">', '</a>'
|
119 |
+
));
|
120 |
+
}
|
121 |
}
|
122 |
|
123 |
/**
|
292 |
*/
|
293 |
public function adminMenu()
|
294 |
{
|
295 |
+
$bubble = null; // Notification "bubble" for the AAM menu item
|
296 |
+
|
297 |
+
if (current_user_can('aam_show_notifications')) {
|
298 |
+
$count = AAM_Core_Console::count();
|
299 |
|
300 |
+
if ($count) {
|
301 |
+
$bubble = ' <span class="update-plugins">'
|
302 |
+
. '<span class="plugin-count">' . $count
|
303 |
+
. '</span></span>';
|
304 |
+
}
|
305 |
}
|
306 |
|
307 |
$hasManagerCap = AAM_Core_API::capExists('aam_manager');
|
309 |
// Register the menu
|
310 |
add_menu_page(
|
311 |
'AAM',
|
312 |
+
'AAM' . $bubble,
|
313 |
($hasManagerCap ? 'aam_manager' : 'administrator'),
|
314 |
'aam',
|
315 |
function() {
|
application/Backend/View/Localization.php
CHANGED
@@ -32,6 +32,7 @@ class AAM_Backend_View_Localization
|
|
32 |
'Search Capability' => __('Search Capability', AAM_KEY),
|
33 |
'_TOTAL_ capability(s)' => __('_TOTAL_ capability(s)', AAM_KEY),
|
34 |
'Saving...' => __('Saving...', AAM_KEY),
|
|
|
35 |
'Failed to add new capability' => __('Failed to add new capability', AAM_KEY),
|
36 |
'Application error' => __('Application error', AAM_KEY),
|
37 |
'Add Capability' => __('Add Capability', AAM_KEY),
|
32 |
'Search Capability' => __('Search Capability', AAM_KEY),
|
33 |
'_TOTAL_ capability(s)' => __('_TOTAL_ capability(s)', AAM_KEY),
|
34 |
'Saving...' => __('Saving...', AAM_KEY),
|
35 |
+
'Execute Migration' => __('Execute Migration', AAM_KEY),
|
36 |
'Failed to add new capability' => __('Failed to add new capability', AAM_KEY),
|
37 |
'Application error' => __('Application error', AAM_KEY),
|
38 |
'Add Capability' => __('Add Capability', AAM_KEY),
|
application/Backend/tmpl/index.php
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
<?php if (defined('AAM_KEY')) { ?>
|
2 |
<div class="wrap" id="aam-container">
|
3 |
<?php echo $this->loadTemplate(__DIR__ . '/page/current-subject.php'); ?>
|
@@ -29,6 +31,7 @@
|
|
29 |
<li><?php echo $message; ?></li>
|
30 |
<?php } ?>
|
31 |
</ul>
|
|
|
32 |
</div>
|
33 |
</div>
|
34 |
</div>
|
1 |
+
<?php /** @version 6.0.0 */ ?>
|
2 |
+
|
3 |
<?php if (defined('AAM_KEY')) { ?>
|
4 |
<div class="wrap" id="aam-container">
|
5 |
<?php echo $this->loadTemplate(__DIR__ . '/page/current-subject.php'); ?>
|
31 |
<li><?php echo $message; ?></li>
|
32 |
<?php } ?>
|
33 |
</ul>
|
34 |
+
<div class="hidden" id="migration-errors-container"><?php echo base64_encode(print_r(AAM_Core_Migration::getFailureLog(), 1)); ?></div>
|
35 |
</div>
|
36 |
</div>
|
37 |
</div>
|
application/Backend/tmpl/partial/post-access-form.php
CHANGED
@@ -77,7 +77,7 @@
|
|
77 |
<input type="number" class="form-control" placeholder="<?php echo __('Enter digital number', AAM_KEY); ?>" id="aam-access-threshold" value="<?php echo $params->object->get('limited.threshold'); ?>" />
|
78 |
</div>
|
79 |
<?php if ($params->subject->isUser()) { ?>
|
80 |
-
<?php $counter = intval(
|
81 |
<?php $remaining = $params->object->get('limited.threshold') - $counter; ?>
|
82 |
|
83 |
<div class="form-group">
|
77 |
<input type="number" class="form-control" placeholder="<?php echo __('Enter digital number', AAM_KEY); ?>" id="aam-access-threshold" value="<?php echo $params->object->get('limited.threshold'); ?>" />
|
78 |
</div>
|
79 |
<?php if ($params->subject->isUser()) { ?>
|
80 |
+
<?php $counter = intval(get_user_option(sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, $params->object->ID), $params->subject->getId())); ?>
|
81 |
<?php $remaining = $params->object->get('limited.threshold') - $counter; ?>
|
82 |
|
83 |
<div class="form-group">
|
application/Core/API.php
CHANGED
@@ -251,6 +251,7 @@ final class AAM_Core_API
|
|
251 |
self::deleteOption(AAM_Core_AccessSettings::DB_OPTION);
|
252 |
self::deleteOption(AAM_Core_Config::DB_OPTION);
|
253 |
self::deleteOption(AAM_Core_ConfigPress::DB_OPTION);
|
|
|
254 |
|
255 |
// Trigger the action to inform other services to clean-up the options
|
256 |
do_action('aam_clear_settings_action');
|
251 |
self::deleteOption(AAM_Core_AccessSettings::DB_OPTION);
|
252 |
self::deleteOption(AAM_Core_Config::DB_OPTION);
|
253 |
self::deleteOption(AAM_Core_ConfigPress::DB_OPTION);
|
254 |
+
self::deleteOption(AAM_Core_Migration::DB_FAILURE_OPTION);
|
255 |
|
256 |
// Trigger the action to inform other services to clean-up the options
|
257 |
do_action('aam_clear_settings_action');
|
application/Core/Contract/MigrationInterface.php
CHANGED
@@ -20,11 +20,11 @@ interface AAM_Core_Contract_MigrationInterface
|
|
20 |
/**
|
21 |
* Trigger migration script
|
22 |
*
|
23 |
-
* @return
|
24 |
*
|
25 |
* @access public
|
26 |
* @version 6.0.0
|
27 |
*/
|
28 |
-
public
|
29 |
|
30 |
}
|
20 |
/**
|
21 |
* Trigger migration script
|
22 |
*
|
23 |
+
* @return array
|
24 |
*
|
25 |
* @access public
|
26 |
* @version 6.0.0
|
27 |
*/
|
28 |
+
public function run();
|
29 |
|
30 |
}
|
application/Core/Gateway.php
CHANGED
@@ -112,7 +112,7 @@ final class AAM_Core_Gateway
|
|
112 |
}
|
113 |
|
114 |
/**
|
115 |
-
* Get role
|
116 |
*
|
117 |
* @param string $id
|
118 |
*
|
@@ -126,6 +126,38 @@ final class AAM_Core_Gateway
|
|
126 |
return new AAM_Core_Subject_Role($id);
|
127 |
}
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
/**
|
130 |
* Log any critical message
|
131 |
*
|
@@ -140,6 +172,27 @@ final class AAM_Core_Gateway
|
|
140 |
call_user_func_array('AAM_Core_Console::add', func_get_args());
|
141 |
}
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
/**
|
144 |
* Merge two set of access settings into one
|
145 |
*
|
112 |
}
|
113 |
|
114 |
/**
|
115 |
+
* Get role subject
|
116 |
*
|
117 |
* @param string $id
|
118 |
*
|
126 |
return new AAM_Core_Subject_Role($id);
|
127 |
}
|
128 |
|
129 |
+
/**
|
130 |
+
* Get visitor subject
|
131 |
+
*
|
132 |
+
* @return AAM_Core_Subject_Visitor
|
133 |
+
*
|
134 |
+
* @access public
|
135 |
+
* @version 6.0.0
|
136 |
+
*/
|
137 |
+
public function getVisitor()
|
138 |
+
{
|
139 |
+
if (is_user_logged_in()) {
|
140 |
+
$visitor = new AAM_Core_Subject_Visitor();
|
141 |
+
} else {
|
142 |
+
$visitor = AAM::getUser();
|
143 |
+
}
|
144 |
+
|
145 |
+
return $visitor;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Get default subject
|
150 |
+
*
|
151 |
+
* @return AAM_Core_Subject_Default
|
152 |
+
*
|
153 |
+
* @access public
|
154 |
+
* @version 6.0.0
|
155 |
+
*/
|
156 |
+
public function getDefault()
|
157 |
+
{
|
158 |
+
return AAM_Core_Subject_Default::getInstance();
|
159 |
+
}
|
160 |
+
|
161 |
/**
|
162 |
* Log any critical message
|
163 |
*
|
172 |
call_user_func_array('AAM_Core_Console::add', func_get_args());
|
173 |
}
|
174 |
|
175 |
+
/**
|
176 |
+
* Prepare Access Policy manager but only if service is enabled
|
177 |
+
*
|
178 |
+
* @param AAM_Core_Subject $subject
|
179 |
+
*
|
180 |
+
* @return AAM_Core_Policy_Manager|null
|
181 |
+
*
|
182 |
+
* @access public
|
183 |
+
* @version 6.0.0
|
184 |
+
*/
|
185 |
+
public function getAccessPolicyManager(AAM_Core_Subject $subject)
|
186 |
+
{
|
187 |
+
if (AAM_Core_Config::get(AAM_Service_AccessPolicy::FEATURE_FLAG, true)) {
|
188 |
+
$manager = AAM_Core_Policy_Factory::get($subject);
|
189 |
+
} else {
|
190 |
+
$manager = null;
|
191 |
+
}
|
192 |
+
|
193 |
+
return $manager;
|
194 |
+
}
|
195 |
+
|
196 |
/**
|
197 |
* Merge two set of access settings into one
|
198 |
*
|
application/Core/Jwt/Issuer.php
CHANGED
@@ -39,7 +39,9 @@ class AAM_Core_Jwt_Issuer
|
|
39 |
$path = AAM_Core_Config::get('authentication.jwt.publicKeyPath');
|
40 |
$key = (is_readable($path) ? file_get_contents($path) : null);
|
41 |
} else {
|
42 |
-
$key = AAM_Core_Config::get(
|
|
|
|
|
43 |
}
|
44 |
|
45 |
// Step #1. Check if token is actually valid
|
@@ -50,8 +52,11 @@ class AAM_Core_Jwt_Issuer
|
|
50 |
// Step #2. If token is "revocable", make sure that claimed user still has
|
51 |
// the token in the meta
|
52 |
if (!empty($response->revocable)) {
|
53 |
-
$tokens =
|
54 |
-
|
|
|
|
|
|
|
55 |
throw new Exception(__('Token has been revoked', AAM_KEY));
|
56 |
}
|
57 |
}
|
@@ -85,11 +90,14 @@ class AAM_Core_Jwt_Issuer
|
|
85 |
if (is_a($expires, 'DateTime')) {
|
86 |
$time = $expires;
|
87 |
} else {
|
88 |
-
$time = DateTime::createFromFormat(
|
|
|
|
|
89 |
}
|
90 |
} else {
|
91 |
$time = new DateTime(
|
92 |
-
AAM_Core_Config::get('authentication.jwt.expires', '+24 hours')
|
|
|
93 |
);
|
94 |
}
|
95 |
|
@@ -99,7 +107,7 @@ class AAM_Core_Jwt_Issuer
|
|
99 |
array(
|
100 |
"iat" => time(),
|
101 |
'iss' => get_site_url(),
|
102 |
-
'exp' => $time->
|
103 |
'jti' => $this->generateUuid()
|
104 |
),
|
105 |
$args
|
39 |
$path = AAM_Core_Config::get('authentication.jwt.publicKeyPath');
|
40 |
$key = (is_readable($path) ? file_get_contents($path) : null);
|
41 |
} else {
|
42 |
+
$key = AAM_Core_Config::get(
|
43 |
+
'authentication.jwt.secret', SECURE_AUTH_KEY
|
44 |
+
);
|
45 |
}
|
46 |
|
47 |
// Step #1. Check if token is actually valid
|
52 |
// Step #2. If token is "revocable", make sure that claimed user still has
|
53 |
// the token in the meta
|
54 |
if (!empty($response->revocable)) {
|
55 |
+
$tokens = get_user_option(
|
56 |
+
AAM_Service_Jwt::DB_OPTION, $response->userId
|
57 |
+
);
|
58 |
+
|
59 |
+
if (!is_array($tokens) || !in_array($token, $tokens, true)) {
|
60 |
throw new Exception(__('Token has been revoked', AAM_KEY));
|
61 |
}
|
62 |
}
|
90 |
if (is_a($expires, 'DateTime')) {
|
91 |
$time = $expires;
|
92 |
} else {
|
93 |
+
$time = DateTime::createFromFormat(
|
94 |
+
'm/d/Y, H:i O', $expires, new DateTimeZone('UTC')
|
95 |
+
);
|
96 |
}
|
97 |
} else {
|
98 |
$time = new DateTime(
|
99 |
+
AAM_Core_Config::get('authentication.jwt.expires', '+24 hours'),
|
100 |
+
new DateTimeZone('UTC')
|
101 |
);
|
102 |
}
|
103 |
|
107 |
array(
|
108 |
"iat" => time(),
|
109 |
'iss' => get_site_url(),
|
110 |
+
'exp' => $time->getTimestamp(),
|
111 |
'jti' => $this->generateUuid()
|
112 |
),
|
113 |
$args
|
application/Core/Migration.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
* @package AAM
|
16 |
* @version 6.0.0
|
17 |
*/
|
18 |
-
class AAM_Core_Migration
|
19 |
{
|
20 |
|
21 |
/**
|
@@ -26,34 +26,125 @@ class AAM_Core_Migration
|
|
26 |
const DB_OPTION = 'aam_migrations';
|
27 |
|
28 |
/**
|
29 |
-
*
|
30 |
*
|
31 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
*
|
33 |
* @access public
|
34 |
* @version 6.0.0
|
35 |
*/
|
36 |
-
public static function
|
37 |
{
|
38 |
-
$
|
39 |
-
$
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
$migration->isFile()
|
45 |
-
&& !in_array($migration->getFilename(), $executed, true)
|
46 |
-
) {
|
47 |
-
require $migration->getPathname();
|
48 |
-
|
49 |
-
$executed[] = $migration->getFilename();
|
50 |
-
$changed = true;
|
51 |
}
|
52 |
}
|
53 |
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
|
59 |
}
|
15 |
* @package AAM
|
16 |
* @version 6.0.0
|
17 |
*/
|
18 |
+
final class AAM_Core_Migration
|
19 |
{
|
20 |
|
21 |
/**
|
26 |
const DB_OPTION = 'aam_migrations';
|
27 |
|
28 |
/**
|
29 |
+
* DB option that stores the entire migration log
|
30 |
*
|
31 |
+
* @version 6.0.0
|
32 |
+
*/
|
33 |
+
const DB_FAILURE_OPTION = 'aam_migration_failures';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Get list of migrations that are still pending to be executed
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
*
|
40 |
* @access public
|
41 |
* @version 6.0.0
|
42 |
*/
|
43 |
+
public static function getPending()
|
44 |
{
|
45 |
+
$completed = AAM_Core_API::getOption(self::DB_OPTION, array());
|
46 |
+
$pending = array();
|
47 |
+
|
48 |
+
foreach (self::getDirectoryIterator() as $mg) {
|
49 |
+
if ($mg->isFile() && !in_array($mg->getFilename(), $completed, true)) {
|
50 |
+
$pending[] = $mg->getPathname();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
}
|
53 |
|
54 |
+
return $pending;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Store failure log
|
59 |
+
*
|
60 |
+
* @param array $log
|
61 |
+
*
|
62 |
+
* @return boolean
|
63 |
+
*
|
64 |
+
* @access public
|
65 |
+
* @version 6.0.0
|
66 |
+
*/
|
67 |
+
public static function storeFailureLog($log)
|
68 |
+
{
|
69 |
+
return AAM_Core_API::updateOption(self::DB_FAILURE_OPTION, $log);
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Get migration failure log
|
74 |
+
*
|
75 |
+
* @return array
|
76 |
+
*
|
77 |
+
* @access public
|
78 |
+
* @version 6.0.0
|
79 |
+
*/
|
80 |
+
public static function getFailureLog()
|
81 |
+
{
|
82 |
+
return AAM_Core_API::getOption(self::DB_FAILURE_OPTION, array());
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Store completed script
|
87 |
+
*
|
88 |
+
* @param string $file_name
|
89 |
+
*
|
90 |
+
* @return boolean
|
91 |
+
*
|
92 |
+
* @access public
|
93 |
+
* @version 6.0.0
|
94 |
+
*/
|
95 |
+
public static function storeCompletedScript($file_name)
|
96 |
+
{
|
97 |
+
$completed = AAM_Core_API::getOption(self::DB_OPTION, array());
|
98 |
+
$completed[] = $file_name;
|
99 |
+
|
100 |
+
return AAM_Core_API::updateOption(self::DB_OPTION, $completed);
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Execute migration script
|
105 |
+
*
|
106 |
+
* @param string $file_path
|
107 |
+
*
|
108 |
+
* @return array
|
109 |
+
*
|
110 |
+
* @access public
|
111 |
+
* @version 6.0.0
|
112 |
+
*/
|
113 |
+
public static function executeScript($file_path)
|
114 |
+
{
|
115 |
+
if (file_exists($file_path)) {
|
116 |
+
$results = include $file_path;
|
117 |
+
} else {
|
118 |
+
$results = array();
|
119 |
}
|
120 |
+
|
121 |
+
return $results;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Check if there is at least one pending migration script
|
126 |
+
*
|
127 |
+
* @return boolean
|
128 |
+
*
|
129 |
+
* @access public
|
130 |
+
* @version 6.0.0
|
131 |
+
*/
|
132 |
+
public static function hasPending()
|
133 |
+
{
|
134 |
+
return (count(self::getPending()) > 0);
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Get migration scripts directory iterator
|
139 |
+
*
|
140 |
+
* @return DirectoryIterator
|
141 |
+
*
|
142 |
+
* @access protected
|
143 |
+
* @version 6.0.0
|
144 |
+
*/
|
145 |
+
protected static function getDirectoryIterator()
|
146 |
+
{
|
147 |
+
return new DirectoryIterator(dirname(__DIR__) . '/Migration');
|
148 |
}
|
149 |
|
150 |
}
|
application/Core/Migration/2019_06_30-migrate-settings-to-6.0.0.php
DELETED
@@ -1,384 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* This migration class converts all AAM legacy access settings
|
12 |
-
*
|
13 |
-
* The main purpose for this class is to eliminate AAM_Core_Compatibility
|
14 |
-
*
|
15 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
16 |
-
* @version 6.0.0
|
17 |
-
*/
|
18 |
-
class Migration600 implements AAM_Core_Contract_MigrationInterface
|
19 |
-
{
|
20 |
-
const VERSION = '6.0.0';
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @inheritdoc
|
24 |
-
*/
|
25 |
-
public static function run()
|
26 |
-
{
|
27 |
-
// Convert AAM Metaboxes & Widgets settings
|
28 |
-
// Prior to AAM 5.9, Metaboxes & Widgets settings were stored in
|
29 |
-
// multi-dimensional array
|
30 |
-
self::fetchAndConvert(
|
31 |
-
AAM_Core_Object_Metabox::OBJECT_TYPE,
|
32 |
-
'Migration600::_convertMetaboxSettings'
|
33 |
-
);
|
34 |
-
|
35 |
-
// Convert API Routes settings
|
36 |
-
// Prior to AAM 5.9, API Routes settings were stored in multi-dimensional
|
37 |
-
// array
|
38 |
-
self::fetchAndConvert(
|
39 |
-
AAM_Core_Object_Route::OBJECT_TYPE,
|
40 |
-
'Migration600::_convertRouteSettings'
|
41 |
-
);
|
42 |
-
|
43 |
-
// Convert legacy utility options to newer naming convention
|
44 |
-
self::convertConfigOptions();
|
45 |
-
|
46 |
-
// TODO: Covert all 1, '1', 0, '0', "false", "true" to boolean for all
|
47 |
-
// access properties
|
48 |
-
self::convertPostTermOptions();
|
49 |
-
|
50 |
-
// TODO: aam-utilities => aam_config
|
51 |
-
|
52 |
-
// TODO: aam-extensions => aam_addons
|
53 |
-
|
54 |
-
//clear schedules
|
55 |
-
wp_clear_scheduled_hook('aam-cron');
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Fetch access settings and convert them to newer format
|
60 |
-
*
|
61 |
-
* @param string $object
|
62 |
-
*
|
63 |
-
* @return void
|
64 |
-
*
|
65 |
-
* @access protected
|
66 |
-
* @static
|
67 |
-
*/
|
68 |
-
protected static function fetchAndConvert($object, $callback)
|
69 |
-
{
|
70 |
-
global $wpdb;
|
71 |
-
|
72 |
-
// Find all metabox options for Role, Visitor and Default subjects
|
73 |
-
$query = "SELECT * FROM {$wpdb->options} WHERE (`option_name` LIKE %s) OR ";
|
74 |
-
$query .= "(`option_name`LIKE %s)";
|
75 |
-
$wpdb->query($wpdb->prepare($query, "aam_{$object}%", "aam_visitor_{$object}"));
|
76 |
-
|
77 |
-
foreach ($wpdb->last_result as $row) {
|
78 |
-
$settings = maybe_unserialize($row->option_value);
|
79 |
-
AAM_Core_API::updateOption(
|
80 |
-
$row->option_key,
|
81 |
-
call_user_func($callback, $settings)
|
82 |
-
);
|
83 |
-
}
|
84 |
-
|
85 |
-
// Find all metabox options for User subjects
|
86 |
-
$query = "SELECT * FROM {$wpdb->user_meta} WHERE (`meta_key` LIKE %s)";
|
87 |
-
$wpdb->query($wpdb->prepare($query, "aam_{$object}%"));
|
88 |
-
|
89 |
-
foreach ($wpdb->last_result as $row) {
|
90 |
-
$settings = maybe_unserialize($row->meta_value);
|
91 |
-
update_user_meta(
|
92 |
-
$row->user_id,
|
93 |
-
$row->meta_key,
|
94 |
-
call_user_func($callback, $settings)
|
95 |
-
);
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Convert config
|
101 |
-
*
|
102 |
-
* @return void
|
103 |
-
*
|
104 |
-
* @access protected
|
105 |
-
*/
|
106 |
-
protected static function convertConfigOptions()
|
107 |
-
{
|
108 |
-
$config = AAM_Core_API::getOption('aam-utilities', array(), 'site');
|
109 |
-
|
110 |
-
foreach (array_keys((is_array($config) ? $config : array())) as $option) {
|
111 |
-
if (strpos($option, 'frontend.redirect') !== false) {
|
112 |
-
self::_convertConfigOption('redirect', $config, $option);
|
113 |
-
} elseif (strpos($option, 'backend.redirect') !== false) {
|
114 |
-
self::_convertConfigOption('redirect', $config, $option);
|
115 |
-
} elseif (strpos($option, 'login.redirect') !== false) {
|
116 |
-
self::_convertConfigOption('loginRedirect', $config, $option);
|
117 |
-
} elseif (strpos($option, 'frontend.teaser') !== false) {
|
118 |
-
self::_convertConfigOption('teaser', $config, $option);
|
119 |
-
}
|
120 |
-
}
|
121 |
-
|
122 |
-
self::_normalizeConfigOptions($config);
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
*
|
127 |
-
* @return void
|
128 |
-
*/
|
129 |
-
protected static function convertPostTermOptions()
|
130 |
-
{
|
131 |
-
global $wpdb;
|
132 |
-
|
133 |
-
// Read all posts access settings and convert them to new format
|
134 |
-
$query = "SELECT * FROM {$wpdb->postmeta} WHERE (`meta_key` LIKE %s)";
|
135 |
-
$wpdb->query($wpdb->prepare($query, "aam-post-access-%"));
|
136 |
-
|
137 |
-
foreach ($wpdb->last_result as $row) {
|
138 |
-
$options = array();
|
139 |
-
$legacy = maybe_unserialize($row->meta_value);
|
140 |
-
|
141 |
-
foreach($legacy as $key => $value) {
|
142 |
-
$k = preg_replace('^(frontend|backend|api)\.', '', $key);
|
143 |
-
|
144 |
-
if ($k === 'list') {
|
145 |
-
$options['hidden'] = self::_isTrue($value);
|
146 |
-
} elseif ($k === 'read') {
|
147 |
-
$options['restricted'] = self::_isTrue($value);
|
148 |
-
} elseif ($k === 'limit') {
|
149 |
-
$options['teaser'] = array(
|
150 |
-
'enabled' => self::_isTrue($value),
|
151 |
-
'message' => (!empty($legacy['teaser']) ? $legacy['teaser'] : '')
|
152 |
-
);
|
153 |
-
} elseif ($k === 'access_counter') {
|
154 |
-
$options['limited'] = array(
|
155 |
-
'enabled' => self::_isTrue($value),
|
156 |
-
'threshold' => (!empty($legacy['access_counter_limit']) ? $legacy['access_counter_limit'] : 0)
|
157 |
-
);
|
158 |
-
} elseif (in_array($k, array('comment', 'edit', 'delete', 'publish'), true)) {
|
159 |
-
$options[$k] = self::_isTrue($value);
|
160 |
-
} elseif ($k === 'redirect') {
|
161 |
-
$chunks = explode('|', $legacy['location']);
|
162 |
-
|
163 |
-
if (count($chunks) === 3) {
|
164 |
-
$options['redirected'] = array(
|
165 |
-
'enabled' => self::_isTrue($value),
|
166 |
-
'type' => $chunks[0],
|
167 |
-
'destination' => $chunks[1],
|
168 |
-
'httpCode' => $chunks[2]
|
169 |
-
);
|
170 |
-
} else {
|
171 |
-
$destination = $chunks[0];
|
172 |
-
|
173 |
-
if (is_numeric($chunks[0])) {
|
174 |
-
$type = 'page';
|
175 |
-
} elseif (filter_var($chunks[0], FILTER_VALIDATE_URL)) {
|
176 |
-
$type = 'url';
|
177 |
-
} elseif (is_callable($chunks[0])) {
|
178 |
-
$type = 'callback';
|
179 |
-
} else {
|
180 |
-
$type = 'login';
|
181 |
-
$destination = null;
|
182 |
-
}
|
183 |
-
|
184 |
-
$options['redirected'] = array(
|
185 |
-
'enabled' => self::_isTrue($value),
|
186 |
-
'type' => $type,
|
187 |
-
'destination' => $destination,
|
188 |
-
'httpCode' => 307 // Default (Temporary Redirect)
|
189 |
-
);
|
190 |
-
}
|
191 |
-
} elseif ($k === 'protected') {
|
192 |
-
$options['protected'] = array(
|
193 |
-
'enabled' => self::_isTrue($value),
|
194 |
-
'password' => $legacy['password']
|
195 |
-
);
|
196 |
-
} elseif ($k === 'expire') {
|
197 |
-
$options['ceased'] = array(
|
198 |
-
'enabled' => self::_isTrue($value),
|
199 |
-
'after' => $legacy['expire_datetime']
|
200 |
-
);
|
201 |
-
} else {
|
202 |
-
// TODO: Implement conversion for Plus Package, E-commerce plugins
|
203 |
-
$options = apply_filters(
|
204 |
-
'aam_posts_terms_migration_filter',
|
205 |
-
$options,
|
206 |
-
$key,
|
207 |
-
$value,
|
208 |
-
self
|
209 |
-
);
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
-
$post = get_post($row->post_id);
|
214 |
-
// Very specific WP case. According to the WP core, you are not allowed to
|
215 |
-
// set meta for revision, so let's bypass this constrain.
|
216 |
-
if ($post->post_type === 'revision') {
|
217 |
-
update_metadata('post', $post->ID, $row->meta_key, $options);
|
218 |
-
} else {
|
219 |
-
update_post_meta($post->ID, $row->meta_key, $options);
|
220 |
-
}
|
221 |
-
}
|
222 |
-
}
|
223 |
-
|
224 |
-
private static function _isTrue($value)
|
225 |
-
{
|
226 |
-
return in_array($value, array(1, '1', 'true'), true);
|
227 |
-
}
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Convert single option to Default subject settings
|
231 |
-
*
|
232 |
-
* @param string $oid
|
233 |
-
* @param array &$config
|
234 |
-
* @param string $option
|
235 |
-
*
|
236 |
-
* @return void
|
237 |
-
*
|
238 |
-
* @access private
|
239 |
-
* @static
|
240 |
-
*/
|
241 |
-
private static function _convertConfigOption($oid, &$config, $option)
|
242 |
-
{
|
243 |
-
static $subject = null;
|
244 |
-
|
245 |
-
if (is_null($subject)) {
|
246 |
-
$subject = new AAM_Core_Subject_Default;
|
247 |
-
}
|
248 |
-
|
249 |
-
$object = $subject->getObject($oid);
|
250 |
-
|
251 |
-
if (is_a($object, 'AAM_Core_Subject')) {
|
252 |
-
$object->save($option, $config[$option]);
|
253 |
-
unset($config[$option]);
|
254 |
-
AAM_Core_API::updateOption('aam-utilities', $config);
|
255 |
-
}
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Convert old-style AAM settings to standard ConfigPress style settings
|
260 |
-
*
|
261 |
-
* @param array $config
|
262 |
-
*
|
263 |
-
* @return array
|
264 |
-
*/
|
265 |
-
private static function _normalizeConfigOptions($config)
|
266 |
-
{
|
267 |
-
if (is_array($config)) {
|
268 |
-
$changes = 0;
|
269 |
-
$changes += self::_normalizeOption('manage-capability', 'core.settings.editCapabilities', $config);
|
270 |
-
$changes += self::_normalizeOption('render-access-metabox', 'ui.settings.renderAccessMetabox', $config);
|
271 |
-
$changes += self::_normalizeOption('core.xmlrpc', 'core.settings.xmlrpc', $config);
|
272 |
-
$changes += self::_normalizeOption('core.restful', 'core.settings.restful', $config);
|
273 |
-
$changes += self::_normalizeOption('ms-member-access', 'core.settings.multisiteMemberAccessControl', $config);
|
274 |
-
$changes += self::_normalizeOption('media-access-control', 'core.settings.mediaAccessControl', $config);
|
275 |
-
$changes += self::_normalizeOption('page-category', 'core.settings.pageCategory', $config);
|
276 |
-
$changes += self::_normalizeOption('media-category', 'core.settings.mediaCategory', $config);
|
277 |
-
$changes += self::_normalizeOption('multi-category', 'core.settings.multiCategory', $config);
|
278 |
-
$changes += self::_normalizeOption('login-timeout', 'core.settings.loginDelay', $config);
|
279 |
-
$changes += self::_normalizeOption('single-session', 'core.settings.singleSession', $config);
|
280 |
-
$changes += self::_normalizeOption('brute-force-lockout', 'core.settings.bruteForceLockout', $config);
|
281 |
-
$changes += self::_normalizeOption('inherit-parent-post', 'core.settings.inheritParentPost', $config);
|
282 |
-
|
283 |
-
if ($changes > 0) {
|
284 |
-
if (is_multisite()) {
|
285 |
-
AAM_Core_API::updateOption('aam-utilities', $config, 'site');
|
286 |
-
} else {
|
287 |
-
AAM_Core_API::updateOption('aam-utilities', $config);
|
288 |
-
}
|
289 |
-
}
|
290 |
-
}
|
291 |
-
|
292 |
-
return $config;
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* Normalize/Convert single Utility option to newer format
|
297 |
-
*
|
298 |
-
* @param string $option
|
299 |
-
* @param string $normalizedName
|
300 |
-
* @param array &$config
|
301 |
-
*
|
302 |
-
* @return int
|
303 |
-
*
|
304 |
-
* @access private
|
305 |
-
* @static
|
306 |
-
*/
|
307 |
-
private static function _normalizeOption($option, $normalizedName, &$config)
|
308 |
-
{
|
309 |
-
$changed = 0;
|
310 |
-
|
311 |
-
if (array_key_exists($option, $config)) {
|
312 |
-
$value = $config[$option];
|
313 |
-
unset($config[$option]);
|
314 |
-
$config[$normalizedName] = $value;
|
315 |
-
$changed = 1;
|
316 |
-
}
|
317 |
-
|
318 |
-
return $changed;
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Convert Metabox & Widget access settings to key/value pair
|
323 |
-
*
|
324 |
-
* @param array $settings
|
325 |
-
*
|
326 |
-
* @return array
|
327 |
-
*
|
328 |
-
* @access private
|
329 |
-
* @static
|
330 |
-
*/
|
331 |
-
private static function _convertMetaboxSettings($settings)
|
332 |
-
{
|
333 |
-
$converted = array();
|
334 |
-
|
335 |
-
if (is_array($settings)) {
|
336 |
-
foreach ($settings as $key => $value) {
|
337 |
-
if (is_array($value)) {
|
338 |
-
foreach ($value as $id => $grand) {
|
339 |
-
$converted["{$key}|{$id}"] = $grand;
|
340 |
-
}
|
341 |
-
} else {
|
342 |
-
$converted[$key] = $value;
|
343 |
-
}
|
344 |
-
}
|
345 |
-
}
|
346 |
-
|
347 |
-
return $converted;
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* Convert API Route settings
|
352 |
-
*
|
353 |
-
* @param array $list
|
354 |
-
*
|
355 |
-
* @return array
|
356 |
-
*
|
357 |
-
* @access private
|
358 |
-
* @static
|
359 |
-
*/
|
360 |
-
private static function _convertRouteSettings($settings)
|
361 |
-
{
|
362 |
-
$converted = array();
|
363 |
-
|
364 |
-
if (is_array($settings)) {
|
365 |
-
foreach ($settings as $type => $routes) {
|
366 |
-
if (is_array($routes)) {
|
367 |
-
foreach ($routes as $route => $methods) {
|
368 |
-
foreach ($methods as $method => $grand) {
|
369 |
-
$converted[strtolower("{$type}|{$route}|{$method}")] = $grand;
|
370 |
-
}
|
371 |
-
}
|
372 |
-
} else {
|
373 |
-
$converted[$type] = $routes;
|
374 |
-
}
|
375 |
-
}
|
376 |
-
}
|
377 |
-
|
378 |
-
return $converted;
|
379 |
-
}
|
380 |
-
}
|
381 |
-
|
382 |
-
if (defined('AAM_KEY')) {
|
383 |
-
Migration600::run();
|
384 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Core/Object.php
CHANGED
@@ -206,7 +206,7 @@ abstract class AAM_Core_Object
|
|
206 |
*
|
207 |
* @param array $option
|
208 |
*
|
209 |
-
* @return
|
210 |
*
|
211 |
* @access public
|
212 |
* @version 6.0.0
|
@@ -214,6 +214,8 @@ abstract class AAM_Core_Object
|
|
214 |
public function setOption(array $option)
|
215 |
{
|
216 |
$this->_option = $option;
|
|
|
|
|
217 |
}
|
218 |
|
219 |
/**
|
@@ -320,6 +322,16 @@ abstract class AAM_Core_Object
|
|
320 |
$this->_explicitOption = $option;
|
321 |
}
|
322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
public function isExplicit($property)
|
324 |
{
|
325 |
$option = $this->_explicitOption;
|
206 |
*
|
207 |
* @param array $option
|
208 |
*
|
209 |
+
* @return AAM_Core_Object
|
210 |
*
|
211 |
* @access public
|
212 |
* @version 6.0.0
|
214 |
public function setOption(array $option)
|
215 |
{
|
216 |
$this->_option = $option;
|
217 |
+
|
218 |
+
return $this;
|
219 |
}
|
220 |
|
221 |
/**
|
322 |
$this->_explicitOption = $option;
|
323 |
}
|
324 |
|
325 |
+
/**
|
326 |
+
* Determine if access settings are set explicitly for current subject
|
327 |
+
*
|
328 |
+
* @param string $property
|
329 |
+
*
|
330 |
+
* @return boolean
|
331 |
+
*
|
332 |
+
* @access public
|
333 |
+
* @version 6.0.0
|
334 |
+
*/
|
335 |
public function isExplicit($property)
|
336 |
{
|
337 |
$option = $this->_explicitOption;
|
application/Core/Object/Menu.php
CHANGED
@@ -69,7 +69,6 @@ class AAM_Core_Object_Menu extends AAM_Core_Object
|
|
69 |
// Step #3. Check if dynamic submenu is restricted because of whole branch
|
70 |
$indirect = ($parent && (!empty($options['menu-' . $parent])));
|
71 |
|
72 |
-
// TODO: Implement crc32 in the Access Policy service
|
73 |
return apply_filters(
|
74 |
'aam_admin_menu_is_restricted_filter',
|
75 |
$direct || $branch || $indirect,
|
69 |
// Step #3. Check if dynamic submenu is restricted because of whole branch
|
70 |
$indirect = ($parent && (!empty($options['menu-' . $parent])));
|
71 |
|
|
|
72 |
return apply_filters(
|
73 |
'aam_admin_menu_is_restricted_filter',
|
74 |
$direct || $branch || $indirect,
|
application/Core/Object/Route.php
CHANGED
@@ -38,9 +38,7 @@ class AAM_Core_Object_Route extends AAM_Core_Object
|
|
38 |
// Trigger custom functionality that may populate the menu options. For
|
39 |
// example, this hooks is used by Access Policy service
|
40 |
if (empty($option)) {
|
41 |
-
$option = apply_filters(
|
42 |
-
'aam_route_object_option_filter', $option, $this->getSubject()
|
43 |
-
);
|
44 |
}
|
45 |
|
46 |
$this->setOption(is_array($option) ? $option : array());
|
38 |
// Trigger custom functionality that may populate the menu options. For
|
39 |
// example, this hooks is used by Access Policy service
|
40 |
if (empty($option)) {
|
41 |
+
$option = apply_filters('aam_route_object_option_filter', $option, $this);
|
|
|
|
|
42 |
}
|
43 |
|
44 |
$this->setOption(is_array($option) ? $option : array());
|
application/Core/Policy/Resource.php
CHANGED
@@ -79,4 +79,11 @@ class AAM_Core_Policy_Resource
|
|
79 |
*/
|
80 |
const PLUGIN = 'Plugin';
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
79 |
*/
|
80 |
const PLUGIN = 'Plugin';
|
81 |
|
82 |
+
/**
|
83 |
+
* API Route resource
|
84 |
+
*
|
85 |
+
* @version 6.0.0
|
86 |
+
*/
|
87 |
+
const ROUTE = 'Route';
|
88 |
+
|
89 |
}
|
application/Core/Policy/Token.php
CHANGED
@@ -28,6 +28,7 @@ class AAM_Core_Policy_Token
|
|
28 |
*/
|
29 |
protected static $map = array(
|
30 |
'USER' => 'AAM_Core_Policy_Token::getUserValue',
|
|
|
31 |
'USER_META' => 'AAM_Core_Policy_Token::getUserMetaValue',
|
32 |
'DATETIME' => 'date',
|
33 |
'HTTP_GET' => 'AAM_Core_Request::get',
|
@@ -142,6 +143,28 @@ class AAM_Core_Policy_Token
|
|
142 |
return $value;
|
143 |
}
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
/**
|
146 |
* Get user meta value(s)
|
147 |
*
|
28 |
*/
|
29 |
protected static $map = array(
|
30 |
'USER' => 'AAM_Core_Policy_Token::getUserValue',
|
31 |
+
'USER_OPTION' => 'AAM_Core_Policy_Token::getUserOptionValue',
|
32 |
'USER_META' => 'AAM_Core_Policy_Token::getUserMetaValue',
|
33 |
'DATETIME' => 'date',
|
34 |
'HTTP_GET' => 'AAM_Core_Request::get',
|
143 |
return $value;
|
144 |
}
|
145 |
|
146 |
+
/**
|
147 |
+
* Get user option value(s)
|
148 |
+
*
|
149 |
+
* @param string $option_name
|
150 |
+
*
|
151 |
+
* @return void
|
152 |
+
*
|
153 |
+
* @access protected
|
154 |
+
* @version 6.0.0
|
155 |
+
*/
|
156 |
+
protected static function getUserOptionValue($option_name)
|
157 |
+
{
|
158 |
+
$value = null;
|
159 |
+
$id = get_current_user_id();
|
160 |
+
|
161 |
+
if (!empty($id)) { // Only authenticated users have some sort of meta
|
162 |
+
$value = get_user_option($option_name, $id);
|
163 |
+
}
|
164 |
+
|
165 |
+
return $value;
|
166 |
+
}
|
167 |
+
|
168 |
/**
|
169 |
* Get user meta value(s)
|
170 |
*
|
application/Core/Subject/User.php
CHANGED
@@ -292,7 +292,11 @@ class AAM_Core_Subject_User extends AAM_Core_Subject
|
|
292 |
*/
|
293 |
public function setUserExpiration($settings)
|
294 |
{
|
295 |
-
|
|
|
|
|
|
|
|
|
296 |
$this->getId(), self::EXPIRATION_OPTION, $settings
|
297 |
) !== false;
|
298 |
}
|
@@ -307,23 +311,11 @@ class AAM_Core_Subject_User extends AAM_Core_Subject
|
|
307 |
*/
|
308 |
public function getUserExpiration()
|
309 |
{
|
310 |
-
$response =
|
311 |
-
$meta = get_user_meta($this->getId(), self::EXPIRATION_OPTION, true);
|
312 |
-
|
313 |
-
if (!empty($meta)) {
|
314 |
-
$parts = explode('|', $meta);
|
315 |
-
|
316 |
-
// TODO: Remove in Jan 2020
|
317 |
-
if (preg_match('/^[\d]{4}-/', $parts[0])) {
|
318 |
-
$expires = DateTime::createFromFormat('Y-m-d H:i:s', $parts[0]);
|
319 |
-
} else {
|
320 |
-
$expires = DateTime::createFromFormat('m/d/Y, H:i O', $parts[0]);
|
321 |
-
}
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
'
|
326 |
-
'meta' => (isset($parts[2]) ? $parts[2] : null)
|
327 |
);
|
328 |
}
|
329 |
|
@@ -340,7 +332,7 @@ class AAM_Core_Subject_User extends AAM_Core_Subject
|
|
340 |
*/
|
341 |
public function resetUserExpiration()
|
342 |
{
|
343 |
-
return
|
344 |
}
|
345 |
|
346 |
/**
|
@@ -357,12 +349,7 @@ class AAM_Core_Subject_User extends AAM_Core_Subject
|
|
357 |
$expiration = $this->getUserExpiration();
|
358 |
|
359 |
if (!empty($expiration)) {
|
360 |
-
$compare = new DateTime();
|
361 |
-
$timezone = $expiration['expires']->getTimezone();
|
362 |
-
|
363 |
-
if (is_a($timezone, 'DateTimeZone')) {
|
364 |
-
$compare->setTimezone($timezone);
|
365 |
-
}
|
366 |
|
367 |
if ($expiration['expires']->getTimestamp() <= $compare->getTimestamp()) {
|
368 |
$status = $expiration;
|
292 |
*/
|
293 |
public function setUserExpiration($settings)
|
294 |
{
|
295 |
+
if (array_key_exists('action', $settings) === false) {
|
296 |
+
$settings['action'] = 'logout';
|
297 |
+
}
|
298 |
+
|
299 |
+
return update_user_option(
|
300 |
$this->getId(), self::EXPIRATION_OPTION, $settings
|
301 |
) !== false;
|
302 |
}
|
311 |
*/
|
312 |
public function getUserExpiration()
|
313 |
{
|
314 |
+
$response = get_user_option(self::EXPIRATION_OPTION, $this->getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
+
if (!empty($response)) {
|
317 |
+
$response['expires'] = new DateTime(
|
318 |
+
'@' . $response['expires'], new DateTimeZone('UTC')
|
|
|
319 |
);
|
320 |
}
|
321 |
|
332 |
*/
|
333 |
public function resetUserExpiration()
|
334 |
{
|
335 |
+
return delete_user_option($this->getId(), self::EXPIRATION_OPTION);
|
336 |
}
|
337 |
|
338 |
/**
|
349 |
$expiration = $this->getUserExpiration();
|
350 |
|
351 |
if (!empty($expiration)) {
|
352 |
+
$compare = new DateTime('now', new DateTimeZone('UTC'));
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
if ($expiration['expires']->getTimestamp() <= $compare->getTimestamp()) {
|
355 |
$status = $expiration;
|
application/Migration/2019_06_30-base.php
ADDED
@@ -0,0 +1,916 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ======================================================================
|
5 |
+
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
+
* file 'license.txt', which is part of this source code package. *
|
7 |
+
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace AAM\Migration;
|
13 |
+
|
14 |
+
use WP_Error,
|
15 |
+
AAM_Core_API,
|
16 |
+
AAM_Core_Config,
|
17 |
+
AAM_Core_Migration,
|
18 |
+
AAM_Core_ConfigPress,
|
19 |
+
AAM_Addon_Repository,
|
20 |
+
AAM_Core_AccessSettings,
|
21 |
+
AAM_Backend_Feature_Settings_Core,
|
22 |
+
AAM_Core_Contract_MigrationInterface,
|
23 |
+
AAM_Backend_Feature_Settings_Content,
|
24 |
+
AAM_Backend_Feature_Settings_Security;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* This migration class converts all AAM legacy access settings
|
28 |
+
*
|
29 |
+
* The main purpose for this class is to eliminate AAM_Core_Compatibility
|
30 |
+
*
|
31 |
+
* @package AAM
|
32 |
+
* @version 6.0.0
|
33 |
+
*/
|
34 |
+
class Migration600 implements AAM_Core_Contract_MigrationInterface
|
35 |
+
{
|
36 |
+
/**
|
37 |
+
* Migration script version
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
+
*/
|
41 |
+
const VERSION = '6.0.0';
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Migration callbacks
|
45 |
+
*
|
46 |
+
* @var array
|
47 |
+
*
|
48 |
+
* @access protected
|
49 |
+
* @version 6.0.0
|
50 |
+
*/
|
51 |
+
protected $migrationCallbacks = array();
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Constructor
|
55 |
+
*
|
56 |
+
* @return void
|
57 |
+
*
|
58 |
+
* @access public
|
59 |
+
* @version 6.0.0
|
60 |
+
*/
|
61 |
+
public function __construct()
|
62 |
+
{
|
63 |
+
$this->migrationCallbacks = array(
|
64 |
+
'menu' => array($this, '_convertMenuOptions'),
|
65 |
+
'metabox' => array($this, '_convertMetaboxOptions'),
|
66 |
+
'toolbar' => array($this, '_convertFlatOptions'),
|
67 |
+
'route' => array($this, '_convertFlatOptions'),
|
68 |
+
'uri' => array($this, '_convertUriOptions'),
|
69 |
+
'redirect' => array($this, '_convertAsIs'),
|
70 |
+
'loginredirect' => array($this, '_convertAsIs'),
|
71 |
+
'logoutredirect' => array($this, '_convertAsIs'),
|
72 |
+
'policy' => array($this, '_convertAsIs'),
|
73 |
+
// Plus Package related object
|
74 |
+
'term' => array($this, '_convertTermOptions'),
|
75 |
+
'type' => array($this, '_convertTypeOptions'),
|
76 |
+
'taxonomy' => array($this, '_convertTaxonomyOptions'),
|
77 |
+
// IP Check related object
|
78 |
+
'ipCheck' => array($this, '_convertIPCheckOptions')
|
79 |
+
);
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @inheritdoc
|
84 |
+
*
|
85 |
+
* @version 6.0.0
|
86 |
+
*/
|
87 |
+
public function run()
|
88 |
+
{
|
89 |
+
// Fetch the list of all the access settings that are going to be converted
|
90 |
+
// Prior to AAM v6, access settings were distributed between following db
|
91 |
+
// tables: wp_options, wp_usermeta, wp_postmeta
|
92 |
+
$settings = $this->fetchAccessSettings();
|
93 |
+
|
94 |
+
// Iterate over each group of settings and convert them to AAM v6 format
|
95 |
+
$results = array(
|
96 |
+
'errors' => array(),
|
97 |
+
'dump' => $settings
|
98 |
+
);
|
99 |
+
|
100 |
+
foreach($settings as $group => $collection) {
|
101 |
+
if ($group === 'options') {
|
102 |
+
$results['errors'] = array_merge(
|
103 |
+
$results['errors'], $this->processOptions($collection)
|
104 |
+
);
|
105 |
+
} elseif ($group === 'usermeta') {
|
106 |
+
$results['errors'] = array_merge(
|
107 |
+
$results['errors'], $this->processUsermeta($collection)
|
108 |
+
);
|
109 |
+
} elseif ($group === 'postmeta') {
|
110 |
+
$results['errors'] = array_merge(
|
111 |
+
$results['errors'], $this->processPostmeta($collection)
|
112 |
+
);
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
// Save access settings
|
117 |
+
AAM_Core_AccessSettings::getInstance()->save();
|
118 |
+
|
119 |
+
// Clear Scheduled legacy AAM task
|
120 |
+
wp_clear_scheduled_hook('aam-cron');
|
121 |
+
|
122 |
+
// Finally store this script as completed
|
123 |
+
AAM_Core_Migration::storeCompletedScript(basename(__FILE__));
|
124 |
+
|
125 |
+
return $results;
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Fetch all access settings from the DB
|
130 |
+
*
|
131 |
+
* @return array
|
132 |
+
*
|
133 |
+
* @access protected
|
134 |
+
* @version 6.0.0
|
135 |
+
*/
|
136 |
+
protected function fetchAccessSettings()
|
137 |
+
{
|
138 |
+
global $wpdb;
|
139 |
+
|
140 |
+
$response = array();
|
141 |
+
|
142 |
+
// Fetch access settings from the wp_options table
|
143 |
+
$opt_query = "SELECT * FROM {$wpdb->options} WHERE (`option_name` LIKE %s) ";
|
144 |
+
$opt_query .= "OR (`option_name` = %s)";
|
145 |
+
$wpdb->query($wpdb->prepare($opt_query, array('aam_%', 'aam-%')));
|
146 |
+
|
147 |
+
$response['options'] = $wpdb->last_result;
|
148 |
+
|
149 |
+
// Fetch access settings from the wp_usermeta table
|
150 |
+
$query = "SELECT * FROM {$wpdb->usermeta} WHERE (`meta_key` LIKE %s) ";
|
151 |
+
$query .= "OR (`meta_key` LIKE %s)";
|
152 |
+
$wpdb->query($wpdb->prepare($query, array("{$wpdb->prefix}aam_%", 'aam-%')));
|
153 |
+
|
154 |
+
$response['usermeta'] = $wpdb->last_result;
|
155 |
+
|
156 |
+
// Fetch access settings from the wp_postmeta table
|
157 |
+
$query = "SELECT * FROM {$wpdb->postmeta} WHERE (`meta_key` LIKE %s)";
|
158 |
+
$wpdb->query($wpdb->prepare($query, array('aam-post-access-%')));
|
159 |
+
|
160 |
+
$response['postmeta'] = $wpdb->last_result;
|
161 |
+
|
162 |
+
return $response;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Process settings fetched from the _options DB table
|
167 |
+
*
|
168 |
+
* @param array $options
|
169 |
+
*
|
170 |
+
* @return array
|
171 |
+
*
|
172 |
+
* @access protected
|
173 |
+
* @version 6.0.0
|
174 |
+
*/
|
175 |
+
protected function processOptions($options)
|
176 |
+
{
|
177 |
+
$results = array();
|
178 |
+
|
179 |
+
foreach($options as $option) {
|
180 |
+
switch($option->option_name) {
|
181 |
+
case 'aam-configpress':
|
182 |
+
$result = $this->_convertConfigPress($option);
|
183 |
+
break;
|
184 |
+
|
185 |
+
case 'aam-extensions':
|
186 |
+
$result = $this->_convertExtensionRegistry($option);
|
187 |
+
break;
|
188 |
+
|
189 |
+
case 'aam-utilities':
|
190 |
+
$result = $this->_convertSettings($option);
|
191 |
+
break;
|
192 |
+
|
193 |
+
case 'aam_metabox_cache':
|
194 |
+
case 'aam_menu_cache':
|
195 |
+
case 'aam_toolbar_cache':
|
196 |
+
case 'aam-check':
|
197 |
+
case 'aam-uid':
|
198 |
+
// Skip this one and just delete
|
199 |
+
AAM_Core_API::deleteOption($option->option_name);
|
200 |
+
break;
|
201 |
+
|
202 |
+
default:
|
203 |
+
$result = $this->_parseObjectOption($option);
|
204 |
+
break;
|
205 |
+
}
|
206 |
+
|
207 |
+
if ($result !== true) {
|
208 |
+
$results[] = $result;
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
return $results;
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Convert postmeta options
|
217 |
+
*
|
218 |
+
* @param object $options
|
219 |
+
*
|
220 |
+
* @return array
|
221 |
+
*
|
222 |
+
* @access protected
|
223 |
+
* @version 6.0.0
|
224 |
+
*/
|
225 |
+
protected function processPostmeta($options)
|
226 |
+
{
|
227 |
+
$results = array();
|
228 |
+
|
229 |
+
foreach($options as $option) {
|
230 |
+
$name = str_replace('aam-post-access-', '', $option->meta_key);
|
231 |
+
$value = $this->_convertPostObject(maybe_unserialize($option->meta_value));
|
232 |
+
|
233 |
+
if (strpos($name, 'user') === 0) {
|
234 |
+
$xpath = 'user.' . substr($name, 4) . '.post.' . $option->post_id;
|
235 |
+
} elseif (strpos($name, 'role') === 0) {
|
236 |
+
$xpath = 'role.' . substr($name, 4) . '.post.' . $option->post_id;
|
237 |
+
} elseif (in_array($name, array('visitor', 'default'), true)) {
|
238 |
+
$xpath = $name . '.post.' . $option->post_id;
|
239 |
+
} else {
|
240 |
+
$xpath = null;
|
241 |
+
}
|
242 |
+
|
243 |
+
if (!is_null($xpath)) {
|
244 |
+
AAM_Core_AccessSettings::getInstance()->set($xpath, $value);
|
245 |
+
|
246 |
+
// Delete legacy option
|
247 |
+
delete_post_meta($option->post_id, $option->meta_key);
|
248 |
+
} else {
|
249 |
+
$results[] = new WP_Error(
|
250 |
+
'migration_error',
|
251 |
+
sprintf('Failed to convert post "%d" options', $option->post_id),
|
252 |
+
$option
|
253 |
+
);
|
254 |
+
}
|
255 |
+
}
|
256 |
+
|
257 |
+
return $results;
|
258 |
+
}
|
259 |
+
|
260 |
+
/**
|
261 |
+
* Convert usermeta options
|
262 |
+
*
|
263 |
+
* @param object $options
|
264 |
+
*
|
265 |
+
* @return array
|
266 |
+
*
|
267 |
+
* @access protected
|
268 |
+
* @version 6.0.0
|
269 |
+
*/
|
270 |
+
protected function processUsermeta($options)
|
271 |
+
{
|
272 |
+
global $wpdb;
|
273 |
+
|
274 |
+
$results = array();
|
275 |
+
|
276 |
+
foreach($options as $option) {
|
277 |
+
// e.g. "wp_aam_type_post", "wp_aam_term_1|category"
|
278 |
+
$regex = '/^' . $wpdb->prefix . 'aam_([a-z]+)_?([a-z0-9_\-\|]*)$/i';
|
279 |
+
|
280 |
+
// Let's parse the option name and determine object & subject
|
281 |
+
if (preg_match($regex, $option->meta_key, $match)) {
|
282 |
+
// (
|
283 |
+
// [0] => wp_aam_term_1|category
|
284 |
+
// [1] => term
|
285 |
+
// [2] => 1|category
|
286 |
+
// )
|
287 |
+
if (isset($this->migrationCallbacks[$match[1]])) {
|
288 |
+
// Convert options
|
289 |
+
$options = call_user_func(
|
290 |
+
$this->migrationCallbacks[$match[1]],
|
291 |
+
maybe_unserialize($option->meta_value),
|
292 |
+
$match[1]
|
293 |
+
);
|
294 |
+
|
295 |
+
$xpath = 'user.' . $option->user_id;
|
296 |
+
|
297 |
+
if ($match[1] === 'taxonomy') {
|
298 |
+
$xpath .= '.system.defaultTerm.';
|
299 |
+
$xpath .= str_replace('|', '.', $match[2]);
|
300 |
+
} else {
|
301 |
+
$xpath .= ".{$match[1]}";
|
302 |
+
$xpath .= (empty($match[2]) ? '' : ".{$match[2]}");
|
303 |
+
}
|
304 |
+
|
305 |
+
AAM_Core_AccessSettings::getInstance()->set($xpath, $options);
|
306 |
+
|
307 |
+
// Delete legacy meta
|
308 |
+
delete_user_meta($option->user_id, $option->meta_key);
|
309 |
+
} else {
|
310 |
+
$results[] = new WP_Error(
|
311 |
+
'migration_error',
|
312 |
+
sprintf('Unrecognized object type "%s"', $match[1]),
|
313 |
+
$option
|
314 |
+
);
|
315 |
+
}
|
316 |
+
}elseif ($option->meta_key === 'aam-jwt') {
|
317 |
+
// Just delete it. AAM v5 JWT tokens are no longer valid due to the
|
318 |
+
// new way to calculate exp property
|
319 |
+
delete_user_meta($option->user_id, $option->meta_key);
|
320 |
+
} else {
|
321 |
+
$results[] = new WP_Error(
|
322 |
+
'migration_error',
|
323 |
+
sprintf('Failed to parse access option %s', $option->meta_key),
|
324 |
+
$option
|
325 |
+
);
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
return $results;
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Convert ConfigPress options
|
334 |
+
*
|
335 |
+
* @param object $option
|
336 |
+
*
|
337 |
+
* @return array|WP_Error
|
338 |
+
*
|
339 |
+
* @access private
|
340 |
+
* @version 6.0.0
|
341 |
+
*/
|
342 |
+
private function _convertConfigPress($option)
|
343 |
+
{
|
344 |
+
$result = AAM_Core_ConfigPress::getInstance()->save($option->option_value);
|
345 |
+
|
346 |
+
if ($result === true) {
|
347 |
+
// Delete legacy option
|
348 |
+
AAM_Core_API::deleteOption($option->option_name);
|
349 |
+
} else {
|
350 |
+
$response = new WP_Error(
|
351 |
+
'migration_error', 'Failed to convert ConfigPress settings', $option
|
352 |
+
);
|
353 |
+
}
|
354 |
+
|
355 |
+
return (!empty($response) ? $response : true);
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Convert AAM extensions option
|
360 |
+
*
|
361 |
+
* @param object $option
|
362 |
+
*
|
363 |
+
* @return array|WP_Error
|
364 |
+
*
|
365 |
+
* @access private
|
366 |
+
* @version 6.0.0
|
367 |
+
*/
|
368 |
+
private function _convertExtensionRegistry($option)
|
369 |
+
{
|
370 |
+
$result = AAM_Core_API::updateOption(
|
371 |
+
AAM_Addon_Repository::DB_OPTION, $option->option_value, 'site'
|
372 |
+
);
|
373 |
+
|
374 |
+
if ($result === true) {
|
375 |
+
// Delete legacy option
|
376 |
+
AAM_Core_API::deleteOption($option->option_name);
|
377 |
+
} else {
|
378 |
+
$response = new WP_Error(
|
379 |
+
'migration_error', 'Failed to convert Addon settings', $option
|
380 |
+
);
|
381 |
+
}
|
382 |
+
|
383 |
+
return (!empty($response) ? $response : true);
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Convert AAM Settings option
|
388 |
+
*
|
389 |
+
* @param object $option
|
390 |
+
*
|
391 |
+
* @return array|WP_Error
|
392 |
+
*
|
393 |
+
* @access private
|
394 |
+
* @version 6.0.0
|
395 |
+
*/
|
396 |
+
private function _convertSettings($option)
|
397 |
+
{
|
398 |
+
$settings = maybe_unserialize($option->option_value);
|
399 |
+
$settings_map = array(
|
400 |
+
'manage-capability' => 'core.settings.editCapabilities',
|
401 |
+
'render-access-metabox' => 'ui.settings.renderAccessMetabox',
|
402 |
+
'core.xmlrpc' => 'core.settings.xmlrpc',
|
403 |
+
'core.restful' => 'core.settings.restful',
|
404 |
+
'page-category' => 'core.settings.pageCategory',
|
405 |
+
'media-category' => 'core.settings.mediaCategory',
|
406 |
+
'single-session' => 'core.settings.singleSession',
|
407 |
+
'brute-force-lockout' => 'core.settings.bruteForceLockout'
|
408 |
+
);
|
409 |
+
|
410 |
+
$whitelist = array_merge(
|
411 |
+
AAM_Backend_Feature_Settings_Content::getList(),
|
412 |
+
AAM_Backend_Feature_Settings_Core::getList(),
|
413 |
+
AAM_Backend_Feature_Settings_Security::getList(),
|
414 |
+
array(
|
415 |
+
'frontend.404redirect.type' => true,
|
416 |
+
'frontend.404redirect.callback' => true,
|
417 |
+
)
|
418 |
+
);
|
419 |
+
|
420 |
+
$result = true;
|
421 |
+
|
422 |
+
if (is_array($settings)) {
|
423 |
+
$converted = array();
|
424 |
+
|
425 |
+
foreach ($settings as $key => $value) {
|
426 |
+
if (array_key_exists($key, $settings_map)) {
|
427 |
+
$converted[$settings_map[$key]] = filter_var(
|
428 |
+
$value, FILTER_VALIDATE_BOOLEAN
|
429 |
+
);
|
430 |
+
} elseif (array_key_exists($key, $whitelist)) {
|
431 |
+
$converted[$key] = filter_var(
|
432 |
+
$value, FILTER_VALIDATE_BOOLEAN
|
433 |
+
);
|
434 |
+
}
|
435 |
+
}
|
436 |
+
|
437 |
+
$result = AAM_Core_API::updateOption(
|
438 |
+
AAM_Core_Config::DB_OPTION, $converted, 'site'
|
439 |
+
);
|
440 |
+
}
|
441 |
+
|
442 |
+
if ($result === true) {
|
443 |
+
// Delete legacy option
|
444 |
+
AAM_Core_API::deleteOption($option->option_name);
|
445 |
+
} else {
|
446 |
+
$response = new WP_Error(
|
447 |
+
'migration_error', 'Failed to convert core settings', $option
|
448 |
+
);
|
449 |
+
}
|
450 |
+
|
451 |
+
return (!empty($response) ? $response : true);
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Convert IP Check options
|
456 |
+
*
|
457 |
+
* @param object $option
|
458 |
+
*
|
459 |
+
* @return array|WP_Error
|
460 |
+
*
|
461 |
+
* @access private
|
462 |
+
* @version 6.0.0
|
463 |
+
*/
|
464 |
+
private function _convertIPCheckOptions($options)
|
465 |
+
{
|
466 |
+
$converted = array();
|
467 |
+
|
468 |
+
foreach($options as $option) {
|
469 |
+
$id = $option['type'] . '|' . $option['rule'];
|
470 |
+
$converted[$id] = filter_var($option['mode'], FILTER_VALIDATE_BOOLEAN);
|
471 |
+
}
|
472 |
+
|
473 |
+
return $converted;
|
474 |
+
}
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Parse object specific DB option and delegate conversion
|
478 |
+
*
|
479 |
+
* @param object $option
|
480 |
+
*
|
481 |
+
* @return array
|
482 |
+
*
|
483 |
+
* @access private
|
484 |
+
* @version 6.0.0
|
485 |
+
*/
|
486 |
+
private function _parseObjectOption($option)
|
487 |
+
{
|
488 |
+
// e.g. "aam_visitor_ipCheck", "aam_visitor_term_1|category"
|
489 |
+
if (strpos($option->option_name, 'aam_visitor') === 0) {
|
490 |
+
$regex = '/^aam_visitor_([a-z]+)_?([a-z0-9_\-\|]*)$/i';
|
491 |
+
} else {
|
492 |
+
// e.g. "aam_route_role_administrator", "aam_type_post_role_editor"
|
493 |
+
$regex = '/^aam_([a-z]+)_([a-z0-9_\-\|]+)?_?(role|default)_?([a-z0-9_\-]*)$/i';
|
494 |
+
}
|
495 |
+
|
496 |
+
// Let's parse the option name and determine object & subject
|
497 |
+
if (preg_match($regex, $option->option_name, $match)) {
|
498 |
+
// Role or Default subjects:
|
499 |
+
// (
|
500 |
+
// [0] => aam_term_1|category_role_administrator_v2
|
501 |
+
// [1] => term
|
502 |
+
// [2] => 1|category
|
503 |
+
// [3] => role
|
504 |
+
// [4] => administrator_v2
|
505 |
+
// )
|
506 |
+
//
|
507 |
+
// Visitor subject:
|
508 |
+
// (
|
509 |
+
// [0] => aam_visitor_term_1|category
|
510 |
+
// [1] => term
|
511 |
+
// [2] => 1|category
|
512 |
+
// )
|
513 |
+
if (isset($this->migrationCallbacks[$match[1]])) {
|
514 |
+
// Convert options
|
515 |
+
$options = call_user_func(
|
516 |
+
$this->migrationCallbacks[$match[1]],
|
517 |
+
maybe_unserialize($option->option_value),
|
518 |
+
$match[1]
|
519 |
+
);
|
520 |
+
|
521 |
+
// Quick normalization. There are side effects with RegEx for terms
|
522 |
+
// (e.g. term_1|category_) as well as IP Check object is ipCheck
|
523 |
+
$object_id = strtolower(trim($match[2], '_'));
|
524 |
+
|
525 |
+
if (count($match) === 3) { // This is Visitor
|
526 |
+
$xpath = 'visitor.' . strtolower($match[1]);
|
527 |
+
$xpath .= (empty($object_id) ? '' : ".{$object_id}");
|
528 |
+
} else { // This is either Role or Default
|
529 |
+
$xpath = $match[3] . (empty($match[4]) ? '' : ".{$match[4]}");
|
530 |
+
|
531 |
+
if ($match[1] === 'taxonomy') {
|
532 |
+
$xpath .= '.system.defaultTerm.';
|
533 |
+
$xpath .= str_replace('|', '.', $object_id);
|
534 |
+
} else {
|
535 |
+
$xpath .= ".{$match[1]}";
|
536 |
+
$xpath .= (empty($object_id) ? '' : ".{$object_id}");
|
537 |
+
}
|
538 |
+
}
|
539 |
+
|
540 |
+
AAM_Core_AccessSettings::getInstance()->set($xpath, $options);
|
541 |
+
|
542 |
+
// Delete legacy option
|
543 |
+
AAM_Core_API::deleteOption($option->option_name);
|
544 |
+
} else {
|
545 |
+
$error = new WP_Error(
|
546 |
+
'migration_error',
|
547 |
+
sprintf('Skipped unrecognized object type "%s"', $match[1]),
|
548 |
+
$option
|
549 |
+
);
|
550 |
+
}
|
551 |
+
} else {
|
552 |
+
$error = new WP_Error(
|
553 |
+
'migration_error',
|
554 |
+
sprintf('Skipped unrecognized option "%s"', $option->option_name),
|
555 |
+
$option
|
556 |
+
);
|
557 |
+
}
|
558 |
+
|
559 |
+
return (!empty($error) ? $error : true);
|
560 |
+
}
|
561 |
+
|
562 |
+
/**
|
563 |
+
* Convert "flat" array of options
|
564 |
+
*
|
565 |
+
* It expects to have simple associated array of string => boolean values
|
566 |
+
*
|
567 |
+
* @param array $options
|
568 |
+
* @param string $object
|
569 |
+
*
|
570 |
+
* @return array
|
571 |
+
*
|
572 |
+
* @access private
|
573 |
+
* @version 6.0.0
|
574 |
+
*/
|
575 |
+
private function _convertFlatOptions($options, $object)
|
576 |
+
{
|
577 |
+
$converted = array();
|
578 |
+
|
579 |
+
if (is_array($options)) {
|
580 |
+
$converted = array_map(function($effect) {
|
581 |
+
return filter_var($effect, FILTER_VALIDATE_BOOLEAN);
|
582 |
+
}, $options);
|
583 |
+
}
|
584 |
+
|
585 |
+
return $converted;
|
586 |
+
}
|
587 |
+
|
588 |
+
/**
|
589 |
+
* Convert metabox array of options
|
590 |
+
*
|
591 |
+
* @param array $options
|
592 |
+
*
|
593 |
+
* @return array
|
594 |
+
*
|
595 |
+
* @access private
|
596 |
+
* @version 6.0.0
|
597 |
+
*/
|
598 |
+
private function _convertMetaboxOptions($options)
|
599 |
+
{
|
600 |
+
$converted = array();
|
601 |
+
|
602 |
+
if (is_array($options)) {
|
603 |
+
foreach($options as $key => $value) {
|
604 |
+
if (!is_numeric($key)) {
|
605 |
+
$converted[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
606 |
+
}
|
607 |
+
}
|
608 |
+
}
|
609 |
+
|
610 |
+
return $converted;
|
611 |
+
}
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Convert menu array of options
|
615 |
+
*
|
616 |
+
* @param array $options
|
617 |
+
*
|
618 |
+
* @return array
|
619 |
+
*
|
620 |
+
* @access private
|
621 |
+
* @version 6.0.0
|
622 |
+
*/
|
623 |
+
private function _convertMenuOptions($options)
|
624 |
+
{
|
625 |
+
return $this->_convertMetaboxOptions($options);
|
626 |
+
}
|
627 |
+
|
628 |
+
/**
|
629 |
+
* Convert As-Is
|
630 |
+
*
|
631 |
+
* @param array $options
|
632 |
+
* @param string $object
|
633 |
+
*
|
634 |
+
* @return array
|
635 |
+
*
|
636 |
+
* @access private
|
637 |
+
* @version 6.0.0
|
638 |
+
*/
|
639 |
+
private function _convertAsIs($options, $object)
|
640 |
+
{
|
641 |
+
return $options;
|
642 |
+
}
|
643 |
+
|
644 |
+
/**
|
645 |
+
* Convert URI options
|
646 |
+
*
|
647 |
+
* @param array $options
|
648 |
+
*
|
649 |
+
* @return array
|
650 |
+
*
|
651 |
+
* @access private
|
652 |
+
* @version 6.0.0
|
653 |
+
*/
|
654 |
+
private function _convertUriOptions($options)
|
655 |
+
{
|
656 |
+
$converted = array();
|
657 |
+
|
658 |
+
if (is_array($options)) {
|
659 |
+
foreach($options as $option) {
|
660 |
+
$code = !empty($option['code']) ? intval($option['code']) : null;
|
661 |
+
|
662 |
+
$converted[$option['uri']] = array(
|
663 |
+
'type' => $option['type'],
|
664 |
+
'action' => $option['action'],
|
665 |
+
'code' => $code
|
666 |
+
);
|
667 |
+
}
|
668 |
+
}
|
669 |
+
|
670 |
+
return $converted;
|
671 |
+
}
|
672 |
+
|
673 |
+
/**
|
674 |
+
* Convert Term related options
|
675 |
+
*
|
676 |
+
* @param array $options
|
677 |
+
*
|
678 |
+
* @return array
|
679 |
+
*
|
680 |
+
* @access private
|
681 |
+
* @version 6.0.0
|
682 |
+
*/
|
683 |
+
private function _convertTermOptions($options)
|
684 |
+
{
|
685 |
+
$term_options = $post_options = array();
|
686 |
+
|
687 |
+
foreach($options as $key => $value) {
|
688 |
+
$parts = explode('|', $key);
|
689 |
+
|
690 |
+
if ($parts[0] === 'post') {
|
691 |
+
$post_options[$parts[1]] = $value;
|
692 |
+
} elseif ($parts[0] === 'term') {
|
693 |
+
$term_options[$parts[1]] = $value;
|
694 |
+
}
|
695 |
+
}
|
696 |
+
|
697 |
+
return array_merge(
|
698 |
+
$this->_convertTermObject($term_options),
|
699 |
+
$this->_convertPostObject($post_options, 'post/')
|
700 |
+
);
|
701 |
+
}
|
702 |
+
|
703 |
+
/**
|
704 |
+
* Convert Type related options
|
705 |
+
*
|
706 |
+
* @param array $options
|
707 |
+
*
|
708 |
+
* @return array
|
709 |
+
*
|
710 |
+
* @access private
|
711 |
+
* @version 6.0.0
|
712 |
+
*/
|
713 |
+
private function _convertTypeOptions($options)
|
714 |
+
{
|
715 |
+
return $this->_convertTermOptions($options);
|
716 |
+
}
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Convert Taxonomy related options
|
720 |
+
*
|
721 |
+
* @param array $options
|
722 |
+
*
|
723 |
+
* @return int|null
|
724 |
+
*
|
725 |
+
* @access private
|
726 |
+
* @version 6.0.0
|
727 |
+
*/
|
728 |
+
private function _convertTaxonomyOptions($options)
|
729 |
+
{
|
730 |
+
return (isset($options['default']) ? intval($options['default']) : null);
|
731 |
+
}
|
732 |
+
|
733 |
+
/**
|
734 |
+
* Convert post object options
|
735 |
+
*
|
736 |
+
* @param array $options
|
737 |
+
* @param string $ns
|
738 |
+
*
|
739 |
+
* @return array
|
740 |
+
*
|
741 |
+
* @access private
|
742 |
+
* @version 6.0.0
|
743 |
+
*/
|
744 |
+
private function _convertPostObject($options, $ns = '')
|
745 |
+
{
|
746 |
+
$converted = array();
|
747 |
+
$normalized = $this->_normalizeContentOptions($options);
|
748 |
+
|
749 |
+
foreach($normalized as $key => $val) {
|
750 |
+
switch($key) {
|
751 |
+
case 'list':
|
752 |
+
$converted[$ns . 'hidden'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
753 |
+
break;
|
754 |
+
|
755 |
+
case 'list_others':
|
756 |
+
$converted[$ns . 'hidden_others'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
757 |
+
break;
|
758 |
+
|
759 |
+
case 'read':
|
760 |
+
$converted[$ns . 'restricted'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
761 |
+
break;
|
762 |
+
|
763 |
+
case 'read_others':
|
764 |
+
$converted[$ns . 'restricted_others'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
765 |
+
break;
|
766 |
+
|
767 |
+
case 'limit':
|
768 |
+
$msg = (!empty($normalized['teaser']) ? $normalized['teaser'] : '');
|
769 |
+
$converted[$ns . 'teaser'] = array(
|
770 |
+
'enabled' => filter_var($val, FILTER_VALIDATE_BOOLEAN),
|
771 |
+
'message' => $msg
|
772 |
+
);
|
773 |
+
break;
|
774 |
+
|
775 |
+
case 'access_counter':
|
776 |
+
$l = (!empty($normalized['access_counter_limit']) ? $normalized['access_counter_limit'] : 0);
|
777 |
+
$converted[$ns . 'limited'] = array(
|
778 |
+
'enabled' => filter_var($val, FILTER_VALIDATE_BOOLEAN),
|
779 |
+
'threshold' => $l
|
780 |
+
);
|
781 |
+
break;
|
782 |
+
|
783 |
+
case 'comment':
|
784 |
+
case 'edit':
|
785 |
+
case 'delete':
|
786 |
+
case 'publish':
|
787 |
+
case 'edit_others':
|
788 |
+
case 'delete_others':
|
789 |
+
case 'publish_others':
|
790 |
+
$converted[$ns . $key] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
791 |
+
break;
|
792 |
+
|
793 |
+
case 'add':
|
794 |
+
$converted[$ns . 'create'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
795 |
+
break;
|
796 |
+
|
797 |
+
case 'redirect':
|
798 |
+
$chunks = explode('|', $normalized['location']);
|
799 |
+
|
800 |
+
$converted[$ns . 'redirected'] = array(
|
801 |
+
'enabled' => filter_var($val, FILTER_VALIDATE_BOOLEAN),
|
802 |
+
'type' => $chunks[0],
|
803 |
+
'destination' => $chunks[1],
|
804 |
+
'httpCode' => (isset($chunks[2]) ? intval($chunks[2]) : 307)
|
805 |
+
);
|
806 |
+
break;
|
807 |
+
|
808 |
+
case 'protected':
|
809 |
+
$converted[$ns . 'protected'] = array(
|
810 |
+
'enabled' => filter_var($val, FILTER_VALIDATE_BOOLEAN),
|
811 |
+
'password' => $normalized['password']
|
812 |
+
);
|
813 |
+
break;
|
814 |
+
|
815 |
+
case 'expire':
|
816 |
+
$converted[$ns . 'ceased'] = array(
|
817 |
+
'enabled' => filter_var($val, FILTER_VALIDATE_BOOLEAN),
|
818 |
+
'after' => $normalized['expire_datetime']
|
819 |
+
);
|
820 |
+
break;
|
821 |
+
|
822 |
+
case 'access_counter_limit':
|
823 |
+
case 'teaser':
|
824 |
+
case 'location':
|
825 |
+
case 'password':
|
826 |
+
case 'expire_datetime':
|
827 |
+
// Skip those
|
828 |
+
break;
|
829 |
+
|
830 |
+
default:
|
831 |
+
break;
|
832 |
+
}
|
833 |
+
}
|
834 |
+
|
835 |
+
return $converted;
|
836 |
+
}
|
837 |
+
|
838 |
+
/**
|
839 |
+
* Normalize content options
|
840 |
+
*
|
841 |
+
* Because we are removing the segmentation of access settings between website
|
842 |
+
* levels (frontend, backend and api), this method with merge access settings
|
843 |
+
* based on preferred priority where API has the highest and Backend the lowest
|
844 |
+
*
|
845 |
+
* @param array $options
|
846 |
+
*
|
847 |
+
* @return array
|
848 |
+
*
|
849 |
+
* @access private
|
850 |
+
* @version 6.0.0
|
851 |
+
*/
|
852 |
+
private function _normalizeContentOptions($options)
|
853 |
+
{
|
854 |
+
$normalized = array(
|
855 |
+
'backend' => array(),
|
856 |
+
'frontend' => array(),
|
857 |
+
'api' => array(),
|
858 |
+
);
|
859 |
+
|
860 |
+
// Normalized it first
|
861 |
+
foreach($options as $key => $value) {
|
862 |
+
if (preg_match('/^(frontend|backend|api)\.(.*)$/i', $key, $match)) {
|
863 |
+
$normalized[$match[1]][$match[2]] = $value;
|
864 |
+
}
|
865 |
+
}
|
866 |
+
|
867 |
+
return array_merge(
|
868 |
+
$normalized['backend'], // Lowest priority
|
869 |
+
$normalized['frontend'], // Higher priority
|
870 |
+
$normalized['api'] // Highest priority
|
871 |
+
);
|
872 |
+
}
|
873 |
+
|
874 |
+
/**
|
875 |
+
* Convert term object options
|
876 |
+
*
|
877 |
+
* @param array $options
|
878 |
+
*
|
879 |
+
* @return array
|
880 |
+
*
|
881 |
+
* @access private
|
882 |
+
* @version 6.0.0
|
883 |
+
*/
|
884 |
+
private function _convertTermObject($options)
|
885 |
+
{
|
886 |
+
$converted = array();
|
887 |
+
$normalized = $this->_normalizeContentOptions($options);
|
888 |
+
|
889 |
+
foreach($normalized as $key => $val) {
|
890 |
+
switch($key) {
|
891 |
+
case 'browse':
|
892 |
+
$converted['term/restricted'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
893 |
+
break;
|
894 |
+
|
895 |
+
case 'list':
|
896 |
+
$converted['term/hidden'] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
897 |
+
break;
|
898 |
+
|
899 |
+
case 'edit':
|
900 |
+
case 'delete':
|
901 |
+
$converted["term/{$key}"] = filter_var($val, FILTER_VALIDATE_BOOLEAN);
|
902 |
+
break;
|
903 |
+
|
904 |
+
default:
|
905 |
+
break;
|
906 |
+
}
|
907 |
+
}
|
908 |
+
|
909 |
+
return $converted;
|
910 |
+
}
|
911 |
+
|
912 |
+
}
|
913 |
+
|
914 |
+
if (defined('AAM_KEY')) {
|
915 |
+
return (new Migration600())->run();
|
916 |
+
}
|
application/Service/AccessPolicy.php
CHANGED
@@ -200,7 +200,10 @@ class AAM_Service_AccessPolicy
|
|
200 |
add_filter('aam_post_object_option_filter', array($this, 'initializePost'), 10, 2);
|
201 |
add_action('aam_visibility_object_init_action', array($this, 'initializeVisibility'));
|
202 |
add_filter('aam_uri_object_option_filter', array($this, 'initializeUri'), 10, 2);
|
203 |
-
|
|
|
|
|
|
|
204 |
|
205 |
// Manage access to the Capabilities
|
206 |
add_filter('aam_cap_can_filter', array($this, 'isCapabilityAllowed'), 10, 3);
|
@@ -390,6 +393,7 @@ class AAM_Service_AccessPolicy
|
|
390 |
*
|
391 |
* @access public
|
392 |
* @see https://aamplugin.com/reference/policy#post
|
|
|
393 |
*/
|
394 |
public function initializePost($option, AAM_Core_Object_Post $object)
|
395 |
{
|
@@ -406,33 +410,50 @@ class AAM_Service_AccessPolicy
|
|
406 |
$parsed = array();
|
407 |
|
408 |
foreach($found as $action => $stmt) {
|
409 |
-
|
410 |
-
case 'edit':
|
411 |
-
case 'delete':
|
412 |
-
case 'publish':
|
413 |
-
case 'comment':
|
414 |
-
$this->convertedPostSimpleAction($parsed, $action, $stmt);
|
415 |
-
break;
|
416 |
-
|
417 |
-
case 'list':
|
418 |
-
$this->convertedPostSimpleAction($parsed, 'hidden', $stmt);
|
419 |
-
break;
|
420 |
-
|
421 |
-
case 'read':
|
422 |
-
$this->convertedPostReadAction($parsed, $stmt);
|
423 |
-
break;
|
424 |
-
|
425 |
-
default:
|
426 |
-
$parsed = apply_filters(
|
427 |
-
'aam_policy_post_conversion_filter', array(), $action, $stmt
|
428 |
-
);
|
429 |
-
break;
|
430 |
-
}
|
431 |
}
|
432 |
|
433 |
return array_replace_recursive($option, $parsed); // First-class citizen
|
434 |
}
|
435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
/**
|
437 |
* Covert simple post action to post object property
|
438 |
*
|
@@ -453,14 +474,16 @@ class AAM_Service_AccessPolicy
|
|
453 |
/**
|
454 |
* Convert Post Read action based on metadata
|
455 |
*
|
456 |
-
* @param array
|
457 |
-
* @param array
|
|
|
458 |
*
|
459 |
* @return void
|
460 |
*
|
461 |
* @access protected
|
|
|
462 |
*/
|
463 |
-
protected function convertedPostReadAction(&$options, $statement)
|
464 |
{
|
465 |
$effect = strtolower($statement['Effect']) !== "allow";
|
466 |
|
@@ -469,7 +492,7 @@ class AAM_Service_AccessPolicy
|
|
469 |
|
470 |
// Password Protected options
|
471 |
if(array_key_exists('Password', $metadata)) {
|
472 |
-
$options['protected'] = array(
|
473 |
'enabled' => $effect,
|
474 |
'password' => $metadata['Password']['Value']
|
475 |
);
|
@@ -477,7 +500,7 @@ class AAM_Service_AccessPolicy
|
|
477 |
|
478 |
// Teaser message is defined
|
479 |
if(array_key_exists('Teaser', $metadata)) {
|
480 |
-
$options['teaser'] = array(
|
481 |
'enabled' => $effect,
|
482 |
'message' => $metadata['Teaser']['Value']
|
483 |
);
|
@@ -487,10 +510,10 @@ class AAM_Service_AccessPolicy
|
|
487 |
if(array_key_exists('Redirect', $metadata)) {
|
488 |
$redirect = $this->convertRedirectAction($metadata['Redirect']);
|
489 |
$redirect['enabled'] = $effect;
|
490 |
-
$options['redirected'] = $redirect;
|
491 |
}
|
492 |
} else { // Simply restrict access to read a post
|
493 |
-
$options['restricted'] = $effect;
|
494 |
}
|
495 |
}
|
496 |
|
@@ -539,6 +562,7 @@ class AAM_Service_AccessPolicy
|
|
539 |
* @return void
|
540 |
*
|
541 |
* @access public
|
|
|
542 |
*/
|
543 |
public function initializeVisibility(AAM_Core_Object_Visibility $visibility)
|
544 |
{
|
@@ -578,6 +602,7 @@ class AAM_Service_AccessPolicy
|
|
578 |
*
|
579 |
* @access public
|
580 |
* @see https://aamplugin.com/reference/policy#uri
|
|
|
581 |
*/
|
582 |
public function initializeUri($option, AAM_Core_Object_Uri $object)
|
583 |
{
|
@@ -605,6 +630,32 @@ class AAM_Service_AccessPolicy
|
|
605 |
return array_merge($option, $parsed); //First-class citizen
|
606 |
}
|
607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
/**
|
609 |
* Convert URI metadata to the URI access option
|
610 |
*
|
@@ -711,32 +762,6 @@ class AAM_Service_AccessPolicy
|
|
711 |
return $filtered;
|
712 |
}
|
713 |
|
714 |
-
/**
|
715 |
-
* Initialize Route Object options
|
716 |
-
*
|
717 |
-
* @param array $option
|
718 |
-
* @param AAM_Core_Subject $subject
|
719 |
-
*
|
720 |
-
* @return array
|
721 |
-
*
|
722 |
-
* @access public
|
723 |
-
* @see https://aamplugin.com/reference/policy#route
|
724 |
-
*/
|
725 |
-
public function initRouteObjectOptions($option, AAM_Core_Subject $subject)
|
726 |
-
{
|
727 |
-
$stms = $this->getPolicyManager($subject)->find("/^Route:/i");
|
728 |
-
|
729 |
-
foreach ($stms as $key => $stm) {
|
730 |
-
$chunks = explode(':', $key);
|
731 |
-
$method = (isset($chunks[3]) ? $chunks[3] : 'post');
|
732 |
-
$id = "{$chunks[1]}|{$chunks[2]}|{$method}";
|
733 |
-
|
734 |
-
$option[$id] = ($stm['Effect'] === 'deny' ? 1 : 0);
|
735 |
-
}
|
736 |
-
|
737 |
-
return $option;
|
738 |
-
}
|
739 |
-
|
740 |
}
|
741 |
|
742 |
if (defined('AAM_KEY')) {
|
200 |
add_filter('aam_post_object_option_filter', array($this, 'initializePost'), 10, 2);
|
201 |
add_action('aam_visibility_object_init_action', array($this, 'initializeVisibility'));
|
202 |
add_filter('aam_uri_object_option_filter', array($this, 'initializeUri'), 10, 2);
|
203 |
+
add_filter('aam_route_object_option_filter', array($this, 'initializeRoute'), 10, 2);
|
204 |
+
|
205 |
+
// Allow third-party to hook into Post resource conversion
|
206 |
+
add_filter('aam_post_resource_filter', array($this, 'convertPostStatement'), 10, 4);
|
207 |
|
208 |
// Manage access to the Capabilities
|
209 |
add_filter('aam_cap_can_filter', array($this, 'isCapabilityAllowed'), 10, 3);
|
393 |
*
|
394 |
* @access public
|
395 |
* @see https://aamplugin.com/reference/policy#post
|
396 |
+
* @version 6.0.0
|
397 |
*/
|
398 |
public function initializePost($option, AAM_Core_Object_Post $object)
|
399 |
{
|
410 |
$parsed = array();
|
411 |
|
412 |
foreach($found as $action => $stmt) {
|
413 |
+
$parsed = $this->convertPostStatement($parsed, $action, $stmt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
}
|
415 |
|
416 |
return array_replace_recursive($option, $parsed); // First-class citizen
|
417 |
}
|
418 |
|
419 |
+
/**
|
420 |
+
* Convert Post resource statement
|
421 |
+
*
|
422 |
+
* @param array $output
|
423 |
+
* @param string $action
|
424 |
+
* @param array $stmt
|
425 |
+
* @param string $ns
|
426 |
+
*
|
427 |
+
* @return array
|
428 |
+
*
|
429 |
+
* @access public
|
430 |
+
* @version 6.0.0
|
431 |
+
*/
|
432 |
+
public function convertPostStatement($output, $action, $stmt, $ns = '')
|
433 |
+
{
|
434 |
+
switch($action) {
|
435 |
+
case 'edit':
|
436 |
+
case 'delete':
|
437 |
+
case 'publish':
|
438 |
+
case 'comment':
|
439 |
+
$this->convertedPostSimpleAction($output, $ns . $action, $stmt);
|
440 |
+
break;
|
441 |
+
|
442 |
+
case 'list':
|
443 |
+
$this->convertedPostSimpleAction($output, $ns . 'hidden', $stmt);
|
444 |
+
break;
|
445 |
+
|
446 |
+
case 'read':
|
447 |
+
$this->convertedPostReadAction($output, $stmt, $ns);
|
448 |
+
break;
|
449 |
+
|
450 |
+
default:
|
451 |
+
break;
|
452 |
+
}
|
453 |
+
|
454 |
+
return $output;
|
455 |
+
}
|
456 |
+
|
457 |
/**
|
458 |
* Covert simple post action to post object property
|
459 |
*
|
474 |
/**
|
475 |
* Convert Post Read action based on metadata
|
476 |
*
|
477 |
+
* @param array &$options
|
478 |
+
* @param array $statement
|
479 |
+
* @param string $ns
|
480 |
*
|
481 |
* @return void
|
482 |
*
|
483 |
* @access protected
|
484 |
+
* @version 6.0.0
|
485 |
*/
|
486 |
+
protected function convertedPostReadAction(&$options, $statement, $ns = '')
|
487 |
{
|
488 |
$effect = strtolower($statement['Effect']) !== "allow";
|
489 |
|
492 |
|
493 |
// Password Protected options
|
494 |
if(array_key_exists('Password', $metadata)) {
|
495 |
+
$options[$ns . 'protected'] = array(
|
496 |
'enabled' => $effect,
|
497 |
'password' => $metadata['Password']['Value']
|
498 |
);
|
500 |
|
501 |
// Teaser message is defined
|
502 |
if(array_key_exists('Teaser', $metadata)) {
|
503 |
+
$options[$ns . 'teaser'] = array(
|
504 |
'enabled' => $effect,
|
505 |
'message' => $metadata['Teaser']['Value']
|
506 |
);
|
510 |
if(array_key_exists('Redirect', $metadata)) {
|
511 |
$redirect = $this->convertRedirectAction($metadata['Redirect']);
|
512 |
$redirect['enabled'] = $effect;
|
513 |
+
$options[$ns . 'redirected'] = $redirect;
|
514 |
}
|
515 |
} else { // Simply restrict access to read a post
|
516 |
+
$options[$ns . 'restricted'] = $effect;
|
517 |
}
|
518 |
}
|
519 |
|
562 |
* @return void
|
563 |
*
|
564 |
* @access public
|
565 |
+
* @version 6.0.0
|
566 |
*/
|
567 |
public function initializeVisibility(AAM_Core_Object_Visibility $visibility)
|
568 |
{
|
602 |
*
|
603 |
* @access public
|
604 |
* @see https://aamplugin.com/reference/policy#uri
|
605 |
+
* @version 6.0.0
|
606 |
*/
|
607 |
public function initializeUri($option, AAM_Core_Object_Uri $object)
|
608 |
{
|
630 |
return array_merge($option, $parsed); //First-class citizen
|
631 |
}
|
632 |
|
633 |
+
/**
|
634 |
+
* Initialize Route Object options
|
635 |
+
*
|
636 |
+
* @param array $option
|
637 |
+
* @param AAM_Core_Object_Route $object
|
638 |
+
*
|
639 |
+
* @return array
|
640 |
+
*
|
641 |
+
* @access public
|
642 |
+
* @see https://aamplugin.com/reference/policy#route
|
643 |
+
* @version 6.0.0
|
644 |
+
*/
|
645 |
+
public function initializeRoute($option, AAM_Core_Object_Route $object)
|
646 |
+
{
|
647 |
+
$manager = AAM_Core_Policy_Factory::get($object->getSubject());
|
648 |
+
$found = $manager->getResources(AAM_Core_Policy_Resource::ROUTE);
|
649 |
+
$parsed = array();
|
650 |
+
|
651 |
+
foreach($found as $route => $stm) {
|
652 |
+
$effect = (strtolower($stm['Effect']) === 'allow' ? false : true);
|
653 |
+
$parsed[strtolower(str_replace(':', '|', $route))] = $effect;
|
654 |
+
}
|
655 |
+
|
656 |
+
return array_merge($option, $parsed); //First-class citizen
|
657 |
+
}
|
658 |
+
|
659 |
/**
|
660 |
* Convert URI metadata to the URI access option
|
661 |
*
|
762 |
return $filtered;
|
763 |
}
|
764 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
765 |
}
|
766 |
|
767 |
if (defined('AAM_KEY')) {
|
application/Service/AdminMenu.php
CHANGED
@@ -80,21 +80,23 @@ class AAM_Service_AdminMenu
|
|
80 |
*/
|
81 |
public function initializeHooks()
|
82 |
{
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
98 |
}
|
99 |
|
100 |
add_action('aam_clear_settings_action', function() {
|
80 |
*/
|
81 |
public function initializeHooks()
|
82 |
{
|
83 |
+
if (is_admin()) {
|
84 |
+
// Filter the admin menu only when we are not on the AAM page and user
|
85 |
+
// does not have the ability to manage admin menu through AAM UI
|
86 |
+
if (!AAM::isAAM() || !current_user_can('aam_manage_admin_menu')) {
|
87 |
+
add_filter('parent_file', array($this, 'filterMenu'), PHP_INT_MAX);
|
88 |
+
} elseif (AAM::isAAM()) {
|
89 |
+
// If we are on the AAM page, then cache the menu and submenu that will
|
90 |
+
// be displayed for managing on the Admin Menu tab
|
91 |
+
add_filter('parent_file', function() {
|
92 |
+
global $menu, $submenu;
|
93 |
+
|
94 |
+
AAM_Core_API::updateOption(self::CACHE_DB_OPTION, array(
|
95 |
+
'menu' => $menu,
|
96 |
+
'submenu' => $submenu
|
97 |
+
));
|
98 |
+
}, PHP_INT_MAX - 1);
|
99 |
+
}
|
100 |
}
|
101 |
|
102 |
add_action('aam_clear_settings_action', function() {
|
application/Service/Compatibility.php
CHANGED
@@ -16,6 +16,7 @@
|
|
16 |
*
|
17 |
* @package AAM
|
18 |
* @version 6.0.0
|
|
|
19 |
*/
|
20 |
class AAM_Service_Compatibility
|
21 |
{
|
@@ -33,14 +34,39 @@ class AAM_Service_Compatibility
|
|
33 |
protected function __construct()
|
34 |
{
|
35 |
$message = '[%s] plugin is outdated and was not loaded. Please update it to ';
|
36 |
-
$message .= '
|
37 |
|
38 |
// Halt outdated premium plugins
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
}
|
45 |
}
|
46 |
|
16 |
*
|
17 |
* @package AAM
|
18 |
* @version 6.0.0
|
19 |
+
* @todo Remove Feb 2021
|
20 |
*/
|
21 |
class AAM_Service_Compatibility
|
22 |
{
|
34 |
protected function __construct()
|
35 |
{
|
36 |
$message = '[%s] plugin is outdated and was not loaded. Please update it to ';
|
37 |
+
$message .= 'the latest available version to make it compatible with AAM';
|
38 |
|
39 |
// Halt outdated premium plugins
|
40 |
+
$addons = array(
|
41 |
+
'AAM_PLUS_PACKAGE' => array(
|
42 |
+
'class' => 'AAM_PlusPackage',
|
43 |
+
'name' => 'Plus Package',
|
44 |
+
'version' => '5.0.0'
|
45 |
+
),
|
46 |
+
'AAM_ROLE_HIERARCHY' => array(
|
47 |
+
'class' => 'AAM_RoleHierarchy',
|
48 |
+
'name' => 'Role Hierarchy',
|
49 |
+
'version' => '3.0.0'
|
50 |
+
),
|
51 |
+
'AAM_IP_CHECK' => array(
|
52 |
+
'class' => 'AAM_IPCheck',
|
53 |
+
'name' => 'IP Check',
|
54 |
+
'version' => '4.0.0'
|
55 |
+
),
|
56 |
+
'AAM_ECOMMERCE' => array(
|
57 |
+
'class' => 'AAM_Ecommerce',
|
58 |
+
'name' => 'E-Commerce',
|
59 |
+
'version' => '4.0.0'
|
60 |
+
)
|
61 |
+
);
|
62 |
|
63 |
+
foreach($addons as $slug => $addon) {
|
64 |
+
if (defined($slug) && version_compare(constant($slug), $addon['version']) === -1) {
|
65 |
+
class_alias('AAM', $addon['class']);
|
66 |
+
if ($slug !== 'AAM_ECOMMERCE') {
|
67 |
+
AAM_Core_Console::add(sprintf($message, $addon['name']), 'b');
|
68 |
+
}
|
69 |
+
}
|
70 |
}
|
71 |
}
|
72 |
|
application/Service/Content.php
CHANGED
@@ -854,8 +854,8 @@ class AAM_Service_Content
|
|
854 |
{
|
855 |
if(is_user_logged_in() && $post->is('limited')) {
|
856 |
$option = sprintf(self::POST_COUNTER_DB_OPTION, $post->ID);
|
857 |
-
$counter = intval(
|
858 |
-
|
859 |
}
|
860 |
}
|
861 |
|
@@ -991,7 +991,7 @@ class AAM_Service_Content
|
|
991 |
if ($user && $post->is('limited')) {
|
992 |
$limited = $post->get('limited');
|
993 |
$option = sprintf(self::POST_COUNTER_DB_OPTION, $post->ID);
|
994 |
-
$counter = intval(
|
995 |
|
996 |
if ($counter >= $limited['threshold']) {
|
997 |
$result = new WP_Error(
|
854 |
{
|
855 |
if(is_user_logged_in() && $post->is('limited')) {
|
856 |
$option = sprintf(self::POST_COUNTER_DB_OPTION, $post->ID);
|
857 |
+
$counter = intval(get_user_option($option, get_current_user_id()));
|
858 |
+
update_user_option(get_current_user_id(), $option, ++$counter);
|
859 |
}
|
860 |
}
|
861 |
|
991 |
if ($user && $post->is('limited')) {
|
992 |
$limited = $post->get('limited');
|
993 |
$option = sprintf(self::POST_COUNTER_DB_OPTION, $post->ID);
|
994 |
+
$counter = intval(get_user_option($option, $user));
|
995 |
|
996 |
if ($counter >= $limited['threshold']) {
|
997 |
$result = new WP_Error(
|
application/Service/Core.php
CHANGED
@@ -90,7 +90,7 @@ class AAM_Service_Core
|
|
90 |
|
91 |
// Fetch registry from the AAM server
|
92 |
$raw = wp_remote_post(
|
93 |
-
|
94 |
array(
|
95 |
'headers' => array(
|
96 |
'Accept' => 'application/json',
|
90 |
|
91 |
// Fetch registry from the AAM server
|
92 |
$raw = wp_remote_post(
|
93 |
+
AAM_Core_API::getAPIEndpoint() . '/registry',
|
94 |
array(
|
95 |
'headers' => array(
|
96 |
'Accept' => 'application/json',
|
application/Service/ExtendedCapabilities.php
CHANGED
@@ -71,8 +71,26 @@ class AAM_Service_ExtendedCapabilities
|
|
71 |
protected function initializeHooks()
|
72 |
{
|
73 |
if (is_admin()) {
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
// Control admin area
|
78 |
add_action('admin_notices', array($this, 'controlAdminNotifications'), -1);
|
@@ -99,33 +117,6 @@ class AAM_Service_ExtendedCapabilities
|
|
99 |
// Password reset feature
|
100 |
add_filter('show_password_fields', array($this, 'canChangePassword'), 10, 2);
|
101 |
add_action('check_passwords', array($this, 'canUpdatePassword'), 10, 3);
|
102 |
-
|
103 |
-
// Admin bar
|
104 |
-
if (
|
105 |
-
AAM_Core_API::capExists('show_admin_bar')
|
106 |
-
&& !current_user_can('show_admin_bar')
|
107 |
-
) {
|
108 |
-
add_filter('show_admin_bar', '__return_false', PHP_INT_MAX);
|
109 |
-
}
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Check if user has access to the backend
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*
|
117 |
-
* @access protected
|
118 |
-
* @version 6.0.0
|
119 |
-
*/
|
120 |
-
protected function checkUserAccess()
|
121 |
-
{
|
122 |
-
if (is_user_logged_in() && AAM_Core_API::capExists('access_dashboard')) {
|
123 |
-
// If this is the AJAX call, still allow it because it will break a lot
|
124 |
-
// of frontend stuff that depends on it
|
125 |
-
if (!current_user_can('access_dashboard') && !defined('DOING_AJAX')) {
|
126 |
-
wp_die(__('Access Denied', AAM_KEY), 'aam_access_denied');
|
127 |
-
}
|
128 |
-
}
|
129 |
}
|
130 |
|
131 |
/**
|
71 |
protected function initializeHooks()
|
72 |
{
|
73 |
if (is_admin()) {
|
74 |
+
add_action('init', function() {
|
75 |
+
if (is_user_logged_in()) {
|
76 |
+
// Check if user is allowed to see backend
|
77 |
+
if (AAM_Core_API::capExists('access_dashboard')) {
|
78 |
+
// If this is the AJAX call, still allow it because it will break a lot
|
79 |
+
// of frontend stuff that depends on it
|
80 |
+
if (!current_user_can('access_dashboard') && !defined('DOING_AJAX')) {
|
81 |
+
wp_die(__('Access Denied', AAM_KEY), 'aam_access_denied');
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
// Check if we need to show admin bar for the current user
|
86 |
+
if (
|
87 |
+
AAM_Core_API::capExists('show_admin_bar')
|
88 |
+
&& !current_user_can('show_admin_bar')
|
89 |
+
) {
|
90 |
+
add_filter('show_admin_bar', '__return_false', PHP_INT_MAX);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}, 1);
|
94 |
|
95 |
// Control admin area
|
96 |
add_action('admin_notices', array($this, 'controlAdminNotifications'), -1);
|
117 |
// Password reset feature
|
118 |
add_filter('show_password_fields', array($this, 'canChangePassword'), 10, 2);
|
119 |
add_action('check_passwords', array($this, 'canUpdatePassword'), 10, 3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
|
122 |
/**
|
application/Service/Jwt.php
CHANGED
@@ -27,6 +27,13 @@ class AAM_Service_Jwt
|
|
27 |
*/
|
28 |
const FEATURE_FLAG = 'core.service.jwt.enabled';
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
/**
|
31 |
* Constructor
|
32 |
*
|
@@ -87,7 +94,10 @@ class AAM_Service_Jwt
|
|
87 |
global $wpdb;
|
88 |
|
89 |
// Run the query, will return true if deleted, false otherwise
|
90 |
-
$wpdb->delete(
|
|
|
|
|
|
|
91 |
});
|
92 |
|
93 |
// Register API endpoint
|
@@ -208,7 +218,7 @@ class AAM_Service_Jwt
|
|
208 |
// calculate the new expiration
|
209 |
$issuedAt = new DateTime();
|
210 |
$issuedAt->setTimestamp($result->iat);
|
211 |
-
$expires = DateTime
|
212 |
|
213 |
$exp = new DateTime();
|
214 |
$exp->add($issuedAt->diff($expires));
|
@@ -314,15 +324,29 @@ class AAM_Service_Jwt
|
|
314 |
$limit = AAM_Core_Config::get('authentication.jwt.registryLimit', 10);
|
315 |
|
316 |
if ($replaceExisting) {
|
317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
} else {
|
319 |
// Make sure that we do not overload the user meta
|
320 |
if (count($registry) >= $limit) {
|
321 |
-
|
322 |
}
|
323 |
|
|
|
|
|
|
|
324 |
// Save token
|
325 |
-
$result =
|
326 |
}
|
327 |
|
328 |
return $result;
|
@@ -340,7 +364,7 @@ class AAM_Service_Jwt
|
|
340 |
*/
|
341 |
public function getTokenRegistry($userId)
|
342 |
{
|
343 |
-
$registry =
|
344 |
|
345 |
return (!empty($registry) ? $registry : array());
|
346 |
}
|
@@ -358,14 +382,15 @@ class AAM_Service_Jwt
|
|
358 |
*/
|
359 |
public function revokeToken($userId, $token)
|
360 |
{
|
361 |
-
$
|
362 |
-
$registry = $this->getTokenRegistry($userId);
|
363 |
|
364 |
-
|
365 |
-
|
|
|
|
|
366 |
}
|
367 |
|
368 |
-
return $
|
369 |
}
|
370 |
|
371 |
/**
|
@@ -446,22 +471,20 @@ class AAM_Service_Jwt
|
|
446 |
$token = $this->extractToken();
|
447 |
$claims = AAM_Core_Jwt_Issuer::getInstance()->extractTokenClaims($token->jwt);
|
448 |
|
449 |
-
// Check if
|
450 |
$user = apply_filters('aam_verify_user_filter', new WP_User($claims->userId));
|
451 |
|
452 |
if (!is_wp_error($user)) {
|
453 |
wp_set_current_user($claims->userId);
|
454 |
wp_set_auth_cookie($claims->userId);
|
455 |
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
'meta' => (!empty($trigger->role) ? $trigger->role : '')
|
464 |
-
));
|
465 |
|
466 |
do_action('wp_login', $user->user_login, $user);
|
467 |
|
@@ -546,7 +569,7 @@ class AAM_Service_Jwt
|
|
546 |
break;
|
547 |
}
|
548 |
|
549 |
-
if (!
|
550 |
break;
|
551 |
}
|
552 |
}
|
27 |
*/
|
28 |
const FEATURE_FLAG = 'core.service.jwt.enabled';
|
29 |
|
30 |
+
/**
|
31 |
+
* JWT Registry DB option
|
32 |
+
*
|
33 |
+
* @version 6.0.0
|
34 |
+
*/
|
35 |
+
const DB_OPTION = 'aam_jwt_registry';
|
36 |
+
|
37 |
/**
|
38 |
* Constructor
|
39 |
*
|
94 |
global $wpdb;
|
95 |
|
96 |
// Run the query, will return true if deleted, false otherwise
|
97 |
+
$wpdb->delete(
|
98 |
+
$wpdb->usermeta,
|
99 |
+
array('meta_key' => $wpdb->prefix . AAM_Service_Jwt::DB_OPTION)
|
100 |
+
);
|
101 |
});
|
102 |
|
103 |
// Register API endpoint
|
218 |
// calculate the new expiration
|
219 |
$issuedAt = new DateTime();
|
220 |
$issuedAt->setTimestamp($result->iat);
|
221 |
+
$expires = new DateTime('@' . $result->exp, new DateTimeZone('UTC'));
|
222 |
|
223 |
$exp = new DateTime();
|
224 |
$exp->add($issuedAt->diff($expires));
|
324 |
$limit = AAM_Core_Config::get('authentication.jwt.registryLimit', 10);
|
325 |
|
326 |
if ($replaceExisting) {
|
327 |
+
// First let's delete existing token
|
328 |
+
$filtered = array();
|
329 |
+
foreach($registry as $item) {
|
330 |
+
if ($item !== $replaceExisting) {
|
331 |
+
$filtered[] = $item;
|
332 |
+
}
|
333 |
+
}
|
334 |
+
|
335 |
+
// Add new token to the registry
|
336 |
+
$filtered[] = $token;
|
337 |
+
|
338 |
+
$result = update_user_option($userId, self::DB_OPTION, $filtered);
|
339 |
} else {
|
340 |
// Make sure that we do not overload the user meta
|
341 |
if (count($registry) >= $limit) {
|
342 |
+
array_shift($registry);
|
343 |
}
|
344 |
|
345 |
+
// Add new token to the registry
|
346 |
+
$registry[] = $token;
|
347 |
+
|
348 |
// Save token
|
349 |
+
$result = update_user_option($userId, self::DB_OPTION, $registry);
|
350 |
}
|
351 |
|
352 |
return $result;
|
364 |
*/
|
365 |
public function getTokenRegistry($userId)
|
366 |
{
|
367 |
+
$registry = get_user_option(self::DB_OPTION, $userId);
|
368 |
|
369 |
return (!empty($registry) ? $registry : array());
|
370 |
}
|
382 |
*/
|
383 |
public function revokeToken($userId, $token)
|
384 |
{
|
385 |
+
$filtered = array();
|
|
|
386 |
|
387 |
+
foreach($this->getTokenRegistry($userId) as $item) {
|
388 |
+
if ($token !== $item) {
|
389 |
+
$filtered[] = $item;
|
390 |
+
}
|
391 |
}
|
392 |
|
393 |
+
return update_user_option($userId, self::DB_OPTION, $filtered);
|
394 |
}
|
395 |
|
396 |
/**
|
471 |
$token = $this->extractToken();
|
472 |
$claims = AAM_Core_Jwt_Issuer::getInstance()->extractTokenClaims($token->jwt);
|
473 |
|
474 |
+
// Check if account is active
|
475 |
$user = apply_filters('aam_verify_user_filter', new WP_User($claims->userId));
|
476 |
|
477 |
if (!is_wp_error($user)) {
|
478 |
wp_set_current_user($claims->userId);
|
479 |
wp_set_auth_cookie($claims->userId);
|
480 |
|
481 |
+
do_action(
|
482 |
+
'aam_set_user_expiration_action',
|
483 |
+
array_merge(
|
484 |
+
array('expires' => $claims->exp),
|
485 |
+
property_exists($claims, 'trigger') ? (array)$claims->trigger : array()
|
486 |
+
)
|
487 |
+
);
|
|
|
|
|
488 |
|
489 |
do_action('wp_login', $user->user_login, $user);
|
490 |
|
569 |
break;
|
570 |
}
|
571 |
|
572 |
+
if (!empty($jwt)) {
|
573 |
break;
|
574 |
}
|
575 |
}
|
application/Service/UserLevelFilter.php
CHANGED
@@ -67,11 +67,13 @@ class AAM_Service_UserLevelFilter
|
|
67 |
protected function initializeHooks()
|
68 |
{
|
69 |
// User/role filters
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
|
76 |
// Check if user has ability to perform certain task on other users
|
77 |
add_filter('map_meta_cap', array($this, 'mapMetaCaps'), 999, 4);
|
67 |
protected function initializeHooks()
|
68 |
{
|
69 |
// User/role filters
|
70 |
+
add_action('init', function() {
|
71 |
+
if (!is_multisite() || !is_super_admin()) {
|
72 |
+
add_filter('editable_roles', array($this, 'filterRoles'));
|
73 |
+
add_action('pre_get_users', array($this, 'filterUserQuery'), 999);
|
74 |
+
add_filter('views_users', array($this, 'filterViews'));
|
75 |
+
}
|
76 |
+
}, 1);
|
77 |
|
78 |
// Check if user has ability to perform certain task on other users
|
79 |
add_filter('map_meta_cap', array($this, 'mapMetaCaps'), 999, 4);
|
lang/advanced-access-manager-en_US.po
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
msgid ""
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Advanced Access Manager\n"
|
4 |
-
"POT-Creation-Date: 2019-10-
|
5 |
"PO-Revision-Date: \n"
|
6 |
"Last-Translator: \n"
|
7 |
"Language-Team: AAMPlugin <support@aamplugin.com>\n"
|
@@ -95,15 +95,19 @@ msgstr ""
|
|
95 |
msgid "Capabilities"
|
96 |
msgstr ""
|
97 |
|
98 |
-
#: application/Backend/Feature/Main/Jwt.php:
|
99 |
msgid "Failed to register JWT token"
|
100 |
msgstr ""
|
101 |
|
102 |
-
#: application/Backend/Feature/Main/Jwt.php:
|
103 |
msgid "Failed to revoke JWT token"
|
104 |
msgstr ""
|
105 |
|
106 |
-
#: application/Backend/Feature/Main/Jwt.php:
|
|
|
|
|
|
|
|
|
107 |
msgid "JWT Tokens"
|
108 |
msgstr ""
|
109 |
|
@@ -169,7 +173,7 @@ msgstr ""
|
|
169 |
msgid "Login page"
|
170 |
msgstr ""
|
171 |
|
172 |
-
#: application/Backend/Feature/Main/Post.php:
|
173 |
#: application/Service/Content.php:72
|
174 |
msgid "Posts & Terms"
|
175 |
msgstr ""
|
@@ -290,13 +294,21 @@ msgstr ""
|
|
290 |
msgid "Cannot manage yourself"
|
291 |
msgstr ""
|
292 |
|
293 |
-
#: application/Backend/Feature/Subject/User.php:
|
294 |
-
#: application/Backend/Feature/Subject/User.php:
|
295 |
-
#: application/Backend/View/Localization.php:
|
296 |
msgid "Unexpected application error"
|
297 |
msgstr ""
|
298 |
|
299 |
-
#: application/Backend/Manager.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
msgid "[Help us] to be more noticeable and submit your review"
|
301 |
msgstr ""
|
302 |
|
@@ -304,511 +316,515 @@ msgstr ""
|
|
304 |
msgid "You are not allowed to manage AAM subjects"
|
305 |
msgstr ""
|
306 |
|
307 |
-
#: application/Backend/View/Localization.php:32 media/js/aam.js:
|
308 |
msgid "Search Capability"
|
309 |
msgstr ""
|
310 |
|
311 |
-
#: application/Backend/View/Localization.php:33 media/js/aam.js:
|
312 |
msgid "_TOTAL_ capability(s)"
|
313 |
msgstr ""
|
314 |
|
315 |
#: application/Backend/View/Localization.php:34 media/js/aam.js:410
|
316 |
-
#: media/js/aam.js:471 media/js/aam.js:
|
317 |
-
#: media/js/aam.js:
|
318 |
-
#: media/js/aam.js:
|
319 |
-
#: media/js/aam.js:
|
320 |
msgid "Saving..."
|
321 |
msgstr ""
|
322 |
|
323 |
-
#: application/Backend/View/Localization.php:35
|
|
|
|
|
|
|
|
|
324 |
msgid "Failed to add new capability"
|
325 |
msgstr ""
|
326 |
|
327 |
-
#: application/Backend/View/Localization.php:
|
328 |
msgid "Application error"
|
329 |
msgstr ""
|
330 |
|
331 |
-
#: application/Backend/View/Localization.php:
|
332 |
msgid "Add Capability"
|
333 |
msgstr ""
|
334 |
|
335 |
-
#: application/Backend/View/Localization.php:
|
336 |
-
#: application/Backend/tmpl/service/capability.php:76 media/js/aam.js:
|
337 |
msgid "Update Capability"
|
338 |
msgstr ""
|
339 |
|
340 |
-
#: application/Backend/View/Localization.php:
|
341 |
#: application/Backend/tmpl/service/menu.php:93
|
342 |
-
#: application/Backend/tmpl/service/toolbar.php:70 media/js/aam.js:
|
343 |
-
#: media/js/aam.js:
|
344 |
msgid "Show Menu"
|
345 |
msgstr ""
|
346 |
|
347 |
-
#: application/Backend/View/Localization.php:
|
348 |
#: application/Backend/tmpl/service/menu.php:97
|
349 |
-
#: application/Backend/tmpl/service/toolbar.php:74 media/js/aam.js:
|
350 |
-
#: media/js/aam.js:
|
351 |
msgid "Restrict Menu"
|
352 |
msgstr ""
|
353 |
|
354 |
-
#: application/Backend/View/Localization.php:
|
355 |
msgid "Failed to retrieve mataboxes"
|
356 |
msgstr ""
|
357 |
|
358 |
-
#: application/Backend/View/Localization.php:
|
359 |
-
#: media/js/aam.js:
|
360 |
msgid "Search"
|
361 |
msgstr ""
|
362 |
|
363 |
-
#: application/Backend/View/Localization.php:
|
364 |
msgid "_TOTAL_ object(s)"
|
365 |
msgstr ""
|
366 |
|
367 |
-
#: application/Backend/View/Localization.php:
|
368 |
msgid "Failed"
|
369 |
msgstr ""
|
370 |
|
371 |
-
#: application/Backend/View/Localization.php:
|
372 |
-
#: media/js/aam.js:
|
373 |
msgid "Loading..."
|
374 |
msgstr ""
|
375 |
|
376 |
-
#: application/Backend/View/Localization.php:
|
377 |
msgid "No role"
|
378 |
msgstr ""
|
379 |
|
380 |
-
#: application/Backend/View/Localization.php:
|
381 |
msgid "Create New Role"
|
382 |
msgstr ""
|
383 |
|
384 |
-
#: application/Backend/View/Localization.php:
|
385 |
msgid "Search Role"
|
386 |
msgstr ""
|
387 |
|
388 |
-
#: application/Backend/View/Localization.php:
|
389 |
msgid "_TOTAL_ role(s)"
|
390 |
msgstr ""
|
391 |
|
392 |
-
#: application/Backend/View/Localization.php:
|
393 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:19
|
394 |
#: application/Backend/tmpl/service/capability.php:30
|
395 |
#: application/Backend/tmpl/service/capability.php:64
|
396 |
-
#: application/Backend/tmpl/service/jwt.php:84 media/js/aam.js:
|
397 |
-
#: media/js/aam.js:
|
398 |
msgid "Create"
|
399 |
msgstr ""
|
400 |
|
401 |
-
#: application/Backend/View/Localization.php:
|
402 |
#: application/Backend/tmpl/page/subject-panel.php:17 media/js/aam.js:171
|
403 |
msgid "Users"
|
404 |
msgstr ""
|
405 |
|
406 |
-
#: application/Backend/View/Localization.php:
|
407 |
msgid "Failed to add new role"
|
408 |
msgstr ""
|
409 |
|
410 |
-
#: application/Backend/View/Localization.php:
|
411 |
msgid "Add Role"
|
412 |
msgstr ""
|
413 |
|
414 |
-
#: application/Backend/View/Localization.php:
|
415 |
msgid "Failed to update role"
|
416 |
msgstr ""
|
417 |
|
418 |
-
#: application/Backend/View/Localization.php:
|
419 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:41
|
420 |
#: application/Backend/tmpl/service/capability.php:90 media/js/aam.js:487
|
421 |
msgid "Update"
|
422 |
msgstr ""
|
423 |
|
424 |
-
#: application/Backend/View/Localization.php:
|
425 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:110
|
426 |
#: application/Backend/tmpl/partial/post-access-form.php:89
|
427 |
-
#: media/js/aam.js:
|
428 |
msgid "Reset"
|
429 |
msgstr ""
|
430 |
|
431 |
-
#: application/Backend/View/Localization.php:
|
432 |
msgid "Update..."
|
433 |
msgstr ""
|
434 |
|
435 |
-
#: application/Backend/View/Localization.php:
|
436 |
-
#: media/js/aam.js:
|
437 |
msgid "Deleting..."
|
438 |
msgstr ""
|
439 |
|
440 |
-
#: application/Backend/View/Localization.php:
|
441 |
msgid "Failed to delete role"
|
442 |
msgstr ""
|
443 |
|
444 |
-
#: application/Backend/View/Localization.php:
|
445 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:53
|
446 |
msgid "Delete Role"
|
447 |
msgstr ""
|
448 |
|
449 |
-
#: application/Backend/View/Localization.php:
|
450 |
msgid "Failed to lock user"
|
451 |
msgstr ""
|
452 |
|
453 |
-
#: application/Backend/View/Localization.php:
|
454 |
msgid "Search user"
|
455 |
msgstr ""
|
456 |
|
457 |
-
#: application/Backend/View/Localization.php:
|
458 |
msgid "Counter was reset successfully"
|
459 |
msgstr ""
|
460 |
|
461 |
-
#: application/Backend/View/Localization.php:
|
462 |
msgid "_TOTAL_ user(s)"
|
463 |
msgstr ""
|
464 |
|
465 |
-
#: application/Backend/View/Localization.php:
|
466 |
msgid "Create New User"
|
467 |
msgstr ""
|
468 |
|
469 |
-
#: application/Backend/View/Localization.php:
|
470 |
-
#: application/Backend/tmpl/page/subject-panel.php:38 media/js/aam.js:
|
471 |
msgid "Role"
|
472 |
msgstr ""
|
473 |
|
474 |
-
#: application/Backend/View/Localization.php:
|
475 |
-
#: application/Core/Subject/Default.php:36 media/js/aam.js:
|
476 |
msgid "All Users, Roles and Visitor"
|
477 |
msgstr ""
|
478 |
|
479 |
-
#: application/Backend/View/Localization.php:
|
480 |
-
#: media/js/aam.js:
|
481 |
msgid "Failed to apply policy changes"
|
482 |
msgstr ""
|
483 |
|
484 |
-
#: application/Backend/View/Localization.php:
|
485 |
#: application/Backend/tmpl/partial/visitor-principal-subject-tab.php:14
|
486 |
-
#: media/js/aam.js:
|
487 |
msgid "Attach Policy To Visitors"
|
488 |
msgstr ""
|
489 |
|
490 |
-
#: application/Backend/View/Localization.php:
|
491 |
#: application/Backend/tmpl/partial/visitor-principal-subject-tab.php:12
|
492 |
-
#: media/js/aam.js:
|
493 |
msgid "Detach Policy From Visitors"
|
494 |
msgstr ""
|
495 |
|
496 |
-
#: application/Backend/View/Localization.php:
|
497 |
-
#: media/js/aam.js:
|
498 |
msgid "Generating URL..."
|
499 |
msgstr ""
|
500 |
|
501 |
-
#: application/Backend/View/Localization.php:
|
502 |
-
#: application/Core/Subject/Visitor.php:43 media/js/aam.js:
|
503 |
msgid "Anonymous"
|
504 |
msgstr ""
|
505 |
|
506 |
-
#: application/Backend/View/Localization.php:
|
507 |
-
#: media/js/aam.js:
|
508 |
msgid "Processing..."
|
509 |
msgstr ""
|
510 |
|
511 |
-
#: application/Backend/View/Localization.php:
|
512 |
msgid "Loading roles..."
|
513 |
msgstr ""
|
514 |
|
515 |
-
#: application/Backend/View/Localization.php:
|
516 |
-
#: media/js/aam.js:
|
517 |
msgid "Failed to generate JWT token"
|
518 |
msgstr ""
|
519 |
|
520 |
-
#: application/Backend/View/Localization.php:
|
521 |
msgid "Failed to process request"
|
522 |
msgstr ""
|
523 |
|
524 |
-
#: application/Backend/View/Localization.php:
|
525 |
msgid "Current user"
|
526 |
msgstr ""
|
527 |
|
528 |
-
#: application/Backend/View/Localization.php:
|
529 |
msgid "Current role"
|
530 |
msgstr ""
|
531 |
|
532 |
-
#: application/Backend/View/Localization.php:
|
533 |
msgid "Manage Access"
|
534 |
msgstr ""
|
535 |
|
536 |
-
#: application/Backend/View/Localization.php:
|
537 |
msgid "Filter by role"
|
538 |
msgstr ""
|
539 |
|
540 |
-
#: application/Backend/View/Localization.php:
|
541 |
-
#: application/Backend/View/PostOptionList.php:76 media/js/aam.js:
|
542 |
msgid "Edit"
|
543 |
msgstr ""
|
544 |
|
545 |
-
#: application/Backend/View/Localization.php:
|
546 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:111
|
547 |
#: application/Backend/tmpl/partial/post-access-form.php:60
|
548 |
#: application/Backend/tmpl/partial/post-access-form.php:90
|
549 |
#: application/Backend/tmpl/partial/post-access-form.php:163
|
550 |
#: application/Backend/tmpl/partial/post-access-form.php:184
|
551 |
#: application/Backend/tmpl/partial/post-access-form.php:205
|
552 |
-
#: application/Backend/tmpl/service/uri.php:108 media/js/aam.js:
|
553 |
-
#: media/js/aam.js:
|
554 |
msgid "Save"
|
555 |
msgstr ""
|
556 |
|
557 |
-
#: application/Backend/View/Localization.php:
|
558 |
msgid "Manage role"
|
559 |
msgstr ""
|
560 |
|
561 |
-
#: application/Backend/View/Localization.php:
|
562 |
msgid "Edit role"
|
563 |
msgstr ""
|
564 |
|
565 |
-
#: application/Backend/View/Localization.php:
|
566 |
#: media/js/aam.js:524
|
567 |
msgid "Delete role"
|
568 |
msgstr ""
|
569 |
|
570 |
-
#: application/Backend/View/Localization.php:
|
571 |
msgid "Clone role"
|
572 |
msgstr ""
|
573 |
|
574 |
-
#: application/Backend/View/Localization.php:
|
575 |
msgid "Manage user"
|
576 |
msgstr ""
|
577 |
|
578 |
-
#: application/Backend/View/Localization.php:
|
579 |
msgid "Edit user"
|
580 |
msgstr ""
|
581 |
|
582 |
-
#: application/Backend/View/Localization.php:
|
583 |
-
#: media/js/aam.js:606 media/js/aam.js:
|
584 |
msgid "Lock user"
|
585 |
msgstr ""
|
586 |
|
587 |
-
#: application/Backend/View/Localization.php:
|
588 |
-
#: media/js/aam.js:600 media/js/aam.js:
|
589 |
msgid "Unlock user"
|
590 |
msgstr ""
|
591 |
|
592 |
-
#: application/Backend/View/Localization.php:
|
593 |
msgid "WordPress core does not allow to grant this capability"
|
594 |
msgstr ""
|
595 |
|
596 |
-
#: application/Backend/View/Localization.php:
|
597 |
-
#: media/js/aam.js:
|
598 |
msgid "Detach Policy From Everybody"
|
599 |
msgstr ""
|
600 |
|
601 |
-
#: application/Backend/View/Localization.php:
|
602 |
-
#: media/js/aam.js:
|
603 |
msgid "Attach Policy To Everybody"
|
604 |
msgstr ""
|
605 |
|
606 |
-
#: application/Backend/View/Localization.php:
|
607 |
msgid "Search Policy"
|
608 |
msgstr ""
|
609 |
|
610 |
-
#: application/Backend/View/Localization.php:
|
611 |
msgid "_TOTAL_ Policies"
|
612 |
msgstr ""
|
613 |
|
614 |
-
#: application/Backend/View/Localization.php:
|
615 |
msgid "Apply Policy"
|
616 |
msgstr ""
|
617 |
|
618 |
-
#: application/Backend/View/Localization.php:
|
619 |
msgid "Revoke Policy"
|
620 |
msgstr ""
|
621 |
|
622 |
-
#: application/Backend/View/Localization.php:
|
623 |
-
#: application/Service/AccessPolicy.php:170 media/js/aam.js:
|
624 |
msgid "Edit Policy"
|
625 |
msgstr ""
|
626 |
|
627 |
-
#: application/Backend/View/Localization.php:
|
628 |
#: application/Backend/tmpl/service/menu.php:79
|
629 |
-
#: application/Backend/tmpl/service/toolbar.php:60 media/js/aam.js:
|
630 |
msgid "Uncheck to allow"
|
631 |
msgstr ""
|
632 |
|
633 |
-
#: application/Backend/View/Localization.php:
|
634 |
#: application/Backend/tmpl/service/menu.php:79
|
635 |
-
#: application/Backend/tmpl/service/toolbar.php:60 media/js/aam.js:
|
636 |
msgid "Check to restrict"
|
637 |
msgstr ""
|
638 |
|
639 |
-
#: application/Backend/View/Localization.php:
|
640 |
-
#: application/Backend/tmpl/service/metabox.php:78 media/js/aam.js:
|
641 |
-
#: media/js/aam.js:
|
642 |
msgid "Uncheck to show"
|
643 |
msgstr ""
|
644 |
|
645 |
-
#: application/Backend/View/Localization.php:
|
646 |
-
#: application/Backend/tmpl/service/metabox.php:78 media/js/aam.js:
|
647 |
-
#: media/js/aam.js:
|
648 |
msgid "Check to hide"
|
649 |
msgstr ""
|
650 |
|
651 |
-
#: application/Backend/View/Localization.php:
|
652 |
-
#: application/Backend/tmpl/service/metabox.php:114 media/js/aam.js:
|
653 |
msgid "Initialize"
|
654 |
msgstr ""
|
655 |
|
656 |
-
#: application/Backend/View/Localization.php:
|
657 |
msgid "No capabilities"
|
658 |
msgstr ""
|
659 |
|
660 |
-
#: application/Backend/View/Localization.php:
|
661 |
msgid "Post Type"
|
662 |
msgstr ""
|
663 |
|
664 |
-
#: application/Backend/View/Localization.php:
|
665 |
msgid "Hierarchical Taxonomy"
|
666 |
msgstr ""
|
667 |
|
668 |
-
#: application/Backend/View/Localization.php:
|
669 |
msgid "Hierarchical Term"
|
670 |
msgstr ""
|
671 |
|
672 |
-
#: application/Backend/View/Localization.php:
|
673 |
msgid "Tag Taxonomy"
|
674 |
msgstr ""
|
675 |
|
676 |
-
#: application/Backend/View/Localization.php:
|
677 |
msgid "Tag"
|
678 |
msgstr ""
|
679 |
|
680 |
-
#: application/Backend/View/Localization.php:
|
681 |
msgid "Customized Settings"
|
682 |
msgstr ""
|
683 |
|
684 |
-
#: application/Backend/View/Localization.php:
|
685 |
-
#: media/js/aam.js:
|
686 |
msgid "Parent"
|
687 |
msgstr ""
|
688 |
|
689 |
-
#: application/Backend/View/Localization.php:
|
690 |
msgid "Drill-Down"
|
691 |
msgstr ""
|
692 |
|
693 |
-
#: application/Backend/View/Localization.php:
|
694 |
msgid "_TOTAL_ route(s)"
|
695 |
msgstr ""
|
696 |
|
697 |
-
#: application/Backend/View/Localization.php:
|
698 |
msgid "No API endpoints found. You might have APIs disabled."
|
699 |
msgstr ""
|
700 |
|
701 |
-
#: application/Backend/View/Localization.php:
|
702 |
-
#: media/js/aam.js:
|
703 |
msgid "Nothing to show"
|
704 |
msgstr ""
|
705 |
|
706 |
-
#: application/Backend/View/Localization.php:
|
707 |
msgid "Failed to save URI rule"
|
708 |
msgstr ""
|
709 |
|
710 |
-
#: application/Backend/View/Localization.php:
|
711 |
msgid "Failed to delete URI rule"
|
712 |
msgstr ""
|
713 |
|
714 |
-
#: application/Backend/View/Localization.php:
|
715 |
msgid "_TOTAL_ URI(s)"
|
716 |
msgstr ""
|
717 |
|
718 |
-
#: application/Backend/View/Localization.php:
|
719 |
msgid "Edit Rule"
|
720 |
msgstr ""
|
721 |
|
722 |
-
#: application/Backend/View/Localization.php:
|
723 |
msgid "Delete Rule"
|
724 |
msgstr ""
|
725 |
|
726 |
-
#: application/Backend/View/Localization.php:
|
727 |
msgid "Denied"
|
728 |
msgstr ""
|
729 |
|
730 |
-
#: application/Backend/View/Localization.php:
|
731 |
msgid "Redirected"
|
732 |
msgstr ""
|
733 |
|
734 |
-
#: application/Backend/View/Localization.php:
|
735 |
msgid "Callback"
|
736 |
msgstr ""
|
737 |
|
738 |
-
#: application/Backend/View/Localization.php:
|
739 |
msgid "Allowed"
|
740 |
msgstr ""
|
741 |
|
742 |
-
#: application/Backend/View/Localization.php:
|
743 |
msgid "Generating token..."
|
744 |
msgstr ""
|
745 |
|
746 |
-
#: application/Backend/View/Localization.php:
|
747 |
msgid "_TOTAL_ token(s)"
|
748 |
msgstr ""
|
749 |
|
750 |
-
#: application/Backend/View/Localization.php:
|
751 |
msgid "No JWT tokens have been generated."
|
752 |
msgstr ""
|
753 |
|
754 |
-
#: application/Backend/View/Localization.php:
|
755 |
msgid "Delete Token"
|
756 |
msgstr ""
|
757 |
|
758 |
-
#: application/Backend/View/Localization.php:
|
759 |
msgid "View Token"
|
760 |
msgstr ""
|
761 |
|
762 |
-
#: application/Backend/View/Localization.php:
|
763 |
msgid "Creating..."
|
764 |
msgstr ""
|
765 |
|
766 |
-
#: application/Backend/View/Localization.php:
|
767 |
msgid "Search Service"
|
768 |
msgstr ""
|
769 |
|
770 |
-
#: application/Backend/View/Localization.php:
|
771 |
msgid "_TOTAL_ service(s)"
|
772 |
msgstr ""
|
773 |
|
774 |
-
#: application/Backend/View/Localization.php:
|
775 |
#: application/Backend/tmpl/settings/content.php:19
|
776 |
#: application/Backend/tmpl/settings/core.php:16
|
777 |
-
#: application/Backend/tmpl/settings/security.php:16 media/js/aam.js:
|
778 |
msgid "Enabled"
|
779 |
msgstr ""
|
780 |
|
781 |
-
#: application/Backend/View/Localization.php:
|
782 |
#: application/Backend/tmpl/settings/content.php:19
|
783 |
#: application/Backend/tmpl/settings/core.php:16
|
784 |
-
#: application/Backend/tmpl/settings/security.php:16 media/js/aam.js:
|
785 |
msgid "Disabled"
|
786 |
msgstr ""
|
787 |
|
788 |
-
#: application/Backend/View/Localization.php:
|
789 |
msgid "All settings has been cleared successfully"
|
790 |
msgstr ""
|
791 |
|
792 |
-
#: application/Backend/View/Localization.php:
|
793 |
-
#: application/Backend/tmpl/index.php:
|
794 |
msgid "Clear"
|
795 |
msgstr ""
|
796 |
|
797 |
-
#: application/Backend/View/Localization.php:
|
798 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:102
|
799 |
-
#: application/Backend/tmpl/partial/role-inheritance.php:7 media/js/aam.js:
|
800 |
msgid "Select Role"
|
801 |
msgstr ""
|
802 |
|
803 |
-
#: application/Backend/View/Localization.php:
|
804 |
msgid "Data has been saved to clipboard"
|
805 |
msgstr ""
|
806 |
|
807 |
-
#: application/Backend/View/Localization.php:
|
808 |
msgid "Failed to save data to clipboard"
|
809 |
msgstr ""
|
810 |
|
811 |
-
#: application/Backend/View/Localization.php:
|
812 |
msgid "Operation completed successfully"
|
813 |
msgstr ""
|
814 |
|
@@ -929,8 +945,8 @@ msgstr ""
|
|
929 |
#: application/Backend/View/PostOptionList.php:81
|
930 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:59
|
931 |
#: application/Backend/tmpl/service/jwt.php:136
|
932 |
-
#: application/Backend/tmpl/service/uri.php:130 media/js/aam.js:
|
933 |
-
#: media/js/aam.js:
|
934 |
msgid "Delete"
|
935 |
msgstr ""
|
936 |
|
@@ -964,31 +980,31 @@ msgstr ""
|
|
964 |
msgid "Howdy, %username%"
|
965 |
msgstr ""
|
966 |
|
967 |
-
#: application/Backend/tmpl/index.php:
|
968 |
msgid "Notifications"
|
969 |
msgstr ""
|
970 |
|
971 |
-
#: application/Backend/tmpl/index.php:
|
972 |
msgid "Access"
|
973 |
msgstr ""
|
974 |
|
975 |
-
#: application/Backend/tmpl/index.php:
|
976 |
msgid "Settings"
|
977 |
msgstr ""
|
978 |
|
979 |
-
#: application/Backend/tmpl/index.php:
|
980 |
msgid "Add-Ons"
|
981 |
msgstr ""
|
982 |
|
983 |
-
#: application/Backend/tmpl/index.php:
|
984 |
msgid "Help"
|
985 |
msgstr ""
|
986 |
|
987 |
-
#: application/Backend/tmpl/index.php:
|
988 |
msgid "Reset AAM Settings"
|
989 |
msgstr ""
|
990 |
|
991 |
-
#: application/Backend/tmpl/index.php:
|
992 |
#: application/Backend/tmpl/page/addon-panel.php:70
|
993 |
#: application/Backend/tmpl/page/addon-panel.php:81
|
994 |
#: application/Backend/tmpl/page/addon-panel.php:91
|
@@ -1039,25 +1055,25 @@ msgstr ""
|
|
1039 |
msgid "Close"
|
1040 |
msgstr ""
|
1041 |
|
1042 |
-
#: application/Backend/tmpl/index.php:
|
1043 |
msgid "Clear all settings"
|
1044 |
msgstr ""
|
1045 |
|
1046 |
-
#: application/Backend/tmpl/index.php:
|
1047 |
msgid "All AAM settings will be removed."
|
1048 |
msgstr ""
|
1049 |
|
1050 |
-
#: application/Backend/tmpl/index.php:
|
1051 |
msgid "Cancel"
|
1052 |
msgstr ""
|
1053 |
|
1054 |
-
#: application/Backend/tmpl/index.php:
|
1055 |
msgid ""
|
1056 |
"With the [Enterprise Package] get our dedicated support channel and all the "
|
1057 |
"premium add-ons for [50+ live websites]"
|
1058 |
msgstr ""
|
1059 |
|
1060 |
-
#: application/Backend/tmpl/index.php:
|
1061 |
#: application/Backend/tmpl/page/addon-panel.php:55
|
1062 |
msgid "Read More"
|
1063 |
msgstr ""
|
@@ -1778,7 +1794,7 @@ msgid "URI"
|
|
1778 |
msgstr ""
|
1779 |
|
1780 |
#: application/Backend/tmpl/service/menu.php:163
|
1781 |
-
#: application/Backend/tmpl/service/toolbar.php:101 media/js/aam.js:
|
1782 |
msgid "ID"
|
1783 |
msgstr ""
|
1784 |
|
@@ -2149,7 +2165,7 @@ msgstr ""
|
|
2149 |
msgid "Log Out"
|
2150 |
msgstr ""
|
2151 |
|
2152 |
-
#: application/Core/Jwt/Issuer.php:
|
2153 |
msgid "Token has been revoked"
|
2154 |
msgstr ""
|
2155 |
|
@@ -2169,7 +2185,7 @@ msgid "The policy document is empty"
|
|
2169 |
msgstr ""
|
2170 |
|
2171 |
#: application/Core/Redirect.php:74
|
2172 |
-
#: application/Service/ExtendedCapabilities.php:
|
2173 |
#: application/Service/Route.php:216
|
2174 |
msgid "Access Denied"
|
2175 |
msgstr ""
|
@@ -2216,7 +2232,7 @@ msgid ""
|
|
2216 |
"to them."
|
2217 |
msgstr ""
|
2218 |
|
2219 |
-
#: application/Service/AdminMenu.php:
|
2220 |
msgid "Sorry, you are not allowed to view this page."
|
2221 |
msgstr ""
|
2222 |
|
@@ -2260,22 +2276,22 @@ msgid ""
|
|
2260 |
"granular access control to the backend core features."
|
2261 |
msgstr ""
|
2262 |
|
2263 |
-
#: application/Service/Jwt.php:
|
2264 |
msgid ""
|
2265 |
"Manage the website authentication with JWT Bearer token. The service "
|
2266 |
"facilitates the ability to manage the list of issued JWT token for any user, "
|
2267 |
"revoke them or issue new on demand."
|
2268 |
msgstr ""
|
2269 |
|
2270 |
-
#: application/Service/Jwt.php:
|
2271 |
msgid "Issue JWT Token"
|
2272 |
msgstr ""
|
2273 |
|
2274 |
-
#: application/Service/Jwt.php:
|
2275 |
msgid "JWT token."
|
2276 |
msgstr ""
|
2277 |
|
2278 |
-
#: application/Service/Jwt.php:
|
2279 |
msgid "JWT token is not refreshable"
|
2280 |
msgstr ""
|
2281 |
|
@@ -2435,25 +2451,25 @@ msgstr ""
|
|
2435 |
msgid "Add role"
|
2436 |
msgstr ""
|
2437 |
|
2438 |
-
#: media/js/aam.js:
|
2439 |
-
#: media/js/aam.js:
|
2440 |
msgid "Resetting..."
|
2441 |
msgstr ""
|
2442 |
|
2443 |
-
#: media/js/aam.js:
|
2444 |
msgid "Post"
|
2445 |
msgstr ""
|
2446 |
|
2447 |
-
#: media/js/aam.js:
|
2448 |
msgid "post type"
|
2449 |
msgstr ""
|
2450 |
|
2451 |
-
#: media/js/aam.js:
|
2452 |
-
#: media/js/aam.js:
|
2453 |
msgid "ID:"
|
2454 |
msgstr ""
|
2455 |
|
2456 |
-
#: media/js/aam.js:
|
2457 |
msgid "taxonomy"
|
2458 |
msgstr ""
|
2459 |
|
1 |
msgid ""
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Advanced Access Manager\n"
|
4 |
+
"POT-Creation-Date: 2019-10-31 22:27-0400\n"
|
5 |
"PO-Revision-Date: \n"
|
6 |
"Last-Translator: \n"
|
7 |
"Language-Team: AAMPlugin <support@aamplugin.com>\n"
|
95 |
msgid "Capabilities"
|
96 |
msgstr ""
|
97 |
|
98 |
+
#: application/Backend/Feature/Main/Jwt.php:136
|
99 |
msgid "Failed to register JWT token"
|
100 |
msgstr ""
|
101 |
|
102 |
+
#: application/Backend/Feature/Main/Jwt.php:162
|
103 |
msgid "Failed to revoke JWT token"
|
104 |
msgstr ""
|
105 |
|
106 |
+
#: application/Backend/Feature/Main/Jwt.php:199
|
107 |
+
msgid "Token is no longer valid"
|
108 |
+
msgstr ""
|
109 |
+
|
110 |
+
#: application/Backend/Feature/Main/Jwt.php:227 application/Service/Jwt.php:60
|
111 |
msgid "JWT Tokens"
|
112 |
msgstr ""
|
113 |
|
173 |
msgid "Login page"
|
174 |
msgstr ""
|
175 |
|
176 |
+
#: application/Backend/Feature/Main/Post.php:1007
|
177 |
#: application/Service/Content.php:72
|
178 |
msgid "Posts & Terms"
|
179 |
msgstr ""
|
294 |
msgid "Cannot manage yourself"
|
295 |
msgstr ""
|
296 |
|
297 |
+
#: application/Backend/Feature/Subject/User.php:227
|
298 |
+
#: application/Backend/Feature/Subject/User.php:252
|
299 |
+
#: application/Backend/View/Localization.php:142 media/js/aam.js:4664
|
300 |
msgid "Unexpected application error"
|
301 |
msgstr ""
|
302 |
|
303 |
+
#: application/Backend/Manager.php:116
|
304 |
+
#, php-format
|
305 |
+
msgid ""
|
306 |
+
"There was at least one error detected with the automated migration script. "
|
307 |
+
"%sDownload the log%s for more details and contact our support at "
|
308 |
+
"%ssupport@aamplugin.com%s for further assistance."
|
309 |
+
msgstr ""
|
310 |
+
|
311 |
+
#: application/Backend/Manager.php:272
|
312 |
msgid "[Help us] to be more noticeable and submit your review"
|
313 |
msgstr ""
|
314 |
|
316 |
msgid "You are not allowed to manage AAM subjects"
|
317 |
msgstr ""
|
318 |
|
319 |
+
#: application/Backend/View/Localization.php:32 media/js/aam.js:1993
|
320 |
msgid "Search Capability"
|
321 |
msgstr ""
|
322 |
|
323 |
+
#: application/Backend/View/Localization.php:33 media/js/aam.js:1994
|
324 |
msgid "_TOTAL_ capability(s)"
|
325 |
msgstr ""
|
326 |
|
327 |
#: application/Backend/View/Localization.php:34 media/js/aam.js:410
|
328 |
+
#: media/js/aam.js:471 media/js/aam.js:1030 media/js/aam.js:2141
|
329 |
+
#: media/js/aam.js:2183 media/js/aam.js:2382 media/js/aam.js:2401
|
330 |
+
#: media/js/aam.js:2471 media/js/aam.js:2493 media/js/aam.js:2512
|
331 |
+
#: media/js/aam.js:3478
|
332 |
msgid "Saving..."
|
333 |
msgstr ""
|
334 |
|
335 |
+
#: application/Backend/View/Localization.php:35
|
336 |
+
msgid "Execute Migration"
|
337 |
+
msgstr ""
|
338 |
+
|
339 |
+
#: application/Backend/View/Localization.php:36 media/js/aam.js:2149
|
340 |
msgid "Failed to add new capability"
|
341 |
msgstr ""
|
342 |
|
343 |
+
#: application/Backend/View/Localization.php:37
|
344 |
msgid "Application error"
|
345 |
msgstr ""
|
346 |
|
347 |
+
#: application/Backend/View/Localization.php:38 media/js/aam.js:2157
|
348 |
msgid "Add Capability"
|
349 |
msgstr ""
|
350 |
|
351 |
+
#: application/Backend/View/Localization.php:39
|
352 |
+
#: application/Backend/tmpl/service/capability.php:76 media/js/aam.js:2199
|
353 |
msgid "Update Capability"
|
354 |
msgstr ""
|
355 |
|
356 |
+
#: application/Backend/View/Localization.php:40
|
357 |
#: application/Backend/tmpl/service/menu.php:93
|
358 |
+
#: application/Backend/tmpl/service/toolbar.php:70 media/js/aam.js:1477
|
359 |
+
#: media/js/aam.js:1608
|
360 |
msgid "Show Menu"
|
361 |
msgstr ""
|
362 |
|
363 |
+
#: application/Backend/View/Localization.php:41
|
364 |
#: application/Backend/tmpl/service/menu.php:97
|
365 |
+
#: application/Backend/tmpl/service/toolbar.php:74 media/js/aam.js:1487
|
366 |
+
#: media/js/aam.js:1618
|
367 |
msgid "Restrict Menu"
|
368 |
msgstr ""
|
369 |
|
370 |
+
#: application/Backend/View/Localization.php:42 media/js/aam.js:1788
|
371 |
msgid "Failed to retrieve mataboxes"
|
372 |
msgstr ""
|
373 |
|
374 |
+
#: application/Backend/View/Localization.php:43 media/js/aam.js:2652
|
375 |
+
#: media/js/aam.js:3365 media/js/aam.js:3557 media/js/aam.js:3786
|
376 |
msgid "Search"
|
377 |
msgstr ""
|
378 |
|
379 |
+
#: application/Backend/View/Localization.php:44 media/js/aam.js:2653
|
380 |
msgid "_TOTAL_ object(s)"
|
381 |
msgstr ""
|
382 |
|
383 |
+
#: application/Backend/View/Localization.php:45
|
384 |
msgid "Failed"
|
385 |
msgstr ""
|
386 |
|
387 |
+
#: application/Backend/View/Localization.php:46 media/js/aam.js:64
|
388 |
+
#: media/js/aam.js:4295
|
389 |
msgid "Loading..."
|
390 |
msgstr ""
|
391 |
|
392 |
+
#: application/Backend/View/Localization.php:47 media/js/aam.js:69
|
393 |
msgid "No role"
|
394 |
msgstr ""
|
395 |
|
396 |
+
#: application/Backend/View/Localization.php:48 media/js/aam.js:149
|
397 |
msgid "Create New Role"
|
398 |
msgstr ""
|
399 |
|
400 |
+
#: application/Backend/View/Localization.php:49
|
401 |
msgid "Search Role"
|
402 |
msgstr ""
|
403 |
|
404 |
+
#: application/Backend/View/Localization.php:50 media/js/aam.js:133
|
405 |
msgid "_TOTAL_ role(s)"
|
406 |
msgstr ""
|
407 |
|
408 |
+
#: application/Backend/View/Localization.php:51
|
409 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:19
|
410 |
#: application/Backend/tmpl/service/capability.php:30
|
411 |
#: application/Backend/tmpl/service/capability.php:64
|
412 |
+
#: application/Backend/tmpl/service/jwt.php:84 media/js/aam.js:1320
|
413 |
+
#: media/js/aam.js:3568 media/js/aam.js:3801 media/js/aam.js:3886
|
414 |
msgid "Create"
|
415 |
msgstr ""
|
416 |
|
417 |
+
#: application/Backend/View/Localization.php:52
|
418 |
#: application/Backend/tmpl/page/subject-panel.php:17 media/js/aam.js:171
|
419 |
msgid "Users"
|
420 |
msgstr ""
|
421 |
|
422 |
+
#: application/Backend/View/Localization.php:53
|
423 |
msgid "Failed to add new role"
|
424 |
msgstr ""
|
425 |
|
426 |
+
#: application/Backend/View/Localization.php:54
|
427 |
msgid "Add Role"
|
428 |
msgstr ""
|
429 |
|
430 |
+
#: application/Backend/View/Localization.php:55 media/js/aam.js:478
|
431 |
msgid "Failed to update role"
|
432 |
msgstr ""
|
433 |
|
434 |
+
#: application/Backend/View/Localization.php:56
|
435 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:41
|
436 |
#: application/Backend/tmpl/service/capability.php:90 media/js/aam.js:487
|
437 |
msgid "Update"
|
438 |
msgstr ""
|
439 |
|
440 |
+
#: application/Backend/View/Localization.php:57
|
441 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:110
|
442 |
#: application/Backend/tmpl/partial/post-access-form.php:89
|
443 |
+
#: media/js/aam.js:1077 media/js/aam.js:2455
|
444 |
msgid "Reset"
|
445 |
msgstr ""
|
446 |
|
447 |
+
#: application/Backend/View/Localization.php:58
|
448 |
msgid "Update..."
|
449 |
msgstr ""
|
450 |
|
451 |
+
#: application/Backend/View/Localization.php:59 media/js/aam.js:510
|
452 |
+
#: media/js/aam.js:1942 media/js/aam.js:3516 media/js/aam.js:3904
|
453 |
msgid "Deleting..."
|
454 |
msgstr ""
|
455 |
|
456 |
+
#: application/Backend/View/Localization.php:60 media/js/aam.js:516
|
457 |
msgid "Failed to delete role"
|
458 |
msgstr ""
|
459 |
|
460 |
+
#: application/Backend/View/Localization.php:61
|
461 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:53
|
462 |
msgid "Delete Role"
|
463 |
msgstr ""
|
464 |
|
465 |
+
#: application/Backend/View/Localization.php:62 media/js/aam.js:610
|
466 |
msgid "Failed to lock user"
|
467 |
msgstr ""
|
468 |
|
469 |
+
#: application/Backend/View/Localization.php:63 media/js/aam.js:702
|
470 |
msgid "Search user"
|
471 |
msgstr ""
|
472 |
|
473 |
+
#: application/Backend/View/Localization.php:64 media/js/aam.js:2444
|
474 |
msgid "Counter was reset successfully"
|
475 |
msgstr ""
|
476 |
|
477 |
+
#: application/Backend/View/Localization.php:65 media/js/aam.js:703
|
478 |
msgid "_TOTAL_ user(s)"
|
479 |
msgstr ""
|
480 |
|
481 |
+
#: application/Backend/View/Localization.php:66 media/js/aam.js:718
|
482 |
msgid "Create New User"
|
483 |
msgstr ""
|
484 |
|
485 |
+
#: application/Backend/View/Localization.php:67
|
486 |
+
#: application/Backend/tmpl/page/subject-panel.php:38 media/js/aam.js:766
|
487 |
msgid "Role"
|
488 |
msgstr ""
|
489 |
|
490 |
+
#: application/Backend/View/Localization.php:68
|
491 |
+
#: application/Core/Subject/Default.php:36 media/js/aam.js:1190
|
492 |
msgid "All Users, Roles and Visitor"
|
493 |
msgstr ""
|
494 |
|
495 |
+
#: application/Backend/View/Localization.php:69 media/js/aam.js:1161
|
496 |
+
#: media/js/aam.js:1236 media/js/aam.js:4264
|
497 |
msgid "Failed to apply policy changes"
|
498 |
msgstr ""
|
499 |
|
500 |
+
#: application/Backend/View/Localization.php:70
|
501 |
#: application/Backend/tmpl/partial/visitor-principal-subject-tab.php:14
|
502 |
+
#: media/js/aam.js:1155 media/js/aam.js:1164
|
503 |
msgid "Attach Policy To Visitors"
|
504 |
msgstr ""
|
505 |
|
506 |
+
#: application/Backend/View/Localization.php:71
|
507 |
#: application/Backend/tmpl/partial/visitor-principal-subject-tab.php:12
|
508 |
+
#: media/js/aam.js:1153 media/js/aam.js:1166
|
509 |
msgid "Detach Policy From Visitors"
|
510 |
msgstr ""
|
511 |
|
512 |
+
#: application/Backend/View/Localization.php:72 media/js/aam.js:649
|
513 |
+
#: media/js/aam.js:3692
|
514 |
msgid "Generating URL..."
|
515 |
msgstr ""
|
516 |
|
517 |
+
#: application/Backend/View/Localization.php:73
|
518 |
+
#: application/Core/Subject/Visitor.php:43 media/js/aam.js:1116
|
519 |
msgid "Anonymous"
|
520 |
msgstr ""
|
521 |
|
522 |
+
#: application/Backend/View/Localization.php:74 media/js/aam.js:1142
|
523 |
+
#: media/js/aam.js:1217 media/js/aam.js:1808 media/js/aam.js:4110
|
524 |
msgid "Processing..."
|
525 |
msgstr ""
|
526 |
|
527 |
+
#: application/Backend/View/Localization.php:75 media/js/aam.js:727
|
528 |
msgid "Loading roles..."
|
529 |
msgstr ""
|
530 |
|
531 |
+
#: application/Backend/View/Localization.php:76 media/js/aam.js:659
|
532 |
+
#: media/js/aam.js:3703
|
533 |
msgid "Failed to generate JWT token"
|
534 |
msgstr ""
|
535 |
|
536 |
+
#: application/Backend/View/Localization.php:77 media/js/aam.js:1910
|
537 |
msgid "Failed to process request"
|
538 |
msgstr ""
|
539 |
|
540 |
+
#: application/Backend/View/Localization.php:78
|
541 |
msgid "Current user"
|
542 |
msgstr ""
|
543 |
|
544 |
+
#: application/Backend/View/Localization.php:79
|
545 |
msgid "Current role"
|
546 |
msgstr ""
|
547 |
|
548 |
+
#: application/Backend/View/Localization.php:80 media/js/aam.js:2842
|
549 |
msgid "Manage Access"
|
550 |
msgstr ""
|
551 |
|
552 |
+
#: application/Backend/View/Localization.php:81 media/js/aam.js:744
|
553 |
msgid "Filter by role"
|
554 |
msgstr ""
|
555 |
|
556 |
+
#: application/Backend/View/Localization.php:82
|
557 |
+
#: application/Backend/View/PostOptionList.php:76 media/js/aam.js:2854
|
558 |
msgid "Edit"
|
559 |
msgstr ""
|
560 |
|
561 |
+
#: application/Backend/View/Localization.php:83
|
562 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:111
|
563 |
#: application/Backend/tmpl/partial/post-access-form.php:60
|
564 |
#: application/Backend/tmpl/partial/post-access-form.php:90
|
565 |
#: application/Backend/tmpl/partial/post-access-form.php:163
|
566 |
#: application/Backend/tmpl/partial/post-access-form.php:184
|
567 |
#: application/Backend/tmpl/partial/post-access-form.php:205
|
568 |
+
#: application/Backend/tmpl/service/uri.php:108 media/js/aam.js:1044
|
569 |
+
#: media/js/aam.js:3495
|
570 |
msgid "Save"
|
571 |
msgstr ""
|
572 |
|
573 |
+
#: application/Backend/View/Localization.php:84 media/js/aam.js:217
|
574 |
msgid "Manage role"
|
575 |
msgstr ""
|
576 |
|
577 |
+
#: application/Backend/View/Localization.php:85 media/js/aam.js:238
|
578 |
msgid "Edit role"
|
579 |
msgstr ""
|
580 |
|
581 |
+
#: application/Backend/View/Localization.php:86 media/js/aam.js:291
|
582 |
#: media/js/aam.js:524
|
583 |
msgid "Delete role"
|
584 |
msgstr ""
|
585 |
|
586 |
+
#: application/Backend/View/Localization.php:87 media/js/aam.js:262
|
587 |
msgid "Clone role"
|
588 |
msgstr ""
|
589 |
|
590 |
+
#: application/Backend/View/Localization.php:88 media/js/aam.js:805
|
591 |
msgid "Manage user"
|
592 |
msgstr ""
|
593 |
|
594 |
+
#: application/Backend/View/Localization.php:89 media/js/aam.js:854
|
595 |
msgid "Edit user"
|
596 |
msgstr ""
|
597 |
|
598 |
+
#: application/Backend/View/Localization.php:90 media/js/aam.js:605
|
599 |
+
#: media/js/aam.js:606 media/js/aam.js:875 media/js/aam.js:886
|
600 |
msgid "Lock user"
|
601 |
msgstr ""
|
602 |
|
603 |
+
#: application/Backend/View/Localization.php:91 media/js/aam.js:599
|
604 |
+
#: media/js/aam.js:600 media/js/aam.js:899 media/js/aam.js:910
|
605 |
msgid "Unlock user"
|
606 |
msgstr ""
|
607 |
|
608 |
+
#: application/Backend/View/Localization.php:92 media/js/aam.js:1904
|
609 |
msgid "WordPress core does not allow to grant this capability"
|
610 |
msgstr ""
|
611 |
|
612 |
+
#: application/Backend/View/Localization.php:93 media/js/aam.js:1228
|
613 |
+
#: media/js/aam.js:1241
|
614 |
msgid "Detach Policy From Everybody"
|
615 |
msgstr ""
|
616 |
|
617 |
+
#: application/Backend/View/Localization.php:94 media/js/aam.js:1230
|
618 |
+
#: media/js/aam.js:1239
|
619 |
msgid "Attach Policy To Everybody"
|
620 |
msgstr ""
|
621 |
|
622 |
+
#: application/Backend/View/Localization.php:95 media/js/aam.js:1309
|
623 |
msgid "Search Policy"
|
624 |
msgstr ""
|
625 |
|
626 |
+
#: application/Backend/View/Localization.php:96 media/js/aam.js:1310
|
627 |
msgid "_TOTAL_ Policies"
|
628 |
msgstr ""
|
629 |
|
630 |
+
#: application/Backend/View/Localization.php:97 media/js/aam.js:1343
|
631 |
msgid "Apply Policy"
|
632 |
msgstr ""
|
633 |
|
634 |
+
#: application/Backend/View/Localization.php:98 media/js/aam.js:1363
|
635 |
msgid "Revoke Policy"
|
636 |
msgstr ""
|
637 |
|
638 |
+
#: application/Backend/View/Localization.php:99
|
639 |
+
#: application/Service/AccessPolicy.php:170 media/js/aam.js:1380
|
640 |
msgid "Edit Policy"
|
641 |
msgstr ""
|
642 |
|
643 |
+
#: application/Backend/View/Localization.php:100
|
644 |
#: application/Backend/tmpl/service/menu.php:79
|
645 |
+
#: application/Backend/tmpl/service/toolbar.php:60 media/js/aam.js:1517
|
646 |
msgid "Uncheck to allow"
|
647 |
msgstr ""
|
648 |
|
649 |
+
#: application/Backend/View/Localization.php:101
|
650 |
#: application/Backend/tmpl/service/menu.php:79
|
651 |
+
#: application/Backend/tmpl/service/toolbar.php:60 media/js/aam.js:1519
|
652 |
msgid "Check to restrict"
|
653 |
msgstr ""
|
654 |
|
655 |
+
#: application/Backend/View/Localization.php:102
|
656 |
+
#: application/Backend/tmpl/service/metabox.php:78 media/js/aam.js:1653
|
657 |
+
#: media/js/aam.js:1842
|
658 |
msgid "Uncheck to show"
|
659 |
msgstr ""
|
660 |
|
661 |
+
#: application/Backend/View/Localization.php:103
|
662 |
+
#: application/Backend/tmpl/service/metabox.php:78 media/js/aam.js:1655
|
663 |
+
#: media/js/aam.js:1844
|
664 |
msgid "Check to hide"
|
665 |
msgstr ""
|
666 |
|
667 |
+
#: application/Backend/View/Localization.php:104
|
668 |
+
#: application/Backend/tmpl/service/metabox.php:114 media/js/aam.js:1811
|
669 |
msgid "Initialize"
|
670 |
msgstr ""
|
671 |
|
672 |
+
#: application/Backend/View/Localization.php:105 media/js/aam.js:1996
|
673 |
msgid "No capabilities"
|
674 |
msgstr ""
|
675 |
|
676 |
+
#: application/Backend/View/Localization.php:106 media/js/aam.js:2674
|
677 |
msgid "Post Type"
|
678 |
msgstr ""
|
679 |
|
680 |
+
#: application/Backend/View/Localization.php:107 media/js/aam.js:2679
|
681 |
msgid "Hierarchical Taxonomy"
|
682 |
msgstr ""
|
683 |
|
684 |
+
#: application/Backend/View/Localization.php:108 media/js/aam.js:2684
|
685 |
msgid "Hierarchical Term"
|
686 |
msgstr ""
|
687 |
|
688 |
+
#: application/Backend/View/Localization.php:109 media/js/aam.js:2689
|
689 |
msgid "Tag Taxonomy"
|
690 |
msgstr ""
|
691 |
|
692 |
+
#: application/Backend/View/Localization.php:110 media/js/aam.js:2694
|
693 |
msgid "Tag"
|
694 |
msgstr ""
|
695 |
|
696 |
+
#: application/Backend/View/Localization.php:111 media/js/aam.js:2705
|
697 |
msgid "Customized Settings"
|
698 |
msgstr ""
|
699 |
|
700 |
+
#: application/Backend/View/Localization.php:112 media/js/aam.js:2775
|
701 |
+
#: media/js/aam.js:2797
|
702 |
msgid "Parent"
|
703 |
msgstr ""
|
704 |
|
705 |
+
#: application/Backend/View/Localization.php:113 media/js/aam.js:2828
|
706 |
msgid "Drill-Down"
|
707 |
msgstr ""
|
708 |
|
709 |
+
#: application/Backend/View/Localization.php:114 media/js/aam.js:3366
|
710 |
msgid "_TOTAL_ route(s)"
|
711 |
msgstr ""
|
712 |
|
713 |
+
#: application/Backend/View/Localization.php:115 media/js/aam.js:3368
|
714 |
msgid "No API endpoints found. You might have APIs disabled."
|
715 |
msgstr ""
|
716 |
|
717 |
+
#: application/Backend/View/Localization.php:116 media/js/aam.js:3369
|
718 |
+
#: media/js/aam.js:3790 media/js/aam.js:4064
|
719 |
msgid "Nothing to show"
|
720 |
msgstr ""
|
721 |
|
722 |
+
#: application/Backend/View/Localization.php:117 media/js/aam.js:3486
|
723 |
msgid "Failed to save URI rule"
|
724 |
msgstr ""
|
725 |
|
726 |
+
#: application/Backend/View/Localization.php:118 media/js/aam.js:3522
|
727 |
msgid "Failed to delete URI rule"
|
728 |
msgstr ""
|
729 |
|
730 |
+
#: application/Backend/View/Localization.php:119 media/js/aam.js:3558
|
731 |
msgid "_TOTAL_ URI(s)"
|
732 |
msgstr ""
|
733 |
|
734 |
+
#: application/Backend/View/Localization.php:120 media/js/aam.js:3597
|
735 |
msgid "Edit Rule"
|
736 |
msgstr ""
|
737 |
|
738 |
+
#: application/Backend/View/Localization.php:121 media/js/aam.js:3609
|
739 |
msgid "Delete Rule"
|
740 |
msgstr ""
|
741 |
|
742 |
+
#: application/Backend/View/Localization.php:122 media/js/aam.js:3624
|
743 |
msgid "Denied"
|
744 |
msgstr ""
|
745 |
|
746 |
+
#: application/Backend/View/Localization.php:123 media/js/aam.js:3631
|
747 |
msgid "Redirected"
|
748 |
msgstr ""
|
749 |
|
750 |
+
#: application/Backend/View/Localization.php:124 media/js/aam.js:3636
|
751 |
msgid "Callback"
|
752 |
msgstr ""
|
753 |
|
754 |
+
#: application/Backend/View/Localization.php:125 media/js/aam.js:3641
|
755 |
msgid "Allowed"
|
756 |
msgstr ""
|
757 |
|
758 |
+
#: application/Backend/View/Localization.php:126 media/js/aam.js:3688
|
759 |
msgid "Generating token..."
|
760 |
msgstr ""
|
761 |
|
762 |
+
#: application/Backend/View/Localization.php:127 media/js/aam.js:3787
|
763 |
msgid "_TOTAL_ token(s)"
|
764 |
msgstr ""
|
765 |
|
766 |
+
#: application/Backend/View/Localization.php:128 media/js/aam.js:3789
|
767 |
msgid "No JWT tokens have been generated."
|
768 |
msgstr ""
|
769 |
|
770 |
+
#: application/Backend/View/Localization.php:129 media/js/aam.js:3834
|
771 |
msgid "Delete Token"
|
772 |
msgstr ""
|
773 |
|
774 |
+
#: application/Backend/View/Localization.php:130 media/js/aam.js:3847
|
775 |
msgid "View Token"
|
776 |
msgstr ""
|
777 |
|
778 |
+
#: application/Backend/View/Localization.php:131 media/js/aam.js:3872
|
779 |
msgid "Creating..."
|
780 |
msgstr ""
|
781 |
|
782 |
+
#: application/Backend/View/Localization.php:132 media/js/aam.js:4061
|
783 |
msgid "Search Service"
|
784 |
msgstr ""
|
785 |
|
786 |
+
#: application/Backend/View/Localization.php:133 media/js/aam.js:4062
|
787 |
msgid "_TOTAL_ service(s)"
|
788 |
msgstr ""
|
789 |
|
790 |
+
#: application/Backend/View/Localization.php:134
|
791 |
#: application/Backend/tmpl/settings/content.php:19
|
792 |
#: application/Backend/tmpl/settings/core.php:16
|
793 |
+
#: application/Backend/tmpl/settings/security.php:16 media/js/aam.js:4074
|
794 |
msgid "Enabled"
|
795 |
msgstr ""
|
796 |
|
797 |
+
#: application/Backend/View/Localization.php:135
|
798 |
#: application/Backend/tmpl/settings/content.php:19
|
799 |
#: application/Backend/tmpl/settings/core.php:16
|
800 |
+
#: application/Backend/tmpl/settings/security.php:16 media/js/aam.js:4074
|
801 |
msgid "Disabled"
|
802 |
msgstr ""
|
803 |
|
804 |
+
#: application/Backend/View/Localization.php:136 media/js/aam.js:4116
|
805 |
msgid "All settings has been cleared successfully"
|
806 |
msgstr ""
|
807 |
|
808 |
+
#: application/Backend/View/Localization.php:137
|
809 |
+
#: application/Backend/tmpl/index.php:95 media/js/aam.js:4128
|
810 |
msgid "Clear"
|
811 |
msgstr ""
|
812 |
|
813 |
+
#: application/Backend/View/Localization.php:138
|
814 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:102
|
815 |
+
#: application/Backend/tmpl/partial/role-inheritance.php:7 media/js/aam.js:4300
|
816 |
msgid "Select Role"
|
817 |
msgstr ""
|
818 |
|
819 |
+
#: application/Backend/View/Localization.php:139 media/js/aam.js:4586
|
820 |
msgid "Data has been saved to clipboard"
|
821 |
msgstr ""
|
822 |
|
823 |
+
#: application/Backend/View/Localization.php:140 media/js/aam.js:4590
|
824 |
msgid "Failed to save data to clipboard"
|
825 |
msgstr ""
|
826 |
|
827 |
+
#: application/Backend/View/Localization.php:141 media/js/aam.js:4660
|
828 |
msgid "Operation completed successfully"
|
829 |
msgstr ""
|
830 |
|
945 |
#: application/Backend/View/PostOptionList.php:81
|
946 |
#: application/Backend/tmpl/page/subject-panel-advanced.php:59
|
947 |
#: application/Backend/tmpl/service/jwt.php:136
|
948 |
+
#: application/Backend/tmpl/service/uri.php:130 media/js/aam.js:3530
|
949 |
+
#: media/js/aam.js:3918
|
950 |
msgid "Delete"
|
951 |
msgstr ""
|
952 |
|
980 |
msgid "Howdy, %username%"
|
981 |
msgstr ""
|
982 |
|
983 |
+
#: application/Backend/tmpl/index.php:25
|
984 |
msgid "Notifications"
|
985 |
msgstr ""
|
986 |
|
987 |
+
#: application/Backend/tmpl/index.php:47
|
988 |
msgid "Access"
|
989 |
msgstr ""
|
990 |
|
991 |
+
#: application/Backend/tmpl/index.php:52
|
992 |
msgid "Settings"
|
993 |
msgstr ""
|
994 |
|
995 |
+
#: application/Backend/tmpl/index.php:58
|
996 |
msgid "Add-Ons"
|
997 |
msgstr ""
|
998 |
|
999 |
+
#: application/Backend/tmpl/index.php:64
|
1000 |
msgid "Help"
|
1001 |
msgstr ""
|
1002 |
|
1003 |
+
#: application/Backend/tmpl/index.php:78
|
1004 |
msgid "Reset AAM Settings"
|
1005 |
msgstr ""
|
1006 |
|
1007 |
+
#: application/Backend/tmpl/index.php:88
|
1008 |
#: application/Backend/tmpl/page/addon-panel.php:70
|
1009 |
#: application/Backend/tmpl/page/addon-panel.php:81
|
1010 |
#: application/Backend/tmpl/page/addon-panel.php:91
|
1055 |
msgid "Close"
|
1056 |
msgstr ""
|
1057 |
|
1058 |
+
#: application/Backend/tmpl/index.php:89
|
1059 |
msgid "Clear all settings"
|
1060 |
msgstr ""
|
1061 |
|
1062 |
+
#: application/Backend/tmpl/index.php:92
|
1063 |
msgid "All AAM settings will be removed."
|
1064 |
msgstr ""
|
1065 |
|
1066 |
+
#: application/Backend/tmpl/index.php:96
|
1067 |
msgid "Cancel"
|
1068 |
msgstr ""
|
1069 |
|
1070 |
+
#: application/Backend/tmpl/index.php:108
|
1071 |
msgid ""
|
1072 |
"With the [Enterprise Package] get our dedicated support channel and all the "
|
1073 |
"premium add-ons for [50+ live websites]"
|
1074 |
msgstr ""
|
1075 |
|
1076 |
+
#: application/Backend/tmpl/index.php:109
|
1077 |
#: application/Backend/tmpl/page/addon-panel.php:55
|
1078 |
msgid "Read More"
|
1079 |
msgstr ""
|
1794 |
msgstr ""
|
1795 |
|
1796 |
#: application/Backend/tmpl/service/menu.php:163
|
1797 |
+
#: application/Backend/tmpl/service/toolbar.php:101 media/js/aam.js:766
|
1798 |
msgid "ID"
|
1799 |
msgstr ""
|
1800 |
|
2165 |
msgid "Log Out"
|
2166 |
msgstr ""
|
2167 |
|
2168 |
+
#: application/Core/Jwt/Issuer.php:60
|
2169 |
msgid "Token has been revoked"
|
2170 |
msgstr ""
|
2171 |
|
2185 |
msgstr ""
|
2186 |
|
2187 |
#: application/Core/Redirect.php:74
|
2188 |
+
#: application/Service/ExtendedCapabilities.php:81
|
2189 |
#: application/Service/Route.php:216
|
2190 |
msgid "Access Denied"
|
2191 |
msgstr ""
|
2232 |
"to them."
|
2233 |
msgstr ""
|
2234 |
|
2235 |
+
#: application/Service/AdminMenu.php:277
|
2236 |
msgid "Sorry, you are not allowed to view this page."
|
2237 |
msgstr ""
|
2238 |
|
2276 |
"granular access control to the backend core features."
|
2277 |
msgstr ""
|
2278 |
|
2279 |
+
#: application/Service/Jwt.php:61
|
2280 |
msgid ""
|
2281 |
"Manage the website authentication with JWT Bearer token. The service "
|
2282 |
"facilitates the ability to manage the list of issued JWT token for any user, "
|
2283 |
"revoke them or issue new on demand."
|
2284 |
msgstr ""
|
2285 |
|
2286 |
+
#: application/Service/Jwt.php:109
|
2287 |
msgid "Issue JWT Token"
|
2288 |
msgstr ""
|
2289 |
|
2290 |
+
#: application/Service/Jwt.php:156 application/Service/Jwt.php:168
|
2291 |
msgid "JWT token."
|
2292 |
msgstr ""
|
2293 |
|
2294 |
+
#: application/Service/Jwt.php:235
|
2295 |
msgid "JWT token is not refreshable"
|
2296 |
msgstr ""
|
2297 |
|
2451 |
msgid "Add role"
|
2452 |
msgstr ""
|
2453 |
|
2454 |
+
#: media/js/aam.js:1063 media/js/aam.js:2364 media/js/aam.js:2435
|
2455 |
+
#: media/js/aam.js:4700
|
2456 |
msgid "Resetting..."
|
2457 |
msgstr ""
|
2458 |
|
2459 |
+
#: media/js/aam.js:2669
|
2460 |
msgid "Post"
|
2461 |
msgstr ""
|
2462 |
|
2463 |
+
#: media/js/aam.js:2735
|
2464 |
msgid "post type"
|
2465 |
msgstr ""
|
2466 |
|
2467 |
+
#: media/js/aam.js:2740 media/js/aam.js:2766 media/js/aam.js:2779
|
2468 |
+
#: media/js/aam.js:2788 media/js/aam.js:2801
|
2469 |
msgid "ID:"
|
2470 |
msgstr ""
|
2471 |
|
2472 |
+
#: media/js/aam.js:2762
|
2473 |
msgid "taxonomy"
|
2474 |
msgstr ""
|
2475 |
|
media/css/aam.css
CHANGED
@@ -228,6 +228,7 @@ html, body {
|
|
228 |
|
229 |
.wrap {
|
230 |
position: relative;
|
|
|
231 |
}
|
232 |
|
233 |
.inner-sm {
|
228 |
|
229 |
.wrap {
|
230 |
position: relative;
|
231 |
+
min-height: calc(100vh - 108px);
|
232 |
}
|
233 |
|
234 |
.inner-sm {
|
media/js/aam.js
CHANGED
@@ -629,7 +629,7 @@
|
|
629 |
}
|
630 |
|
631 |
if (trigger.action === 'change-role') {
|
632 |
-
trigger.
|
633 |
}
|
634 |
|
635 |
$.ajax(getLocal().ajaxurl, {
|
@@ -642,7 +642,8 @@
|
|
642 |
subject: 'user',
|
643 |
subjectId: $('#reset-user-expiration-btn').attr('data-user-id'),
|
644 |
expires: $('#user-expires').val(),
|
645 |
-
trigger: trigger
|
|
|
646 |
},
|
647 |
beforeSend: function () {
|
648 |
$('#login-url-preview').val(getAAM().__('Generating URL...'));
|
@@ -3679,11 +3680,17 @@
|
|
3679 |
subject: getAAM().getSubject().type,
|
3680 |
subjectId: getAAM().getSubject().id,
|
3681 |
expires: expires,
|
3682 |
-
refreshable: refreshable
|
|
|
3683 |
},
|
3684 |
beforeSend: function () {
|
3685 |
-
$('#jwt-token-preview').val(
|
3686 |
-
|
|
|
|
|
|
|
|
|
|
|
3687 |
},
|
3688 |
success: function (response) {
|
3689 |
if (response.status === 'success') {
|
@@ -3952,54 +3959,6 @@
|
|
3952 |
});
|
3953 |
}
|
3954 |
|
3955 |
-
/**
|
3956 |
-
*
|
3957 |
-
* @param {*} base64
|
3958 |
-
*/
|
3959 |
-
function base64ToArrayBuffer(base64) {
|
3960 |
-
const binaryString = window.atob(base64); // Comment this if not using base64
|
3961 |
-
const bytes = new Uint8Array(binaryString.length);
|
3962 |
-
|
3963 |
-
return bytes.map((byte, i) => binaryString.charCodeAt(i));
|
3964 |
-
}
|
3965 |
-
|
3966 |
-
/**
|
3967 |
-
*
|
3968 |
-
* @param {*} data
|
3969 |
-
* @param {*} filename
|
3970 |
-
* @param {*} mime
|
3971 |
-
*/
|
3972 |
-
function download(data, filename, mime) {
|
3973 |
-
var blob = new Blob([data], { type: mime || 'application/octet-stream' });
|
3974 |
-
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
3975 |
-
// IE workaround for "HTML7007: One or more blob URLs were
|
3976 |
-
// revoked by closing the blob for which they were created.
|
3977 |
-
// These URLs will no longer resolve as the data backing
|
3978 |
-
// the URL has been freed."
|
3979 |
-
window.navigator.msSaveBlob(blob, filename);
|
3980 |
-
}
|
3981 |
-
else {
|
3982 |
-
var blobURL = window.URL.createObjectURL(blob);
|
3983 |
-
var tempLink = document.createElement('a');
|
3984 |
-
tempLink.style.display = 'none';
|
3985 |
-
tempLink.href = blobURL;
|
3986 |
-
tempLink.setAttribute('download', filename);
|
3987 |
-
|
3988 |
-
// Safari thinks _blank anchor are pop ups. We only want to set _blank
|
3989 |
-
// target if the browser does not support the HTML5 download attribute.
|
3990 |
-
// This allows you to download files in desktop safari if pop up blocking
|
3991 |
-
// is enabled.
|
3992 |
-
if (typeof tempLink.download === 'undefined') {
|
3993 |
-
tempLink.setAttribute('target', '_blank');
|
3994 |
-
}
|
3995 |
-
|
3996 |
-
document.body.appendChild(tempLink);
|
3997 |
-
tempLink.click();
|
3998 |
-
document.body.removeChild(tempLink);
|
3999 |
-
window.URL.revokeObjectURL(blobURL);
|
4000 |
-
}
|
4001 |
-
}
|
4002 |
-
|
4003 |
/**
|
4004 |
*
|
4005 |
* @returns {undefined}
|
@@ -4024,8 +3983,8 @@
|
|
4024 |
$('i', _this).attr('class', 'icon-spin4 animate-spin');
|
4025 |
downloadExtension(license, function (response) {
|
4026 |
if (response) {
|
4027 |
-
|
4028 |
-
|
4029 |
response.title + '.zip',
|
4030 |
'application/zip'
|
4031 |
);
|
@@ -4567,6 +4526,17 @@
|
|
4567 |
//load the UI javascript support
|
4568 |
UI();
|
4569 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4570 |
//initialize help context
|
4571 |
$('.aam-help-menu').each(function () {
|
4572 |
var target = $(this).data('target');
|
@@ -4751,6 +4721,45 @@
|
|
4751 |
return (getLocal().ui === type);
|
4752 |
};
|
4753 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4754 |
/**
|
4755 |
*
|
4756 |
* @returns {aamLocal}
|
629 |
}
|
630 |
|
631 |
if (trigger.action === 'change-role') {
|
632 |
+
trigger.meta = $('#expiration-change-role').val();
|
633 |
}
|
634 |
|
635 |
$.ajax(getLocal().ajaxurl, {
|
642 |
subject: 'user',
|
643 |
subjectId: $('#reset-user-expiration-btn').attr('data-user-id'),
|
644 |
expires: $('#user-expires').val(),
|
645 |
+
trigger: trigger,
|
646 |
+
register: true
|
647 |
},
|
648 |
beforeSend: function () {
|
649 |
$('#login-url-preview').val(getAAM().__('Generating URL...'));
|
3680 |
subject: getAAM().getSubject().type,
|
3681 |
subjectId: getAAM().getSubject().id,
|
3682 |
expires: expires,
|
3683 |
+
refreshable: refreshable,
|
3684 |
+
register: false
|
3685 |
},
|
3686 |
beforeSend: function () {
|
3687 |
+
$('#jwt-token-preview').val(
|
3688 |
+
getAAM().__('Generating token...')
|
3689 |
+
);
|
3690 |
+
|
3691 |
+
$('#jwt-url-preview').val(
|
3692 |
+
getAAM().__('Generating URL...')
|
3693 |
+
);
|
3694 |
},
|
3695 |
success: function (response) {
|
3696 |
if (response.status === 'success') {
|
3959 |
});
|
3960 |
}
|
3961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3962 |
/**
|
3963 |
*
|
3964 |
* @returns {undefined}
|
3983 |
$('i', _this).attr('class', 'icon-spin4 animate-spin');
|
3984 |
downloadExtension(license, function (response) {
|
3985 |
if (response) {
|
3986 |
+
getAAM().downloadFile(
|
3987 |
+
response.content,
|
3988 |
response.title + '.zip',
|
3989 |
'application/zip'
|
3990 |
);
|
4526 |
//load the UI javascript support
|
4527 |
UI();
|
4528 |
|
4529 |
+
// Migration log downloader
|
4530 |
+
if ($('#download-migration-log').length) {
|
4531 |
+
$('#download-migration-log').bind('click', function() {
|
4532 |
+
getAAM().downloadFile(
|
4533 |
+
$('#migration-errors-container').html(),
|
4534 |
+
'migration-error.log',
|
4535 |
+
'text/plain'
|
4536 |
+
);
|
4537 |
+
});
|
4538 |
+
}
|
4539 |
+
|
4540 |
//initialize help context
|
4541 |
$('.aam-help-menu').each(function () {
|
4542 |
var target = $(this).data('target');
|
4721 |
return (getLocal().ui === type);
|
4722 |
};
|
4723 |
|
4724 |
+
/**
|
4725 |
+
*
|
4726 |
+
*/
|
4727 |
+
AAM.prototype.downloadFile = function(content, filename, mime) {
|
4728 |
+
const binaryString = window.atob(content); // Comment this if not using base64
|
4729 |
+
const bytes = new Uint8Array(binaryString.length);
|
4730 |
+
const base64 = bytes.map((byte, i) => binaryString.charCodeAt(i));
|
4731 |
+
|
4732 |
+
var blob = new Blob([base64], { type: mime || 'application/octet-stream' });
|
4733 |
+
|
4734 |
+
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
4735 |
+
// IE workaround for "HTML7007: One or more blob URLs were
|
4736 |
+
// revoked by closing the blob for which they were created.
|
4737 |
+
// These URLs will no longer resolve as the data backing
|
4738 |
+
// the URL has been freed."
|
4739 |
+
window.navigator.msSaveBlob(blob, filename);
|
4740 |
+
}
|
4741 |
+
else {
|
4742 |
+
var blobURL = window.URL.createObjectURL(blob);
|
4743 |
+
var tempLink = document.createElement('a');
|
4744 |
+
tempLink.style.display = 'none';
|
4745 |
+
tempLink.href = blobURL;
|
4746 |
+
tempLink.setAttribute('download', filename);
|
4747 |
+
|
4748 |
+
// Safari thinks _blank anchor are pop ups. We only want to set _blank
|
4749 |
+
// target if the browser does not support the HTML5 download attribute.
|
4750 |
+
// This allows you to download files in desktop safari if pop up blocking
|
4751 |
+
// is enabled.
|
4752 |
+
if (typeof tempLink.download === 'undefined') {
|
4753 |
+
tempLink.setAttribute('target', '_blank');
|
4754 |
+
}
|
4755 |
+
|
4756 |
+
document.body.appendChild(tempLink);
|
4757 |
+
tempLink.click();
|
4758 |
+
document.body.removeChild(tempLink);
|
4759 |
+
window.URL.revokeObjectURL(blobURL);
|
4760 |
+
}
|
4761 |
+
}
|
4762 |
+
|
4763 |
/**
|
4764 |
*
|
4765 |
* @returns {aamLocal}
|
readme.txt
DELETED
@@ -1,1069 +0,0 @@
|
|
1 |
-
=== Advanced Access Manager ===
|
2 |
-
Contributors: vasyltech
|
3 |
-
Tags: access control, membership, backend menu, user role, restricted content, security, jwt
|
4 |
-
Requires at least: 4.4.0
|
5 |
-
Tested up to: 5.2.1
|
6 |
-
Stable tag: 5.9.7.2
|
7 |
-
|
8 |
-
All you need to manage access to you WordPress websites on frontend, backend and API levels for any role, user or visitors.
|
9 |
-
|
10 |
-
== Description ==
|
11 |
-
|
12 |
-
> Advanced Access Manager (aka AAM) is all you need to manage access to your website frontend and backend for any user, role or visitors.
|
13 |
-
|
14 |
-
https://www.youtube.com/watch?v=mj5Xa_Wc16Y
|
15 |
-
|
16 |
-
= Few Quick Facts =
|
17 |
-
|
18 |
-
* The only plugin that gives you absolute freedom to define the most granular access to any aspect of your website and most of the feature are free;
|
19 |
-
* Bullet-proven plugin that is used on over 100,000 websites where all features are well-tested and [documented](https://aamplugin.com/support). Very low amount of support tickets speaks for quality;
|
20 |
-
* It is the only plugin that gives you the ability to manage access to your website content for any role, individual user and visitors or even define the default access to all posts, pages, custom post types, categories and custom hierarchical taxonomies;
|
21 |
-
* AAM is developer oriented plugin. It has dozens of hooks and configurations. It is integrated with WordPress RESTful and XML-RPC APIs and has numerous abstract layers to simplify coding;
|
22 |
-
* No ads or other promotional crap. The UI is clean and well crafted so you can focus only on what matters;
|
23 |
-
* No need to be a "paid" customer to get help. Request support via email or start chat with Google Hangout;
|
24 |
-
* Some features are limited or available only with [premium extensions](https://aamplugin.com/store). AAM functionality is transparent and you will absolute know when you need to get a premium extension;
|
25 |
-
|
26 |
-
= Main Areas Of Focus =
|
27 |
-
|
28 |
-
* [Access & Security Policy](https://aamplugin.com/reference/policy) allows you to define who, when, how and under what conditions your website resources can be accessed;
|
29 |
-
* Content access control on frontend, backend and API sides to posts, pages, custom post types, categories, custom hierarchical taxonomies and CPTs for any role, user and visitors;
|
30 |
-
* Roles & capabilities management with ability to create new roles and capabilities, edit, clone or delete existing;
|
31 |
-
* Access control to backend area including backend menu, toolbar, metaboxes & widgets;
|
32 |
-
* Access control to RESTful & XML-RPC APIs;
|
33 |
-
* Developer friendly API so it can be used by other developers to work with AAM core;
|
34 |
-
* And all necessary features to setup smooth user flow during login, logout, access denied even, 404 etc.
|
35 |
-
|
36 |
-
= The Most Popular Features =
|
37 |
-
|
38 |
-
* [free] Manage Backend Menu. Manage access to the backend menu for any user or role. Find out more from [How to manage WordPress backend menu](https://aamplugin.com/article/how-to-manage-wordpress-backend-menu) article;
|
39 |
-
* [free] Manage Roles & Capabilities. Manage all your WordPress role and capabilities.
|
40 |
-
* [free] All necessary set of tools to manage JWT authentication [Ultimate guide to WordPress JWT Authentication](https://aamplugin.com/article/ultimate-guide-to-wordpress-jwt-authentication)
|
41 |
-
* [free] Create temporary user accounts. Create and manage temporary user accounts. Find out more from [How to create temporary WordPress user account](https://aamplugin.com/article/how-to-create-temporary-wordpress-user-account);
|
42 |
-
* [limited] Content access. Very granular access to unlimited number of post, page or custom post type ([19 different options](https://aamplugin.com/reference/plugin#posts-terms)). With premium [Plus Package](https://aamplugin.com/extension/plus-package) extension also manage access to hierarchical taxonomies or setup the default access to all post types and taxonomies. Find out more from [How to manage access to the WordPress content](https://aamplugin.com/article/how-to-manage-access-to-the-wordpress-content) article;
|
43 |
-
* [free] Manage Admin Toolbar. Filter out unnecessary items from the top admin toolbar for any role or user.
|
44 |
-
* [free] Backend Lockdown. Restrict access to your website backend side for any user or role. Find out more from [How to lockdown WordPress backend](https://aamplugin.com/article/how-to-lockdown-wordpress-backend) article;
|
45 |
-
* [free] Secure Login Widget & Shortcode. Drop AJAX login widget or shortcode anywhere on your website. Find out more from [How does AAM Secure Login works](https://aamplugin.com/article/how-does-aam-secure-login-works) article;
|
46 |
-
* [free] Ability to enable/disable RESTful and XML-RPC APIs.
|
47 |
-
* [limited] URI Access. Allow or deny access to any page of you website by the page URL as well as how to redirect user when access is denied;
|
48 |
-
* [free] Manage access to RESTful or XML-RPC individual endpoints for any role, user or visitors.
|
49 |
-
* [free] JWT authentication. Authenticate user with WordPress RESTful API and use received JWT token for further requests. Fid out more from [Hot to authenticate WordPress user with JWT token](https://aamplugin.com/article/how-to-authenticate-wordpress-user-with-jwt-token)
|
50 |
-
* [free] Login with URL. For more information check [WordPress: Temporary User Account, Login With URL & JWT Token](https://aamplugin.com/article/wordpress-temporary-user-account-login-with-url-jwt-token) article.
|
51 |
-
* [free] Content Filter. Filter or replace parts of your content with AAM shortcodes. Find out more from [How to filter WordPress post content](https://aamplugin.com/article/how-to-filter-wordpress-post-content) article;
|
52 |
-
* [free] Login/Logout Redirects. Define custom login and logout redirect for any user or role;
|
53 |
-
* [free] 404 Redirect. Redefine where user should be redirected when page does not exist. Find out more from [How to redirect on WordPress 404 error](https://aamplugin.com/article/how-to-redirect-on-wordpress-404-error);
|
54 |
-
* [free] Access Denied Redirect. Define custom redirect for any role, user or visitors when access is denied for restricted area on your website;
|
55 |
-
* [free] Manage Metaboxes & Widgets. Filter out restricted or unnecessary metaboxes and widgets on both frontend and backend for any user, role or visitors. Find out more from [How to hide WordPress metaboxes & widgets](https://aamplugin.com/article/how-to-hide-wordpress-metaboxes-and-widgets) article;
|
56 |
-
* [paid] Manage access based on IP address or referred domain. Manage access to your website for all visitors based on referred host or IP address. Find out more from [How to manage access to WordPress website by IP address](https://aamplugin.com/article/how-to-manage-access-to-wordpress-website-by-ip-address) article;
|
57 |
-
* [paid] Monetize access to you content. Start selling access to your website content with premium [E-Commerce](https://aamplugin.com/extension/ecommerce) extension. Find out more from [How to monetize access to the WordPress content](https://aamplugin.com/article/how-to-monetize-access-to-the-wordpress-content) article;
|
58 |
-
* [free] Multisite support. Sync access settings across your network or even restrict none-members from accessing one of your sites. Find out more from [AAM and WordPress Multisite support](https://aamplugin.com/article/aam-and-wordpress-multisite-support);
|
59 |
-
* [free] Multiple role support. Finally AAM supports multiple roles per user [WordPress access control for users with multiple roles](https://aamplugin.com/article/wordpress-access-control-for-users-with-multiple-roles)
|
60 |
-
* [and even more...] Check our [help page](https://aamplugin.com/support) to learn more about AAM
|
61 |
-
|
62 |
-
== Installation ==
|
63 |
-
|
64 |
-
1. Upload `advanced-access-manager` folder to the `/wp-content/plugins/` directory
|
65 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress
|
66 |
-
|
67 |
-
== Screenshots ==
|
68 |
-
|
69 |
-
1. Manage access to backend menu
|
70 |
-
2. Manage access to metaboxes & widgets
|
71 |
-
3. Manage capabilities for roles and users
|
72 |
-
4. Manage access to posts, pages, media or custom post types
|
73 |
-
5. Posts and pages access options form
|
74 |
-
6. Define access to posts and categories while editing them
|
75 |
-
7. Manage access denied redirect rule
|
76 |
-
8. Manage user login redirect
|
77 |
-
9. Manage 404 redirect
|
78 |
-
10. Create your own content teaser for limited content
|
79 |
-
11. Improve your website security
|
80 |
-
|
81 |
-
== Changelog ==
|
82 |
-
|
83 |
-
= 5.9.7.1 =
|
84 |
-
* Fixed the bug with Access Policy for Capability resource
|
85 |
-
* Fixed the bug with Nginx redirect rules for media access
|
86 |
-
|
87 |
-
= 5.9.7 =
|
88 |
-
* Prep for upcoming AAM v6 release. Converting all extensions to plugins
|
89 |
-
* Covered odd use-case when some plugins decide to register CPT capabilities during plugin activation
|
90 |
-
* Improved Backend Menu feature functionality
|
91 |
-
|
92 |
-
= 5.9.6.3 =
|
93 |
-
* Fixed the bug with merging access settings for multiple roles
|
94 |
-
* Improved the way capabilities are managed internally by AAM
|
95 |
-
* Fixed PHP notice reported by jaerlo https://forum.aamplugin.com/d/207-indirect-modification-of-overloaded-property-aam-core-subject-user-roles
|
96 |
-
* Fixed PHP fatal error reported by kevinagar https://wordpress.org/support/topic/fatal-error-3199/
|
97 |
-
* Fixed the bug with Backend Menu feature where all the menu items that require "administrator" capability where not shown
|
98 |
-
|
99 |
-
= 5.9.6.2 =
|
100 |
-
* Fixed the bug added slashes to the Access Policy JSON document
|
101 |
-
* Fixed the bug with Metaboxes & Widgets to prevent PHP warning for widgets that registered with Closure callback
|
102 |
-
* Fixed the bug in URI Access feature that causes PHP warning when data is merged for multiple roles
|
103 |
-
* Fixed the bug with Access Policy rules that are not initialized correctly for Visitors
|
104 |
-
* Fixed the bug reported on GitHub https://github.com/aamplugin/advanced-access-manager/issues/6
|
105 |
-
* Changed the way AAM hooks into get_options pipeline with Access Policy "Params". This is done to support array options
|
106 |
-
* Changed the way Login Widget is registered to reduce code
|
107 |
-
|
108 |
-
= 5.9.6.1 =
|
109 |
-
* Fixed the fatal error related to URI object
|
110 |
-
|
111 |
-
= 5.9.6 =
|
112 |
-
* Fixed the bug with URI Access feature for URIs with trailing forward slash "/"
|
113 |
-
* Fixed the bug with Access Policy where incorrect default value was propagated
|
114 |
-
* Fixed the bug with API Routes not merged properly with multiple-roles support
|
115 |
-
* Added HTTP Redirect Code to URI Access, Posts & Terms features
|
116 |
-
* Added new Access Policy marker type QUERY that is alias for the GET
|
117 |
-
* Added support for the null data type for Access Policy data type casting
|
118 |
-
* Improved the way password-protected feature works; enhanced Access Policy to support it https://aamplugin.com/reference/policy#post
|
119 |
-
* Deprecated and removed internal AAM cache by optimizing AAM performance. Cache became major constrain for the dynamic Access Policy conditions
|
120 |
-
|
121 |
-
= 5.9.5 =
|
122 |
-
* Fixed the bug with Access Policy `Param` value that was not evaluating embedded markers
|
123 |
-
* Fixed the bug that was causing PHP Warning for users that have none-existing role assigned
|
124 |
-
* Fixed the bug with Customizer that was blocking user from publishing changes
|
125 |
-
* Added support for `tags` - the ability to manage access to posts by none-hierarchical terms
|
126 |
-
* Added the ability to define dynamic Resource names with markers in Access Policies
|
127 |
-
* Added new Access Policy marker USERMETA https://aamplugin.com/reference/policy#usermeta
|
128 |
-
|
129 |
-
= 5.9.4 =
|
130 |
-
* Fixed the bug with incorrectly identifying CPT capabilities
|
131 |
-
* Fixed the bug with URI Access where there where no way to override wildcard rule
|
132 |
-
* Fixed multiple bugs related to JWT authentication
|
133 |
-
* Fixed the bug with Access Policy that triggers PHP Notice for visitors
|
134 |
-
* Removed support for ConfigPress option `core.settings.setJwtCookieAfterLogin`
|
135 |
-
* Added the ability to obtain Login URL from the "Manage User" modal
|
136 |
-
* Added the ability to control AAM cache size https://aamplugin.com/reference/plugin#core-cache-limit
|
137 |
-
* Refactored Capabilities feature to follow the best practices for integration with WP Core
|
138 |
-
* Refactored JWT authentication so it can be more seamlessly integrated with user status
|
139 |
-
|
140 |
-
= 5.9.3 =
|
141 |
-
* Fixed the bug with LIST and LIST TO OTHERS options for multiple roles support
|
142 |
-
* Fixed the bug with managing access to custom post types that contain "-" in name
|
143 |
-
* Added ability to refresh JWT token with new RESTful endpoint /refresh-jwt
|
144 |
-
* Added ability to filter out metabox by its name with Access Policy
|
145 |
-
* Improved Posts & Terms access control with Access Policy
|
146 |
-
|
147 |
-
= 5.9.2.1 =
|
148 |
-
* Fixed several bugs that are related to post, page or custom post type editing
|
149 |
-
|
150 |
-
= 5.9.2 =
|
151 |
-
* Fixed the bug with Access Policy access control
|
152 |
-
* Fixed the bug with Access Policy tab shows only 10 last Policies
|
153 |
-
* Fixed the bug where AAM was not determining correct max user level
|
154 |
-
* Fixed the bug where user was able to manage his roles on the profile page
|
155 |
-
* Fixed the bug with Access Policy "Between" condition
|
156 |
-
* Optimized AAM to support unusual access capabilities for custom post types https://forum.aamplugin.com/d/99-custom-post-type-does-not-honor-edit-delete-publish-overrides/5
|
157 |
-
* Enhanced Access Policy with few new features. The complete reference is here https://aamplugin.com/reference/policy
|
158 |
-
* Enabled 'JWT Authentication' by default
|
159 |
-
* Significantly improved AAM UI page security
|
160 |
-
* Added new JWT Tokens feature to the list of AAM features https://aamplugin.com/reference/plugin#jwt-tokens
|
161 |
-
* Added new capability aam_manage_jwt
|
162 |
-
* Added "Add New Policies" submenu to fix WordPress core bug with managing access to submenus
|
163 |
-
* Removed "Role Expiration" feature - it was too confusing to work with
|
164 |
-
* Removed allow_ajax_calls capability support - it was too confusing for end users
|
165 |
-
|
166 |
-
= 5.9.1.1 =
|
167 |
-
* Fixed the bug with saving Metaboxes & Widgets settings
|
168 |
-
* Fixed the bug with saving Access Policy that has backward slashes in it
|
169 |
-
* Fixed the bug with fetching Param values from the Access Policies
|
170 |
-
* Fixed the bug with Access Policy resource "Role" when Effect is set to "deny"
|
171 |
-
* Adjusted AAM core to prevent PHP warning when edit_user or delete_user capability is checked without user ID provided (caused by other plugins)
|
172 |
-
|
173 |
-
= 5.9.1 =
|
174 |
-
* Fixed the bug with controlling which capability can be deleted with Access Policy
|
175 |
-
* Fixed typo in the aam_edit_others_policies capability slug
|
176 |
-
* Fixed the bug with API Routes not being saved property for those that have htmlspecial characters in it
|
177 |
-
* Fixed major bug with keeping track of active user sessions that prevents multiple session per same user
|
178 |
-
* Added "Redirect To Login" to the LIMIT option for visitors on Posts & Terms tab
|
179 |
-
* Added the new concept of "Boundary" to Access Policy that allows to Enforce certain statements
|
180 |
-
|
181 |
-
= 5.9 =
|
182 |
-
* Fixed the bug with publish pages not being managed correctly
|
183 |
-
* Fixed the bug with getting correct post from the list of posts
|
184 |
-
* Significantly enhanced AAM UI security
|
185 |
-
* Added ability to toggle default term for any post type
|
186 |
-
* Added ability to assign multiple roles per user
|
187 |
-
|
188 |
-
= 5.8.3 =
|
189 |
-
* Fixed the bug with multi-lingual support
|
190 |
-
* Fixed the bug with LIMIT option that escaped quotes in the message
|
191 |
-
* Fixed the bug with managing access to Access Policies
|
192 |
-
* Added support for aam_edit_policy, aam_read_policy, aam_delete_policy, aam_delete_policies, aam_edit_policies, aam_edit_others_policies, aam_publish_policies capabilities
|
193 |
-
* Refactored Default Category functionality (moved it to Plus Package extension)
|
194 |
-
* Added support for the nav_menu_meta_box_object hook to filter posts on Menu Builder page
|
195 |
-
* Extend Access Policy with more features
|
196 |
-
|
197 |
-
= 5.8.2 =
|
198 |
-
* Fixed numerous bugs with access control for media
|
199 |
-
* Added support for change_own_password capability
|
200 |
-
* Added support for change_passwords capability
|
201 |
-
* Added type casting to the Access Policy document
|
202 |
-
* Added new resource `Role` to the Access Policy
|
203 |
-
* Refactored internal Access Policy implementation
|
204 |
-
* Improved performance
|
205 |
-
|
206 |
-
= 5.8.1 =
|
207 |
-
* Fixed bug that causes fatal error with Policy editor on Linux servers
|
208 |
-
* Profiled and improved several bottlenecks that may speed-up website load up to 300 milliseconds
|
209 |
-
|
210 |
-
= 5.8 =
|
211 |
-
* Fixed the bug with Access Policy settings inheritance mechanism
|
212 |
-
* Fixed numerous of bugs with JWT authentication and improved time expiration handling
|
213 |
-
* Enhanced temporary user access management functionality
|
214 |
-
* Added Logout action when user access expired
|
215 |
-
* Added ability to login user with URL
|
216 |
-
|
217 |
-
= 5.7.3 =
|
218 |
-
* Fixed the bug with JWT authentication
|
219 |
-
* Fixed the PHP bug in policy metabox when no errors with JSON is detected
|
220 |
-
* Fixed the bug with license expiration for Extended versions not properly displayed
|
221 |
-
* Fixed the bug with Admin Menu listed incorrectly when Default Access Settings defined
|
222 |
-
* Fixed the PHP bug in Post object when access settings are defined in a Policy
|
223 |
-
* Improved role creation feature
|
224 |
-
* Improved capability handling with Access & Security Policy
|
225 |
-
* Refactor the way extension is installed to eliminate cURL issues
|
226 |
-
* Deprecated and removed `aam_display_license` capability
|
227 |
-
* Extended default policy document with dependencies
|
228 |
-
* Added support for `Features` in the Access & Security Policy
|
229 |
-
* Added policy Validation functionality
|
230 |
-
* Reduced number of methods that use cURL to contact aamplugin.com API
|
231 |
-
|
232 |
-
= 5.7.2 =
|
233 |
-
* Fixed bug with Posts & Terms feature for WP version under 4.8
|
234 |
-
* Fixed bug were Access Policy can't be attached to any principal on the Policy edit screen
|
235 |
-
* Fixed bug with Access URI options were not merged for users with multiple roles
|
236 |
-
* Fixed bug with Access URI options were not exported
|
237 |
-
* Fixed but with Post PUBLISH option due to the fact that Gutenberg is using RESTful API
|
238 |
-
* Extended Access & Security Policy to support Posts & Terms options
|
239 |
-
* Added /validate-jwt RESTful API endpoint to validate JWT
|
240 |
-
* Added ability to extract JWT token from GET queries or POST payload
|
241 |
-
* Added custom capability aam_view_help_btn to hide HELP icon on AAM UI
|
242 |
-
* Significantly improved capability mapping mechanism and access control based on caps
|
243 |
-
* Added URI Access support to Access & Security Policy
|
244 |
-
* Added Post, Term, PostType support to Access & Security Policy
|
245 |
-
|
246 |
-
= 5.7.1 =
|
247 |
-
* Fixed the bug with AAM notifications related to extension updates
|
248 |
-
* Fixed the bug with AAM not taking in consideration capabilities that defined in policy
|
249 |
-
* Improved the way show_admin_bar capability is handled
|
250 |
-
* Added ability to define Conditions to the Statement Policy document
|
251 |
-
|
252 |
-
= 5.7 =
|
253 |
-
* Added a huge innovation to the access control management - Access & Security Policy
|
254 |
-
* Fixed the bug with updating extension versions
|
255 |
-
|
256 |
-
= 5.6.1.1 =
|
257 |
-
* Fixed the bug when website may crash when some extensions are really out-of-date
|
258 |
-
|
259 |
-
= 5.6.1 =
|
260 |
-
* Fixed the bug with caching
|
261 |
-
* Fixed the bug with the way post type and taxonomies are registered with extensions
|
262 |
-
* Turned on by default the ability to edit and delete capabilities
|
263 |
-
|
264 |
-
= 5.6 =
|
265 |
-
* Fixed the bug with encoding on Safari when gzip is enabled
|
266 |
-
* Fixed the bug with double caching
|
267 |
-
* Added URI Access feature that allows to manage access to any website URI
|
268 |
-
* Improved UI a little bit
|
269 |
-
|
270 |
-
= 5.5.2 =
|
271 |
-
* Improved performance for website with large amount of posts/pages
|
272 |
-
* Prepared few changes forward for the upcoming AAM 5.6 release
|
273 |
-
|
274 |
-
= 5.5.1 =
|
275 |
-
* Fixed the bug with exporting AAM settings when roles, configpress was added by default
|
276 |
-
* Fixed the bug with AAM cache not being triggered properly
|
277 |
-
* Fixed the bug with some of the classes been cached improperly
|
278 |
-
* Fixed the bug with toolbar filter that are corrupted by third part plugin or theme
|
279 |
-
* Improved AAM to handle gzip compression properly
|
280 |
-
* Updated bootstrap library to the v3.3.7
|
281 |
-
|
282 |
-
= 5.5 =
|
283 |
-
* Fixed the bug with EDIT BY OTHERS option
|
284 |
-
* Fixed UI bug when managing access to AAM page itself
|
285 |
-
* Fixed the bug reported by https://github.com/KenAer
|
286 |
-
* Fixed the bug with creating new post when default access is denied to EDIT
|
287 |
-
* Fixed the bug with editing page that is in draft state
|
288 |
-
* Fixed multiple bugs with AAM export/import feature
|
289 |
-
* Fixed the bug with blocked user being able to login again
|
290 |
-
* Slightly improved extension installation feedback
|
291 |
-
* Improved UI
|
292 |
-
* Enhanced JWT token feature
|
293 |
-
* Improved the way Backend Menu and Toolbar features work
|
294 |
-
* Added multiple-roles support
|
295 |
-
* Refactored Import/Export features
|
296 |
-
* Removed Settings->Tools tab
|
297 |
-
|
298 |
-
= 5.4.3.2 =
|
299 |
-
* Fixed bug that incorrectly checks post author property
|
300 |
-
* Fixed bug that does not allow to assign roles that contain apostrophe
|
301 |
-
* Fixed bug with incorrectly handled AAM Console messages that contain HTML
|
302 |
-
* Added ability to order roles by name
|
303 |
-
* Added ability to order users by display name
|
304 |
-
* Improved Users/Roles Manager UI
|
305 |
-
|
306 |
-
= 5.4.3.1 =
|
307 |
-
* Quick fix for the bug that is related to Posts & Terms
|
308 |
-
|
309 |
-
= 5.4.3 =
|
310 |
-
* Fixed the bug with Posts & Terms feature that hides it when Manage Frontend & Backend Access are disabled however API is enabled
|
311 |
-
* Fixed the bug that cached objects while managing them on AAM page. That was causing inconsistency sometimes
|
312 |
-
* Fixed the bug with content shortcode that was defining incorrectly if wrapped content should be hidden or not for specific user
|
313 |
-
* Fixed the bug with AAM not being able to apply translations for other languages
|
314 |
-
* Added new option "Support AAM Extensions" that allows to enables/disables Extensions feature
|
315 |
-
* Added new option "Get Started Feature" that toggle the Get Started tab
|
316 |
-
* Added new option "AAM Cron Job" that enables/disables the internal AAM cron job
|
317 |
-
* Added Get Started tab with some basic introduction to AAM plugin
|
318 |
-
* Added ability to set "hard" user login time
|
319 |
-
* Added ability to sort posts and terms list by title
|
320 |
-
* Enhanced JWT authentication with ability to set also cookie that contains JWT token or define signing algorithm
|
321 |
-
* Refactored Metaboxes & Widget feature so initialization process is handled with client side
|
322 |
-
* Refactored Admin Toolbar feature so initialization process is handled with client side
|
323 |
-
* Improved the Post & Terms feature by enabling to manage more post types out-of-box
|
324 |
-
* Improved the Import/Export feature that eliminates issues with incompatible AAM versions
|
325 |
-
* Refactored internal implementation to make it compatible with strict and secure environments like WordPress VIP
|
326 |
-
|
327 |
-
= 5.4.2 =
|
328 |
-
* Fixed the bug that was causing an error with legacy "teaser" data
|
329 |
-
* Fixed the bug with aam_manage_admin_toolbar capability been named incorrectly
|
330 |
-
* Clearing all AAM settings when plugin is uninstalled
|
331 |
-
* Highlighted post, term or type that has explicit access settings defined on Posts & Terms tab
|
332 |
-
* Improved JWT authentication feature to allow use it for stand-alone embedded to WP apps
|
333 |
-
|
334 |
-
= 5.4.1 =
|
335 |
-
* Fixed the bug reported by Doug Davis where newly created posts get locked if default access settings are defined
|
336 |
-
* Fixed the bug with post visibility when /%category%/%postname%/ permalink is defined
|
337 |
-
* Fixed the but with default category not been selected when redefined with ConfigPress
|
338 |
-
* Improved AAM performance by caching post visibility results
|
339 |
-
|
340 |
-
= 5.4 =
|
341 |
-
* Fixed bug with Api Access Control option that when disabled, still denies API Routes
|
342 |
-
* Fixed bug when RESTful or XML-RPC disabled but endpoints still listed on API Routes
|
343 |
-
* Fixed bug with Secure Login for themes that are not build with jQuery support
|
344 |
-
* Fixed bug with posts not been filtered during search in few post types
|
345 |
-
* Added ability to manage Admin Toolbar items
|
346 |
-
* Added ability to manage premium licenses so now user can transfer license anytime
|
347 |
-
* Moved security options (brute force lockout, login timeout etc) to stand-alone Security tab
|
348 |
-
* Improved UI for the ACCESS EXPIRATION option on Posts & Terms tab
|
349 |
-
* Improved UI for defining temporary user account timespan
|
350 |
-
* Removed deprecated "Check Post Visibility" option
|
351 |
-
|
352 |
-
= 5.3.5 =
|
353 |
-
* Fixed bug with post LIST & LIST TO OTHERS when access is set to term in odd order
|
354 |
-
* Fixed bug that potentially did not filter posts during search
|
355 |
-
* Added notification to the UI that extension folder does not exist or is not writable
|
356 |
-
* Added XML-RPC endpoint control
|
357 |
-
* Added ability to filter list of users by roles on the Users/Roles Manager panel
|
358 |
-
|
359 |
-
= 5.3.4 =
|
360 |
-
* Fixed incompatibility issue with plugins that use "plugins_loaded" hook for post manipulations
|
361 |
-
* Fixed the bug with AAM_Api_Rest_Resource_User
|
362 |
-
* Fixed issues with ConfigPress settings compatibility between versions
|
363 |
-
* Fixed the issues with infinite loop when access denied redirect is not configured correctly
|
364 |
-
* Fixed issue with post filtering that disregards Backend/Frotent/API Access Control settings
|
365 |
-
* Fixed bug with login widget labels
|
366 |
-
* Added more information about parent terms & posts to the Post & Terms list
|
367 |
-
* Added additional widget that lists of AAM licenses on the Extensions tab
|
368 |
-
* Added fallback secret key for jwt token generator
|
369 |
-
* Added ability to filter out widgets from the Appearance->Widgets screen
|
370 |
-
|
371 |
-
= 5.3.3 =
|
372 |
-
* Fixed couple bugs with secure login widget rendering
|
373 |
-
* Fixed the bug with AAM UI refresh triggered by aam extensions
|
374 |
-
* Fixed the bug with send remote request and array of cookies
|
375 |
-
* Added ability to hide login navigations links in the secure login widget with feature.secureLogin.ui.showNav configPress option
|
376 |
-
* Added new custom capability "manage_same_user_level"
|
377 |
-
|
378 |
-
= 5.3.2 =
|
379 |
-
* Fixed the bug that triggers PHP warnings when blocked user is trying to login
|
380 |
-
* Fixed the bug with get current post method in the core API
|
381 |
-
* WARNING Experimental approach! to the post access that enormously improve AAM performance
|
382 |
-
* Added custom capability "edit_permalink" that control ability to edit post permalink
|
383 |
-
|
384 |
-
= 5.3.1 =
|
385 |
-
* Fixed bug with deprecated cache object to keep it backward compatible
|
386 |
-
* Fixed bug with teaser message on none latin alphabet
|
387 |
-
* Improved REDIRECT functionality for Posts & Terms feature
|
388 |
-
* Added finally singe point API (AAM::api method)
|
389 |
-
* Added "Single Session" option to the Secure Login widget
|
390 |
-
* Added more localization string to the AAM *.po file
|
391 |
-
* Standardized AAM core settings names
|
392 |
-
* Standardized REST API error codes
|
393 |
-
|
394 |
-
= 5.3 =
|
395 |
-
* Fixed the bug with ConfigPress settings when array is defined
|
396 |
-
* Fixed the bug with jwt authentication
|
397 |
-
* Fixed the bug with infinite logout loop when user is locked
|
398 |
-
* Refactored internal functionality to make it fully compatible with WP REST API
|
399 |
-
* Split Posts & Pages access control on Backend, Frontend and API sections
|
400 |
-
* Cleaned up posts and pages access settings
|
401 |
-
* Refactored internal AAM cache to make it more flexible and faster
|
402 |
-
* Added "API Access Control" option
|
403 |
-
* Added ability to change user role after certain period of time
|
404 |
-
* Removed ability to lock Dashboard menu
|
405 |
-
|
406 |
-
= 5.2.7 =
|
407 |
-
* Fixed bug with REST API Routes list
|
408 |
-
* Improved REST API response messages
|
409 |
-
* Added support for WordPress RESTful API for posts, categories, comments and users.
|
410 |
-
|
411 |
-
= 5.2.6 =
|
412 |
-
* Dropped support for WordPress versions 3.x. Min supported version is 4.0
|
413 |
-
* Fixed bug with Admin Menu access control to Posts list
|
414 |
-
* Fixed bug in AAM Core API for get plugins data call
|
415 |
-
* Fixed bug with visitors cache auto-flush
|
416 |
-
* Minor improvements to the AAM UI
|
417 |
-
|
418 |
-
= 5.2.5 =
|
419 |
-
* Fixed the bug with JWT authentication
|
420 |
-
* Added the ability to enable/disable XML-RPC
|
421 |
-
* Added the ability to enable/disable REST API
|
422 |
-
* Added the ability to manage access to the individual REST API endpoints
|
423 |
-
|
424 |
-
= 5.2.1 =
|
425 |
-
* Fixed bug with Linux incompatibility
|
426 |
-
|
427 |
-
= 5.2 =
|
428 |
-
* Fixed the bug with user lock functionality
|
429 |
-
* Dropped support for PHP 5.2.x version. Minimum required version is 5.3.0
|
430 |
-
* Merged ConfigPress extension to the core
|
431 |
-
* Added JWT Authentication
|
432 |
-
* Added Register link to the Secure Login Widget
|
433 |
-
|
434 |
-
= 5.1.1 =
|
435 |
-
* Fixed the issue with Multisite Network notification
|
436 |
-
* Fixed the minor bug with login message for "Redirect to login form"
|
437 |
-
* Deleted redundant AAM_Core_Log class
|
438 |
-
* Improved and refactored AAM Core Login functionality for upcoming REST API control extension
|
439 |
-
|
440 |
-
= 5.1 =
|
441 |
-
* Fixed sever minor bugs reported by users
|
442 |
-
* Added free social login extension (alpha version undocumented)
|
443 |
-
* Added ability to create a temporary user account
|
444 |
-
* Moved all free extension to the Github repository
|
445 |
-
|
446 |
-
= 5.0.8 =
|
447 |
-
* Fixed the bug to keep AAM compatible with older WP version
|
448 |
-
|
449 |
-
= 5.0.7 =
|
450 |
-
* Fixed the bug that is caused by other plugins not using core filters correctly
|
451 |
-
* Hiding Dashboard and Edit My Profile links if user does not have access to them
|
452 |
-
|
453 |
-
= 5.0.6 =
|
454 |
-
* Fixed several minor PHP errors caused by legacy PHP versions and corrupted data
|
455 |
-
* Another boost to the AAM performance
|
456 |
-
* Normalized few AAM core filters and actions
|
457 |
-
|
458 |
-
= 5.0.5 =
|
459 |
-
* Enhanced Admin Menu feature
|
460 |
-
* Extended AAM API. Preparing it for developers to use.
|
461 |
-
|
462 |
-
= 5.0.4 =
|
463 |
-
* Fixed bug with caching. Significantly improved speed.
|
464 |
-
* Fixed incompatibility issue with websites that have corrupted role list.
|
465 |
-
* Fixed bug with role expiration timer when "Manage Backend Access" option is off.
|
466 |
-
* Fixed incompatibility issue with plugins that use "the_title" filter.
|
467 |
-
* Fixed bug with extension status
|
468 |
-
* Removed registration step during plugin activation.
|
469 |
-
|
470 |
-
= 5.0.3 =
|
471 |
-
* Fixed bug with LIST option
|
472 |
-
* Fixed bug with incompatible PHP 5.3 or lower
|
473 |
-
|
474 |
-
= 5.0.2 =
|
475 |
-
* Fixed bug with admin menu reported by Andrew
|
476 |
-
* Fixed possible bug with theTitle filter
|
477 |
-
* Fixed bug with custom HTML message for the access denied redirect rule
|
478 |
-
* Fixed bug with ACCESS EXPIRATION option for Posts & Pages
|
479 |
-
* Fixed bug with Multinetwork setup when super admin is not able to add new users
|
480 |
-
* Fixed bug with extension statuses
|
481 |
-
* Removed support for integration with ConfigPress plugin. Use ConfigPress extension instead
|
482 |
-
* Added localization strings for Login widget & shortcode
|
483 |
-
|
484 |
-
= 5.0.1 =
|
485 |
-
* Fixed bug with extension updates status
|
486 |
-
* Fixed bug in post core handling caused by incompatibility with unknown plugin
|
487 |
-
* Improved UI notification with more insides about the issue
|
488 |
-
|
489 |
-
= 5.0 =
|
490 |
-
* Added ACCESS COUNTER option to Posts & Pages
|
491 |
-
* Added premium MONETIZE option to Posts & Pages
|
492 |
-
* Added ability to turn off "Secure Login" feature
|
493 |
-
* Added ability to toggle extension status (active/inactive)
|
494 |
-
* Added ability for AAM to filter out Admin Top Bar based on restricted admin menus
|
495 |
-
* Deprecated AAM Role Filter extension and merged it to the AAM core
|
496 |
-
* Deprecated AAM Payment extension and merged it with AAM E-Commerce extension
|
497 |
-
* Deprecated ConfigPress options that manage access to AAM UI. All is based on capabilities from now.
|
498 |
-
* Split UI to three areas: Access, Settings and Extensions
|
499 |
-
* Fixed over 25+ reported bugs and discovered during internal refactoring
|
500 |
-
* Removed deprecated "Security" feature. Replaced with Secure Login Widget
|
501 |
-
* Removed deprecated "Teaser" feature. Replaced with Teaser Message per post base
|
502 |
-
|
503 |
-
= 4.9.5.2 =
|
504 |
-
* Fixed compatibility with PHP 5.3 or lower
|
505 |
-
|
506 |
-
= 4.9.5.1 =
|
507 |
-
* Fixed the bug with media access
|
508 |
-
* Improved UI
|
509 |
-
|
510 |
-
= 4.9.5 =
|
511 |
-
* Improved user experience with AAM UI
|
512 |
-
* Removed Welcome message
|
513 |
-
* Fixed bug with media access
|
514 |
-
* Added filter for AAM shordcodes so other plugins can hook to AAM
|
515 |
-
* Optimized AAM javascript
|
516 |
-
* Removed subscription box to reduce "UI noise" as more features are coming
|
517 |
-
|
518 |
-
= 4.9.4 =
|
519 |
-
* Significantly improved Admin Menu access management
|
520 |
-
* Filter AAM UI based on Backend/Frontend Access Control options
|
521 |
-
|
522 |
-
= 4.9.3 =
|
523 |
-
* Simplified core implementation. First iteration to upcoming v5.0
|
524 |
-
* Added ability to check for extension updates with "Check for Updates" button
|
525 |
-
* Adjusted Admin Menu access control to cover none-standard menu definitions
|
526 |
-
* Multiple improvements to the UI
|
527 |
-
* Fixed bug with enter key not working with Login Widget
|
528 |
-
* Improved cache implementation to cover scenario when user manually corrupted cache data
|
529 |
-
* Fixed bug with utilities compatibility
|
530 |
-
* Fixed bug with extended license key
|
531 |
-
* Fixed bug with LIST and READ options checked at the same time that causes 404
|
532 |
-
* Extended Import/Export feature to cover multisite network sync
|
533 |
-
* Added ability to sync settings between multisite network
|
534 |
-
|
535 |
-
= 4.9.2 =
|
536 |
-
* Fixed the bug with AAM media control for files with special characters
|
537 |
-
* Added secure login widget and shortcode
|
538 |
-
* Deprecated Security feature
|
539 |
-
|
540 |
-
= 4.9.1 =
|
541 |
-
* Improved UI
|
542 |
-
* Improved [aam] shortcode
|
543 |
-
* Improved plugin activation experience
|
544 |
-
|
545 |
-
= 4.9 =
|
546 |
-
* Fixed bug with Login Redirect duplicate settings saving
|
547 |
-
* Added ability to hide license key with aam_display_license capability
|
548 |
-
* Added ability to export/import AAM settings
|
549 |
-
* Improved AAM UI
|
550 |
-
* Added ability to restrict access to the Hope page
|
551 |
-
* Added ability to manage access to frontend ajax calls with allow_ajax_calls cap
|
552 |
-
|
553 |
-
= 4.8.1 =
|
554 |
-
* Added ability to control post_password_expires with post.password.expires config
|
555 |
-
* Improved media access
|
556 |
-
* Improved UI
|
557 |
-
|
558 |
-
= 4.8 =
|
559 |
-
* Fixed the bug with Media access control reported by Antonius Hegyes
|
560 |
-
* Fixed the bug with post access properties preview
|
561 |
-
* Fixed the bug with permanent redirects cached by some browsers
|
562 |
-
* Fixed the bug with PasswordHash fatal error
|
563 |
-
* Added ability to define teaser message for an individual post or category
|
564 |
-
* Deprecated Content Teaser tab (will be removed in AAM 5.0)
|
565 |
-
* Extended [aam context="content"] shortcode to filter content based on IP address
|
566 |
-
* Added ability to set time expiration for roles
|
567 |
-
|
568 |
-
= 4.7.6 =
|
569 |
-
* Added ability to hide admin notification with show_admin_notices capability
|
570 |
-
* Added ability to subscribe to the AAM updates
|
571 |
-
* Updated refund policy term
|
572 |
-
|
573 |
-
= 4.7.5 =
|
574 |
-
* Improved Utilities tab
|
575 |
-
* Fixed bug with post search and archive pages
|
576 |
-
* Updated localization source
|
577 |
-
|
578 |
-
= 4.7.2 =
|
579 |
-
* Fixed the bug with Posts & Pages pagination feature
|
580 |
-
* Fixed the bug with Media access control
|
581 |
-
* Improved UI
|
582 |
-
* Added Welcome email message to every new AAM installation
|
583 |
-
|
584 |
-
= 4.7.1 =
|
585 |
-
* Fixed the PHP bug reported by CodePinch service
|
586 |
-
* Fixed the bug with Posts & Pages redirect URL
|
587 |
-
* Fixed the bug related to extensions update status
|
588 |
-
* Optimized cron procedure for AAM maintenance needs
|
589 |
-
* Added ability to restore default capabilities for users
|
590 |
-
* Move AAM User Activity to the free extension suite
|
591 |
-
* Introduced Development Package for unlimited number of sites
|
592 |
-
|
593 |
-
= 4.7 =
|
594 |
-
* Significantly improved the ability to manage access to AAM interface
|
595 |
-
* Added new group of capabilities AAM Interface
|
596 |
-
* Optimized Posts & Pages UI feature for extra large amount of records
|
597 |
-
* BIGGEST DEAL! From now no more 10 posts limit. It is unlimited!
|
598 |
-
* Fixed bug with custom HTML message for access denied redirect
|
599 |
-
* Added option to redirect to login page and back after login when access is denied
|
600 |
-
* Significantly improved media access control
|
601 |
-
* Improved CSS to keep to suppress "bad behavior" from other plugins and themes
|
602 |
-
|
603 |
-
= 4.6.2 =
|
604 |
-
* Added ability to logout automatically locked user
|
605 |
-
* Updated capability feature to allow set custom capabilities on user level
|
606 |
-
* Improved Posts & Pages feature for large number of posts
|
607 |
-
* Few minor bug fixed reported by CodePinch
|
608 |
-
|
609 |
-
= 4.6.1 =
|
610 |
-
* Fixed bug with user capabilities
|
611 |
-
* Fixed bug with post access settings not being checked even when they are
|
612 |
-
* Added ability to manage hidden post types
|
613 |
-
* Added ability to manage number of analyzed posts with get_post_limit config
|
614 |
-
|
615 |
-
= 4.6 =
|
616 |
-
* Fixed internal bug with custom post type LIST control
|
617 |
-
* Fixed PHP errors in Access Manager metabox
|
618 |
-
* Fixed bug with customize.php not being able to restrict
|
619 |
-
* Fixed bug with losing AAM licenses when Clearing all AAM settings
|
620 |
-
* Fixed bug with not being able to turn off Access Manager metabox rendering
|
621 |
-
* Fixed bug with access denied default redirect
|
622 |
-
* Fixed bug with cached javascript library
|
623 |
-
* Fixed bug with role hierarchy
|
624 |
-
* Improved media access control
|
625 |
-
* Improved Double Authentication mechanism
|
626 |
-
* Improved AAM caching mechanism
|
627 |
-
* Minor UI improvements
|
628 |
-
* Added ability to define logout redirect
|
629 |
-
* Added Access Expiration option to Posts & Pages
|
630 |
-
* Added ability to turn off post LIST check for performance reasons
|
631 |
-
* Added ability to add default media image instead of restricted
|
632 |
-
* Added ability to remove Access link under posts, users title on the list page
|
633 |
-
|
634 |
-
= 4.5 =
|
635 |
-
* Fixed few minor bugs reported by users
|
636 |
-
* Refactored Extensions functionality
|
637 |
-
* Added fully functioning Access Manager Widget for both Posts and Categories
|
638 |
-
* Updated documentation
|
639 |
-
* Significantly improved performance
|
640 |
-
|
641 |
-
= 4.4.1 =
|
642 |
-
* Adjusted code to support low memory servers
|
643 |
-
|
644 |
-
= 4.4 =
|
645 |
-
* Fixed bug with frontend page redirect
|
646 |
-
* Significantly improved AAM speed and caching
|
647 |
-
* Added 404 redirect to the Default Settings
|
648 |
-
|
649 |
-
= 4.3.1 =
|
650 |
-
* Minor bug fixes
|
651 |
-
|
652 |
-
= 4.3 =
|
653 |
-
* Fixed the bug with SSL when WordPress is not configured properly
|
654 |
-
* Added AAM User Activity extension
|
655 |
-
* Added ability to track access denied events
|
656 |
-
* Fixed the bug with internal AAM configurations
|
657 |
-
* Fixed the bug with login hook when only one argument is passed
|
658 |
-
* Fixed the bug with invalid argument is passed to password protected check
|
659 |
-
|
660 |
-
= 4.2 =
|
661 |
-
* Fixed the bug with post list caching
|
662 |
-
* Fixed the bug with Manage Access button
|
663 |
-
* Added REDIRECT option to post access list
|
664 |
-
* Added redirect to existing page for Backend tab on Access Denied Redirect
|
665 |
-
* Improved caching mechanism
|
666 |
-
|
667 |
-
= 4.1.1 =
|
668 |
-
* Fixed bug with Post & Pages UI
|
669 |
-
* Added ability to define default category for any role or user
|
670 |
-
|
671 |
-
= 4.1 =
|
672 |
-
* Added AAM IP Check extension
|
673 |
-
* Improved Content filter shortcode to allow other shortcodes inside
|
674 |
-
* Fixed bug for add/edit role with apostrophe
|
675 |
-
* Fixed bug with custom Access Denied message
|
676 |
-
* Fixed bug with data migration
|
677 |
-
|
678 |
-
= 4.0.1 =
|
679 |
-
* Fixed bug with login redirect
|
680 |
-
* Fixed minor bug with PHP Warnings on Utilities tab
|
681 |
-
* Fixed post filtering bug
|
682 |
-
* Updated login shortcode
|
683 |
-
|
684 |
-
= 4.0 =
|
685 |
-
* Added link Access to category list
|
686 |
-
* Added shortcode [aam] to manage access to the post's content
|
687 |
-
* Moved AAM Redirect extension to the basic AAM package
|
688 |
-
* Moved AAM Login Redirect extension to the basic AAM package
|
689 |
-
* Moved AAM Content Teaser extension to the basic AAM package
|
690 |
-
* Set single password for any post or posts in any category or post type
|
691 |
-
* Added two protection mechanism from login brute force attacks
|
692 |
-
* Added double authentication mechanism
|
693 |
-
* Few minor core bug fixings
|
694 |
-
* Improved multisite support
|
695 |
-
* Improved caching mechanism
|
696 |
-
|
697 |
-
= 3.9.5.1 =
|
698 |
-
* Fixed bug with login redirect
|
699 |
-
|
700 |
-
= 3.9.5 =
|
701 |
-
* General bug fixing and improvements
|
702 |
-
* Added ability to setup access settings to all Users, Roles and Visitors
|
703 |
-
* Added Login Redirect feature
|
704 |
-
|
705 |
-
= 3.9.3 =
|
706 |
-
* Bug fixing
|
707 |
-
* Implemented license check mechanism
|
708 |
-
* Improved media access control
|
709 |
-
* Added ConfigPress extension
|
710 |
-
|
711 |
-
= 3.9.2.2 =
|
712 |
-
* Bug fixing
|
713 |
-
* Simplified affiliate implementation
|
714 |
-
|
715 |
-
= 3.9.2.1 =
|
716 |
-
* Minor bug fixes reported by CodePinch service
|
717 |
-
|
718 |
-
= 3.9.2 =
|
719 |
-
* Bug fixing
|
720 |
-
* Internal code improvements
|
721 |
-
* Extended list of post & pages access options
|
722 |
-
|
723 |
-
= 3.9.1.1 =
|
724 |
-
* Minor bug fix to cover uncommon scenario when user without role
|
725 |
-
|
726 |
-
= 3.9.1 =
|
727 |
-
* Replaced AAM Post Filter extension with core option "Large Post Number Support"
|
728 |
-
* Removed redundant HTML permalink support
|
729 |
-
* Visually highlighted editing role or user is administrator
|
730 |
-
* Hide restricted actions for roles and users on User/Role Panel
|
731 |
-
* Minor UI improvements
|
732 |
-
* Significant improvements to post & pages access inheritance mechanism
|
733 |
-
* Optimized caching mechanism
|
734 |
-
* Fixed bug with post frontend access
|
735 |
-
|
736 |
-
= 3.9 =
|
737 |
-
* Fixed UI bug with role list
|
738 |
-
* Fixed core bug with max user level
|
739 |
-
* Fixed bug with CodePinch installation page
|
740 |
-
* Added native user switch functionality
|
741 |
-
|
742 |
-
= 3.8.3 =
|
743 |
-
* Fixed the bug with post access inheritance
|
744 |
-
* Update CodePinch affiliate program
|
745 |
-
|
746 |
-
= 3.8.2 =
|
747 |
-
* Optimized AAM UI to manage large amount of posts and categories
|
748 |
-
* Improved Multisite support
|
749 |
-
* Improved UI
|
750 |
-
* Fixed bug with Extensions tab
|
751 |
-
* Added ability to check for extension updates manually
|
752 |
-
|
753 |
-
= 3.8.1 =
|
754 |
-
* Minor refactoring
|
755 |
-
* UI improvements
|
756 |
-
* Bug fixing
|
757 |
-
|
758 |
-
= 3.8 =
|
759 |
-
* Added Clone Role feature
|
760 |
-
* Added auto cache clearing on term or post update
|
761 |
-
* Added init custom URL for metaboxes
|
762 |
-
|
763 |
-
= 3.7.6 =
|
764 |
-
* Fixed bug related to Media Access Control
|
765 |
-
* Fixed bug with cleaning user posts & pages cache after profile update
|
766 |
-
|
767 |
-
= 3.7.5 =
|
768 |
-
* Added AAM Content Teaser extension
|
769 |
-
* Added LIMIT option to Posts & Pages access forms to support Teaser feature
|
770 |
-
* Bug fixing
|
771 |
-
* Improved UI
|
772 |
-
* Added ability to show/hide admin bar with show_admin_bar capability
|
773 |
-
|
774 |
-
= 3.7.1 =
|
775 |
-
* Added AAM Role Hierarchy extension
|
776 |
-
* Fixed bug with 404 page for frontend
|
777 |
-
* Started CSS fixes for all known incompatible themes and plugins
|
778 |
-
|
779 |
-
= 3.7 =
|
780 |
-
* Introduced Redirect feature
|
781 |
-
* Added CodePinch widget
|
782 |
-
* Added AAM Redirect extension
|
783 |
-
* Added AAM Complete Package extension
|
784 |
-
* Removed AAM Development extension
|
785 |
-
* Removed setting Access Denied Handling from the Utilities tab
|
786 |
-
|
787 |
-
= 3.6.1 =
|
788 |
-
* Bug fixing related to URL redirect
|
789 |
-
* Added back deprecated ConfigPress class to keep compatability with old extensions
|
790 |
-
* Fixed bug reported through CodePinch service
|
791 |
-
|
792 |
-
= 3.6 =
|
793 |
-
* Added Media Access Control feature
|
794 |
-
* Added Access Denied Handling feature
|
795 |
-
* Improved core functionality
|
796 |
-
|
797 |
-
= 3.5 =
|
798 |
-
* Improved access control for Posts & Pages
|
799 |
-
* Introduced Access Manager metabox to Post edit screen
|
800 |
-
* Added Access action to list of Posts and Pages
|
801 |
-
* Improved UI
|
802 |
-
* Deprecated Skeleton extension in favor to upcoming totally new concept
|
803 |
-
* Fixed bug with metaboxes initialization when backend filtering is OFF
|
804 |
-
|
805 |
-
= 3.4.2 =
|
806 |
-
* Fixed bug with post & pages access control
|
807 |
-
* Added Extension version indicator
|
808 |
-
|
809 |
-
= 3.4.1 =
|
810 |
-
* Fixed bug with visitor access control
|
811 |
-
|
812 |
-
= 3.4 =
|
813 |
-
* Refactored backend UI implementation
|
814 |
-
* Integrated Utilities extension to the core
|
815 |
-
* Improved capability management functionality
|
816 |
-
* Improved UI
|
817 |
-
* Added caching mechanism to the core
|
818 |
-
* Improved caching mechanism
|
819 |
-
* Fixed few functional bugs
|
820 |
-
|
821 |
-
= 3.3 =
|
822 |
-
* Improved UI
|
823 |
-
* Completely protect Admin Menu if restricted
|
824 |
-
* Tiny core refactoring
|
825 |
-
* Rewrote UI descriptions
|
826 |
-
|
827 |
-
= 3.2.3 =
|
828 |
-
* Quick fix for extensions ajax calls
|
829 |
-
|
830 |
-
= 3.2.2 =
|
831 |
-
* Improved AAM security reported by James Golovich from Pritect
|
832 |
-
* Extended core to allow manage access to AAM features via ConfigPress
|
833 |
-
|
834 |
-
= 3.2.1 =
|
835 |
-
* Added show_screen_options capability support to control Screen Options Tab
|
836 |
-
* Added show_help_tabs capability support to control Help Tabs
|
837 |
-
* Added AAM Support
|
838 |
-
|
839 |
-
= 3.2 =
|
840 |
-
* Fixed minor bug reporetd by WP Error Fix
|
841 |
-
* Extended core functionality to support filter by author for Plus Package
|
842 |
-
* Added Contact Us tab
|
843 |
-
|
844 |
-
= 3.1.5 =
|
845 |
-
* Improved UI
|
846 |
-
* Fixed the bug reported by WP Error Fix
|
847 |
-
|
848 |
-
= 3.1.4 =
|
849 |
-
* Fixed bug with menu/metabox checkbox
|
850 |
-
* Added extra hook to clear the user cache after profile update
|
851 |
-
* Added drill-down button for Posts & Pages tab
|
852 |
-
|
853 |
-
= 3.1.3.1 =
|
854 |
-
* One more minor issue
|
855 |
-
|
856 |
-
= 3.1.3 =
|
857 |
-
* Fixed bug with default post settings
|
858 |
-
* Filtering roles and capabilities form malicious code
|
859 |
-
|
860 |
-
= 3.1.2 =
|
861 |
-
* Quick fix
|
862 |
-
|
863 |
-
= 3.1.1 =
|
864 |
-
* Fixed potential bug with check user capability functionality
|
865 |
-
* Added social links to the AAM page
|
866 |
-
|
867 |
-
= 3.1 =
|
868 |
-
* Integrated User Switch with AAM
|
869 |
-
* Fixed bugs reported by WP Error Fix
|
870 |
-
* Removed intro message
|
871 |
-
* Improved AAM speed
|
872 |
-
* Updated AAM Utilities extension
|
873 |
-
* Updated AAM Plus Package extension
|
874 |
-
* Added new AAM Skeleton Extension for developers
|
875 |
-
|
876 |
-
= 3.0.10 =
|
877 |
-
* Fixed bug reported by WP Error Fix when user's first role does not exist
|
878 |
-
* Fixed bug reported by WP Error Fix when roles has invalid capability set
|
879 |
-
|
880 |
-
= 3.0.9 =
|
881 |
-
* Added ability to extend the AAM Utilities property list
|
882 |
-
* Updated AAM Plus Package with ability to toggle the page categories feature
|
883 |
-
* Added WP Error Fix promotion tab
|
884 |
-
* Finalized and resolved all known issues
|
885 |
-
|
886 |
-
= 3.0.8 =
|
887 |
-
* Extended AAM with few extra core filters and actions
|
888 |
-
* Added role list sorting by name
|
889 |
-
* Added WP Error Fix item to the extension list
|
890 |
-
* Fixed the issue with language file
|
891 |
-
|
892 |
-
= 3.0.7 =
|
893 |
-
* Fixed the warning issue with newly installed AAM instance
|
894 |
-
|
895 |
-
= 3.0.6 =
|
896 |
-
* Fixed issue when server has security policy regarding file_get_content as URL
|
897 |
-
* Added filters to support Edit/Delete caps with AAM Utilities extension
|
898 |
-
* Updated AAM Utilities extension
|
899 |
-
* Refactored extension list manager
|
900 |
-
* Added AAM Role Filter extension
|
901 |
-
* Added AAM Post Filter extension
|
902 |
-
* Standardize the extension folder name
|
903 |
-
|
904 |
-
= 3.0.5 =
|
905 |
-
* Wrapped all *.phtml files into condition to avoid crash on direct file access
|
906 |
-
* Fixed bug with Visitor subject API
|
907 |
-
* Added internal capability id to the list of capabilities
|
908 |
-
* Fixed bug with strict standard notice
|
909 |
-
* Fixed bug when extension after update still indicates that update is needed
|
910 |
-
* Fixed bug when extensions were not able to load js & css on windows server
|
911 |
-
* Updated AAM Utilities extension
|
912 |
-
* Updated AAM Multisite extension
|
913 |
-
|
914 |
-
= 3.0.4 =
|
915 |
-
* Improved the Metaboxes & Widget filtering on user level
|
916 |
-
* Improved visual feedback for already installed extensions
|
917 |
-
* Fixed the bug when posts and categories were filtered on the AAM page
|
918 |
-
* Significantly improved the posts & pages inheritance mechanism
|
919 |
-
* Updated and fixed bugs in AAM Plus Package and AAM Utilities
|
920 |
-
* Improved AAM navigation during page reload
|
921 |
-
* Removed Trash post access option. Now Delete option is the same
|
922 |
-
* Added UI feedback on current posts, menu and metaboxes inheritance status
|
923 |
-
* Updated AAM Multisite extension
|
924 |
-
|
925 |
-
= 3.0.3 =
|
926 |
-
* Fixed bug with backend menu saving
|
927 |
-
* Fixed bug with metaboxes & widgets saving
|
928 |
-
* Fixed bug with WP_Filesystem when non-standard filesystem is used
|
929 |
-
* Optimized Posts & Pages breadcrumb load
|
930 |
-
|
931 |
-
= 3.0.2 =
|
932 |
-
* Fixed a bug with posts access within categories
|
933 |
-
* Significantly improved the caching mechanism
|
934 |
-
* Added mandatory notification if caching is not turned on
|
935 |
-
* Added more help content
|
936 |
-
|
937 |
-
= 3.0.1 =
|
938 |
-
* Fixed the bug with capability saving
|
939 |
-
* Fixed the bug with capability drop-down menu
|
940 |
-
* Made backend menu help is more clear
|
941 |
-
* Added tooltips to some UI buttons
|
942 |
-
|
943 |
-
= 3.0 =
|
944 |
-
* Brand new and much more intuitive user interface
|
945 |
-
* Fully responsive design
|
946 |
-
* Better, more reliable and faster core functionality
|
947 |
-
* Completely new extension handler
|
948 |
-
* Added "Manage Access" action to the list of user
|
949 |
-
* Tested against WP 3.8 and PHP 5.2.17 versions
|
950 |
-
|
951 |
-
= 2.9.4 =
|
952 |
-
* Added missing files from the previous commit.
|
953 |
-
|
954 |
-
= 2.9.3 =
|
955 |
-
* Introduced AAM version 3 alpha
|
956 |
-
|
957 |
-
= 2.9.2 =
|
958 |
-
* Small fix in core
|
959 |
-
* Moved ConfigPress as stand-alone plugin. It is no longer a part of AAM
|
960 |
-
* Styled the AAM notification message
|
961 |
-
|
962 |
-
= 2.8.8 =
|
963 |
-
* AAM is changing the primary owner to VasylTech
|
964 |
-
* Removed contextual help menu
|
965 |
-
* Added notification about AAM v3
|
966 |
-
|
967 |
-
= 2.8.7 =
|
968 |
-
* Tested and verified functionality on the latest WordPress release
|
969 |
-
* Removed AAM Plus Package. Happy hours are over.
|
970 |
-
|
971 |
-
= 2.8.5 =
|
972 |
-
* Fixed bugs reported by (@TheThree)
|
973 |
-
* Improved CSS
|
974 |
-
|
975 |
-
= 2.8.4 =
|
976 |
-
* Updated the extension list pricing
|
977 |
-
* Updated AAM Plugin Manager
|
978 |
-
|
979 |
-
= 2.8.3 =
|
980 |
-
* Improved ConfigPress security (thanks to Tom Adams from security.dxw.com)
|
981 |
-
* Added ConfigPress new setting control_permalink
|
982 |
-
|
983 |
-
= 2.8.2 =
|
984 |
-
* Fixed issue with Default acces to posts/pages for AAM Plus Package
|
985 |
-
* Fixed issue with AAM Plugin Manager for lower PHP version
|
986 |
-
|
987 |
-
= 2.8.1 =
|
988 |
-
* Simplified the Repository internal handling
|
989 |
-
* Added Development License Support
|
990 |
-
|
991 |
-
= 2.8 =
|
992 |
-
* Fixed issue with AAM Control Manage HTML
|
993 |
-
* Fixed issue with __PHP_Incomplete_Class
|
994 |
-
* Added AAM Plugin Manager Extension
|
995 |
-
* Removed Deprecated ConfigPress Object from the core
|
996 |
-
|
997 |
-
= 2.7 =
|
998 |
-
* Fixed bug with subject managing check
|
999 |
-
* Fixed bug with update hook
|
1000 |
-
* Fixed issue with extension activation hook
|
1001 |
-
* Added AAM Security Feature. First iteration
|
1002 |
-
* Improved CSS
|
1003 |
-
|
1004 |
-
= 2.6 =
|
1005 |
-
* Fixed bug with user inheritance
|
1006 |
-
* Fixed bug with user restore default settings
|
1007 |
-
* Fixed bug with installed extension detection
|
1008 |
-
* Improved core extension handling
|
1009 |
-
* Improved subject inheritance mechanism
|
1010 |
-
* Removed deprecated ConfigPress Tutorial
|
1011 |
-
* Optimized CSS
|
1012 |
-
* Regenerated translation pot file
|
1013 |
-
|
1014 |
-
= 2.5 =
|
1015 |
-
* Fixed issue with AAM Plus Package and Multisite
|
1016 |
-
* Introduced Development License
|
1017 |
-
* Minor internal adjustment for AAM Development Community
|
1018 |
-
|
1019 |
-
= 2.4 =
|
1020 |
-
* Added Norwegian language Norwegian (by Christer Berg Johannesen)
|
1021 |
-
* Localize the default Roles
|
1022 |
-
* Regenerated .pod file
|
1023 |
-
* Added AAM Media Manager Extension
|
1024 |
-
* Added AAM Content Manager Extension
|
1025 |
-
* Standardized Extension Services
|
1026 |
-
* Fixed issue with Media list
|
1027 |
-
|
1028 |
-
= 2.3 =
|
1029 |
-
* Added Persian translation by Ghaem Omidi
|
1030 |
-
* Added Inherit Capabilities From Role drop-down on Add New Role Dialog
|
1031 |
-
* Small Cosmetic CSS changes
|
1032 |
-
|
1033 |
-
= 2.2 =
|
1034 |
-
* Fixed issue with jQuery UI Tooltip Widget
|
1035 |
-
* Added AAM Warning Panel
|
1036 |
-
* Added Event Log Feature
|
1037 |
-
* Moved ConfigPress to separate Page (refactored internal handling)
|
1038 |
-
* Reverted back the SSL handling
|
1039 |
-
* Added Post Delete feature
|
1040 |
-
* Added Post's Restore Default Restrictions feature
|
1041 |
-
* Added ConfigPress Extension turn on/off setting
|
1042 |
-
* Russian translation by (Maxim Kernozhitskiy https://aeromultimedia.com)
|
1043 |
-
* Removed Migration possibility
|
1044 |
-
* Refactored AAM Core Console model
|
1045 |
-
* Increased the number of saved restriction for basic version
|
1046 |
-
* Simplified Undo feature
|
1047 |
-
|
1048 |
-
= 2.1 =
|
1049 |
-
* Fixed issue with Admin Menu restrictions (thanks to MikeB2B)
|
1050 |
-
* Added Polish Translation
|
1051 |
-
* Fixed issue with Widgets restriction
|
1052 |
-
* Improved internal User & Role handling
|
1053 |
-
* Implemented caching mechanism
|
1054 |
-
* Extended Update mechanism (remove the AAM cache after update)
|
1055 |
-
* Added New ConfigPress setting aam.caching (by default is FALSE)
|
1056 |
-
* Improved Metabox & Widgets filtering mechanism
|
1057 |
-
* Added French Translation (by Moskito7)
|
1058 |
-
* Added "My Feature" Tab
|
1059 |
-
* Regenerated .pot file
|
1060 |
-
|
1061 |
-
= 2.0 =
|
1062 |
-
* New UI
|
1063 |
-
* Robust and completely new core functionality
|
1064 |
-
* Over 3 dozen of bug fixed and improvement during 3 alpha & beta versions
|
1065 |
-
* Improved Update mechanism
|
1066 |
-
|
1067 |
-
= 1.0 =
|
1068 |
-
* Fixed issue with comment editing
|
1069 |
-
* Implemented JavaScript error catching
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/IpCheck/IpCheckTest.php
DELETED
@@ -1,343 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\IpCheck;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Service_Content,
|
14 |
-
AAM_Core_Object_Post,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\AddOn\IPCheck\Object\IPCheck as IPCheckObject;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Test cases for the IP Check addon
|
21 |
-
*
|
22 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
23 |
-
* @version 6.0.0
|
24 |
-
*/
|
25 |
-
class IpCheckTest extends TestCase
|
26 |
-
{
|
27 |
-
use ResetTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test that entire website is restricted when IP matched
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testEntireWebsiteRestricted()
|
38 |
-
{
|
39 |
-
// Override the default handlers so we can suppress die exit
|
40 |
-
add_filter('wp_die_handler', function() {
|
41 |
-
return function($message, $title) {
|
42 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
43 |
-
};
|
44 |
-
}, PHP_INT_MAX);
|
45 |
-
|
46 |
-
// Fake the IP address
|
47 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
48 |
-
|
49 |
-
$object = AAM::getUser()->getObject(IPCheckObject::OBJECT_TYPE);
|
50 |
-
$this->assertTrue($object->updateOptionItem('ip|127.0.0.1', true)->save());
|
51 |
-
|
52 |
-
// Capture the WP Die message
|
53 |
-
ob_start();
|
54 |
-
do_action('wp');
|
55 |
-
$content = ob_get_contents();
|
56 |
-
ob_end_clean();
|
57 |
-
|
58 |
-
$this->assertStringContainsString('Access Denied', $content);
|
59 |
-
|
60 |
-
// Reset WP Query
|
61 |
-
remove_all_filters('wp_die_handler', PHP_INT_MAX);
|
62 |
-
unset($_SERVER['REMOTE_ADDR']);
|
63 |
-
}
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Test that access is denied based on user IP address
|
67 |
-
*
|
68 |
-
* @return void
|
69 |
-
*
|
70 |
-
* @access public
|
71 |
-
* @version 6.0.0
|
72 |
-
*/
|
73 |
-
public function testPageRestrictedByIp()
|
74 |
-
{
|
75 |
-
$object = AAM::getUser()->getObject(
|
76 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
77 |
-
);
|
78 |
-
|
79 |
-
// Set restriction
|
80 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
81 |
-
'rules' => array(
|
82 |
-
'ip|127.0.0.1' => true,
|
83 |
-
),
|
84 |
-
'enabled' => true
|
85 |
-
))->save());
|
86 |
-
|
87 |
-
// Reset all internal cache
|
88 |
-
$this->_resetSubjects();
|
89 |
-
|
90 |
-
// Verify that access is denied by IP address
|
91 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
92 |
-
|
93 |
-
$post = AAM::getUser()->getObject(
|
94 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
95 |
-
);
|
96 |
-
|
97 |
-
$result = AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post);
|
98 |
-
$this->assertEquals('WP_Error', get_class($result));
|
99 |
-
$this->assertEquals(
|
100 |
-
'User is unauthorized to access this post. Access Denied.',
|
101 |
-
$result->get_error_message()
|
102 |
-
);
|
103 |
-
|
104 |
-
// Reset original state
|
105 |
-
unset($_SERVER['REMOTE_ADDR']);
|
106 |
-
}
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Test that access is denied for wildcard IP address
|
110 |
-
*
|
111 |
-
* @return void
|
112 |
-
*
|
113 |
-
* @access public
|
114 |
-
* @version 6.0.0
|
115 |
-
*/
|
116 |
-
public function testPageRestrictedByIpWildcard()
|
117 |
-
{
|
118 |
-
$object = AAM::getUser()->getObject(
|
119 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
120 |
-
);
|
121 |
-
|
122 |
-
// Set restriction
|
123 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
124 |
-
'rules' => array(
|
125 |
-
'ip|127.0.0.*' => true,
|
126 |
-
),
|
127 |
-
'enabled' => true
|
128 |
-
))->save());
|
129 |
-
|
130 |
-
// Reset all internal cache
|
131 |
-
$this->_resetSubjects();
|
132 |
-
|
133 |
-
// Verify that access is denied by IP address
|
134 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.3';
|
135 |
-
|
136 |
-
$post = AAM::getUser()->getObject(
|
137 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
138 |
-
);
|
139 |
-
|
140 |
-
$result = AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post);
|
141 |
-
$this->assertEquals('WP_Error', get_class($result));
|
142 |
-
$this->assertEquals(
|
143 |
-
'User is unauthorized to access this post. Access Denied.',
|
144 |
-
$result->get_error_message()
|
145 |
-
);
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Test that access is denied for the IP range
|
150 |
-
*
|
151 |
-
* @return void
|
152 |
-
*
|
153 |
-
* @access public
|
154 |
-
* @version 6.0.0
|
155 |
-
*/
|
156 |
-
public function testPageRestrictedByIpRange()
|
157 |
-
{
|
158 |
-
$object = AAM::getUser()->getObject(
|
159 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
160 |
-
);
|
161 |
-
|
162 |
-
// Set restriction
|
163 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
164 |
-
'rules' => array(
|
165 |
-
'ip|127.0.0.0-20' => true,
|
166 |
-
),
|
167 |
-
'enabled' => true
|
168 |
-
))->save());
|
169 |
-
|
170 |
-
// Reset all internal cache
|
171 |
-
$this->_resetSubjects();
|
172 |
-
|
173 |
-
// Verify that access is denied by IP address
|
174 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.5';
|
175 |
-
|
176 |
-
$post = AAM::getUser()->getObject(
|
177 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
178 |
-
);
|
179 |
-
|
180 |
-
$result = AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post);
|
181 |
-
$this->assertEquals('WP_Error', get_class($result));
|
182 |
-
$this->assertEquals(
|
183 |
-
'User is unauthorized to access this post. Access Denied.',
|
184 |
-
$result->get_error_message()
|
185 |
-
);
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Test that access is denied by the referred host
|
190 |
-
*
|
191 |
-
* @return void
|
192 |
-
*
|
193 |
-
* @access public
|
194 |
-
* @version 6.0.0
|
195 |
-
*/
|
196 |
-
public function testPageRestrictedByHost()
|
197 |
-
{
|
198 |
-
$object = AAM::getUser()->getObject(
|
199 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
200 |
-
);
|
201 |
-
|
202 |
-
// Set restriction
|
203 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
204 |
-
'rules' => array(
|
205 |
-
'host|example.local' => true,
|
206 |
-
),
|
207 |
-
'enabled' => true
|
208 |
-
))->save());
|
209 |
-
|
210 |
-
// Reset all internal cache
|
211 |
-
$this->_resetSubjects();
|
212 |
-
|
213 |
-
// Verify that access is denied by referred host
|
214 |
-
$_SERVER['HTTP_REFERER'] = 'https://example.local';
|
215 |
-
|
216 |
-
$post = AAM::getUser()->getObject(
|
217 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
218 |
-
);
|
219 |
-
|
220 |
-
$result = AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post);
|
221 |
-
$this->assertEquals('WP_Error', get_class($result));
|
222 |
-
$this->assertEquals(
|
223 |
-
'User is unauthorized to access this post. Access Denied.',
|
224 |
-
$result->get_error_message()
|
225 |
-
);
|
226 |
-
}
|
227 |
-
|
228 |
-
/**
|
229 |
-
* Test that access is denied by query param
|
230 |
-
*
|
231 |
-
* @return void
|
232 |
-
*
|
233 |
-
* @access public
|
234 |
-
* @version 6.0.0
|
235 |
-
*/
|
236 |
-
public function testPageRestrictedByRef()
|
237 |
-
{
|
238 |
-
$object = AAM::getUser()->getObject(
|
239 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
240 |
-
);
|
241 |
-
|
242 |
-
// Set restriction
|
243 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
244 |
-
'rules' => array(
|
245 |
-
'ref|test' => true,
|
246 |
-
),
|
247 |
-
'enabled' => true
|
248 |
-
))->save());
|
249 |
-
|
250 |
-
// Reset all internal cache
|
251 |
-
$this->_resetSubjects();
|
252 |
-
|
253 |
-
// Verify that access is denied by ref
|
254 |
-
$_GET['ref'] = 'test';
|
255 |
-
|
256 |
-
$post = AAM::getUser()->getObject(
|
257 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
258 |
-
);
|
259 |
-
|
260 |
-
$result = AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post);
|
261 |
-
$this->assertEquals('WP_Error', get_class($result));
|
262 |
-
$this->assertEquals(
|
263 |
-
'User is unauthorized to access this post. Access Denied.',
|
264 |
-
$result->get_error_message()
|
265 |
-
);
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* Test that cookie with JWT is sent when access is granted
|
270 |
-
*
|
271 |
-
* @return void
|
272 |
-
*
|
273 |
-
* @access public
|
274 |
-
* @version 6.0.0
|
275 |
-
*/
|
276 |
-
public function testWebsiteAccessCookieSetup()
|
277 |
-
{
|
278 |
-
// Fake the IP address
|
279 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
280 |
-
|
281 |
-
$object = AAM::getUser()->getObject(IPCheckObject::OBJECT_TYPE);
|
282 |
-
$this->assertTrue($object->updateOptionItem('ip|127.0.0.1', false)->save());
|
283 |
-
|
284 |
-
// Capture the WP Die message
|
285 |
-
ob_start();
|
286 |
-
do_action('wp');
|
287 |
-
ob_end_clean();
|
288 |
-
|
289 |
-
$this->assertCount(1, array_filter(xdebug_get_headers(), function($m) {
|
290 |
-
return (strpos($m, 'aam_ipcheck_jwt=') !== false);
|
291 |
-
}));
|
292 |
-
|
293 |
-
// Reset WP Query
|
294 |
-
unset($_SERVER['REMOTE_ADDR']);
|
295 |
-
header_remove('Set-Cookie');
|
296 |
-
}
|
297 |
-
|
298 |
-
/**
|
299 |
-
* Test that cookie with JWT is sent when access to page is granted
|
300 |
-
*
|
301 |
-
* @return void
|
302 |
-
*
|
303 |
-
* @access public
|
304 |
-
* @version 6.0.0
|
305 |
-
*/
|
306 |
-
public function testPageAccessCookieSetup()
|
307 |
-
{
|
308 |
-
$object = AAM::getUser()->getObject(
|
309 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
310 |
-
);
|
311 |
-
|
312 |
-
// Set restriction
|
313 |
-
$this->assertTrue($object->updateOptionItem('selective', array(
|
314 |
-
'rules' => array(
|
315 |
-
'ip|127.0.0.0-20' => false,
|
316 |
-
),
|
317 |
-
'enabled' => true
|
318 |
-
))->save());
|
319 |
-
|
320 |
-
// Reset all internal cache
|
321 |
-
$this->_resetSubjects();
|
322 |
-
|
323 |
-
// Verify that access is denied by IP address
|
324 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.5';
|
325 |
-
|
326 |
-
$post = AAM::getUser()->getObject(
|
327 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
328 |
-
);
|
329 |
-
|
330 |
-
$this->assertTrue(
|
331 |
-
AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post)
|
332 |
-
);
|
333 |
-
|
334 |
-
// Note! 2 is because there is no way to clear sent headers with xdebug_*
|
335 |
-
$this->assertCount(2, array_filter(xdebug_get_headers(), function($m) {
|
336 |
-
return (strpos($m, 'aam_ipcheck_jwt=') !== false);
|
337 |
-
}));
|
338 |
-
|
339 |
-
// Reset WP Query
|
340 |
-
unset($_SERVER['REMOTE_ADDR']);
|
341 |
-
}
|
342 |
-
|
343 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/PlusPackage/ContentAccessTest.php
DELETED
@@ -1,451 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\PlusPackage;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Post,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait,
|
17 |
-
AAM\AddOn\PlusPackage\Object\Term,
|
18 |
-
AAM\AddOn\PlusPackage\Object\Type,
|
19 |
-
AAM\AddOn\PlusPackage\Object\Taxonomy,
|
20 |
-
AAM\AddOn\PlusPackage\Hooks\ContentHooks;
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Test cases for the Plus Package content access management
|
24 |
-
*
|
25 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
26 |
-
* @version 6.0.0
|
27 |
-
*/
|
28 |
-
class ContentAccessTest extends TestCase
|
29 |
-
{
|
30 |
-
use ResetTrait,
|
31 |
-
AuthUserTrait;
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Test that access settings are inherited from the parent term
|
35 |
-
*
|
36 |
-
* @return void
|
37 |
-
*
|
38 |
-
* @access public
|
39 |
-
* @version 6.0.0
|
40 |
-
*/
|
41 |
-
public function testInheritPostAccessFromParentTerm()
|
42 |
-
{
|
43 |
-
$user = AAM::getUser();
|
44 |
-
$object = $user->getObject(
|
45 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
46 |
-
);
|
47 |
-
|
48 |
-
// Check if save returns positive result
|
49 |
-
$this->assertTrue($object->updateOptionItem('post/hidden', true)->save());
|
50 |
-
|
51 |
-
// Reset all internal cache
|
52 |
-
$this->_resetSubjects();
|
53 |
-
ContentHooks::bootstrap()->resetCache();
|
54 |
-
|
55 |
-
$post = $user->getObject(
|
56 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
57 |
-
);
|
58 |
-
|
59 |
-
$this->assertTrue($post->is('hidden'));
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Test that access settings are inherited from the parent post type
|
64 |
-
*
|
65 |
-
* @return void
|
66 |
-
*
|
67 |
-
* @access public
|
68 |
-
* @version 6.0.0
|
69 |
-
*/
|
70 |
-
public function testInheritPostAccessFromParentType()
|
71 |
-
{
|
72 |
-
$user = AAM::getUser();
|
73 |
-
$object = $user->getObject(Type::OBJECT_TYPE, 'post');
|
74 |
-
|
75 |
-
// Check if save returns positive result
|
76 |
-
$this->assertTrue($object->updateOptionItem('post/hidden', true)->save());
|
77 |
-
|
78 |
-
// Reset all internal cache
|
79 |
-
$this->_resetSubjects();
|
80 |
-
ContentHooks::bootstrap()->resetCache();
|
81 |
-
|
82 |
-
$post = $user->getObject(
|
83 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
84 |
-
);
|
85 |
-
|
86 |
-
$this->assertTrue($post->is('hidden'));
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Test that access settings are inherited from the parent post
|
91 |
-
*
|
92 |
-
* @return void
|
93 |
-
*
|
94 |
-
* @access public
|
95 |
-
* @version 6.0.0
|
96 |
-
*/
|
97 |
-
public function testInheritFromParentPost()
|
98 |
-
{
|
99 |
-
$user = AAM::getUser();
|
100 |
-
$object = $user->getObject(
|
101 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_PAGE_LEVEL_1_ID
|
102 |
-
);
|
103 |
-
|
104 |
-
// Check if save returns positive result
|
105 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
106 |
-
|
107 |
-
// Reset all internal cache
|
108 |
-
$this->_resetSubjects();
|
109 |
-
|
110 |
-
$post = $user->getObject(
|
111 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_PAGE_LEVEL_2_ID
|
112 |
-
);
|
113 |
-
|
114 |
-
$this->assertTrue($post->is('hidden'));
|
115 |
-
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Test access settings adjusting based on [ACTION]_OTHERS access option
|
119 |
-
*
|
120 |
-
* @return void
|
121 |
-
*
|
122 |
-
* @access public
|
123 |
-
* @version 6.0.0
|
124 |
-
*/
|
125 |
-
public function testAdjustedPostAccessSettings()
|
126 |
-
{
|
127 |
-
// Make other user as the owner of the post
|
128 |
-
wp_update_post(array(
|
129 |
-
'ID' => AAM_UNITTEST_POST_ID,
|
130 |
-
'post_author' => AAM_UNITTEST_JOHN_ID
|
131 |
-
));
|
132 |
-
|
133 |
-
$user = AAM::getUser();
|
134 |
-
$object = $user->getObject(Type::OBJECT_TYPE, 'post');
|
135 |
-
|
136 |
-
foreach(array('edit', 'hidden', 'delete', 'publish', 'restricted') as $act) {
|
137 |
-
$object->updateOptionItem("post/{$act}_others", true);
|
138 |
-
}
|
139 |
-
|
140 |
-
// Check if save returns positive result
|
141 |
-
$this->assertTrue($object->save());
|
142 |
-
|
143 |
-
// Reset all internal cache
|
144 |
-
$this->_resetSubjects();
|
145 |
-
ContentHooks::bootstrap()->resetCache();
|
146 |
-
|
147 |
-
$post = $user->getObject(
|
148 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
149 |
-
);
|
150 |
-
|
151 |
-
$this->assertTrue($post->is('hidden'));
|
152 |
-
$this->assertTrue($post->is('restricted'));
|
153 |
-
$this->assertFalse($post->isAllowedTo('edit'));
|
154 |
-
$this->assertFalse($post->isAllowedTo('delete'));
|
155 |
-
$this->assertFalse($post->isAllowedTo('publish'));
|
156 |
-
|
157 |
-
// Reset back to the original author
|
158 |
-
wp_update_post(array(
|
159 |
-
'ID' => AAM_UNITTEST_POST_ID,
|
160 |
-
'post_author' => AAM_UNITTEST_AUTH_USER_ID
|
161 |
-
));
|
162 |
-
}
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Test that access is denied to create a new post of a specific post type
|
166 |
-
*
|
167 |
-
* @return void
|
168 |
-
*
|
169 |
-
* @access public
|
170 |
-
* @version 6.0.0
|
171 |
-
*/
|
172 |
-
public function testDenyCreateNewPost()
|
173 |
-
{
|
174 |
-
$user = AAM::getUser();
|
175 |
-
$object = $user->getObject(Type::OBJECT_TYPE, 'aam_test');
|
176 |
-
|
177 |
-
// Check if save returns positive result
|
178 |
-
$this->assertTrue($object->updateOptionItem('post/create', true)->save());
|
179 |
-
|
180 |
-
// Reset all internal cache
|
181 |
-
$this->_resetSubjects();
|
182 |
-
ContentHooks::bootstrap()->resetCache();
|
183 |
-
|
184 |
-
register_post_type('aam_test', array(
|
185 |
-
'label' => __('AAM Test', AAM_KEY),
|
186 |
-
'description' => __('Just for testing purposes', AAM_KEY)
|
187 |
-
));
|
188 |
-
|
189 |
-
$this->assertEquals(
|
190 |
-
get_post_type_object('aam_test')->cap->create_posts, 'do_not_allow'
|
191 |
-
);
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Test that access is denied to edit or create a new term of a specific taxonomy
|
196 |
-
*
|
197 |
-
* @return void
|
198 |
-
*
|
199 |
-
* @access public
|
200 |
-
* @version 6.0.0
|
201 |
-
*/
|
202 |
-
public function testDenyCreateOrEditTaxonomy()
|
203 |
-
{
|
204 |
-
$user = AAM::getUser();
|
205 |
-
$object = $user->getObject(Taxonomy::OBJECT_TYPE, 'aam_test');
|
206 |
-
|
207 |
-
// Check if save returns positive result
|
208 |
-
$this->assertTrue($object->updateOptionItem('term/edit', true)->save());
|
209 |
-
|
210 |
-
// Reset all internal cache
|
211 |
-
$this->_resetSubjects();
|
212 |
-
ContentHooks::bootstrap()->resetCache();
|
213 |
-
|
214 |
-
register_taxonomy('aam_test', 'post', array('hierarchical' => true));
|
215 |
-
|
216 |
-
$this->assertEquals(
|
217 |
-
get_taxonomy('aam_test')->cap->edit_terms, 'do_not_allow'
|
218 |
-
);
|
219 |
-
}
|
220 |
-
|
221 |
-
/**
|
222 |
-
* Test the ability to edit term
|
223 |
-
*
|
224 |
-
* @return void
|
225 |
-
*
|
226 |
-
* @access public
|
227 |
-
* @version 6.0.0
|
228 |
-
*/
|
229 |
-
public function testEditTermAccessOption()
|
230 |
-
{
|
231 |
-
$user = AAM::getUser();
|
232 |
-
$role = $user->getParent(); // Administrator role
|
233 |
-
|
234 |
-
$object = $role->getObject(
|
235 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
236 |
-
);
|
237 |
-
|
238 |
-
$this->assertTrue($object->updateOptionItem('term/edit', true)->save());
|
239 |
-
|
240 |
-
// Reset all internal cache
|
241 |
-
$this->_resetSubjects();
|
242 |
-
ContentHooks::bootstrap()->resetCache();
|
243 |
-
|
244 |
-
$this->assertFalse(current_user_can('edit_term', AAM_UNITTEST_CATEGORY_ID));
|
245 |
-
}
|
246 |
-
|
247 |
-
/**
|
248 |
-
* Test the ability to delete term
|
249 |
-
*
|
250 |
-
* @return void
|
251 |
-
*
|
252 |
-
* @access public
|
253 |
-
* @version 6.0.0
|
254 |
-
*/
|
255 |
-
public function testDeleteTermAccessOption()
|
256 |
-
{
|
257 |
-
$user = AAM::getUser();
|
258 |
-
$role = $user->getParent(); // Administrator role
|
259 |
-
|
260 |
-
$object = $role->getObject(
|
261 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
262 |
-
);
|
263 |
-
|
264 |
-
$this->assertTrue($object->updateOptionItem('term/delete', true)->save());
|
265 |
-
|
266 |
-
// Reset all internal cache
|
267 |
-
$this->_resetSubjects();
|
268 |
-
ContentHooks::bootstrap()->resetCache();
|
269 |
-
|
270 |
-
$this->assertFalse(current_user_can('delete_term', AAM_UNITTEST_CATEGORY_ID));
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* Test the ability to assign term
|
275 |
-
*
|
276 |
-
* @return void
|
277 |
-
*
|
278 |
-
* @access public
|
279 |
-
* @version 6.0.0
|
280 |
-
*/
|
281 |
-
public function testAssignTermAccessOption()
|
282 |
-
{
|
283 |
-
$user = AAM::getUser();
|
284 |
-
$role = $user->getParent(); // Administrator role
|
285 |
-
|
286 |
-
$object = $role->getObject(
|
287 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
288 |
-
);
|
289 |
-
|
290 |
-
$this->assertTrue($object->updateOptionItem('term/assign', true)->save());
|
291 |
-
|
292 |
-
// Reset all internal cache
|
293 |
-
$this->_resetSubjects();
|
294 |
-
ContentHooks::bootstrap()->resetCache();
|
295 |
-
|
296 |
-
$this->assertFalse(current_user_can('assign_term', AAM_UNITTEST_CATEGORY_ID));
|
297 |
-
}
|
298 |
-
|
299 |
-
/**
|
300 |
-
* Test that term filter is working as expected
|
301 |
-
*
|
302 |
-
* There are multiple different ways to fetch the list of terms and this is
|
303 |
-
* defined by the $fields argument WP_Term_Query::__construct.
|
304 |
-
*
|
305 |
-
* @return void
|
306 |
-
*
|
307 |
-
* @access public
|
308 |
-
* @version 6.0.0
|
309 |
-
*/
|
310 |
-
public function testFilterTerms()
|
311 |
-
{
|
312 |
-
$user = AAM::getUser();
|
313 |
-
$role = $user->getParent(); // Administrator role
|
314 |
-
|
315 |
-
$object = $role->getObject(
|
316 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
317 |
-
);
|
318 |
-
|
319 |
-
$this->assertTrue($object->updateOptionItem('term/hidden', true)->save());
|
320 |
-
|
321 |
-
// Reset all internal cache
|
322 |
-
$this->_resetSubjects();
|
323 |
-
ContentHooks::bootstrap()->resetCache();
|
324 |
-
|
325 |
-
$terms = get_terms(array(
|
326 |
-
'number' => 0,
|
327 |
-
'fields' => 'ids',
|
328 |
-
'taxonomy' => 'category',
|
329 |
-
'hide_empty' => false
|
330 |
-
));
|
331 |
-
|
332 |
-
$this->assertFalse(in_array(AAM_UNITTEST_CATEGORY_ID, $terms));
|
333 |
-
|
334 |
-
$terms = get_terms(array(
|
335 |
-
'number' => 0,
|
336 |
-
'fields' => 'id=>slug',
|
337 |
-
'taxonomy' => 'category',
|
338 |
-
'hide_empty' => false
|
339 |
-
));
|
340 |
-
|
341 |
-
$this->assertFalse(array_key_exists(AAM_UNITTEST_CATEGORY_ID, $terms));
|
342 |
-
|
343 |
-
$terms = get_terms(array(
|
344 |
-
'number' => 0,
|
345 |
-
'fields' => 'id=>name',
|
346 |
-
'taxonomy' => 'category',
|
347 |
-
'hide_empty' => false
|
348 |
-
));
|
349 |
-
|
350 |
-
$this->assertFalse(array_key_exists(AAM_UNITTEST_CATEGORY_ID, $terms));
|
351 |
-
|
352 |
-
$terms = get_terms(array(
|
353 |
-
'number' => 0,
|
354 |
-
'fields' => 'id=>parent',
|
355 |
-
'taxonomy' => 'category',
|
356 |
-
'hide_empty' => false
|
357 |
-
));
|
358 |
-
|
359 |
-
$this->assertFalse(array_key_exists(AAM_UNITTEST_CATEGORY_ID, $terms));
|
360 |
-
|
361 |
-
$terms = get_terms(array(
|
362 |
-
'number' => 0,
|
363 |
-
'fields' => 'all',
|
364 |
-
'taxonomy' => 'category',
|
365 |
-
'hide_empty' => false
|
366 |
-
));
|
367 |
-
|
368 |
-
$this->assertCount(0, array_filter($terms, function($term) {
|
369 |
-
return $term->term_id === AAM_UNITTEST_CATEGORY_ID;
|
370 |
-
}));
|
371 |
-
}
|
372 |
-
|
373 |
-
/**
|
374 |
-
* Test that navigation menu is filtered as expected
|
375 |
-
*
|
376 |
-
* @return void
|
377 |
-
*
|
378 |
-
* @access public
|
379 |
-
* @version 5.0.0
|
380 |
-
*/
|
381 |
-
public function testFilterNavMenu()
|
382 |
-
{
|
383 |
-
$user = AAM::getUser();
|
384 |
-
$role = $user->getParent(); // Administrator role
|
385 |
-
|
386 |
-
$object = $role->getObject(
|
387 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
388 |
-
);
|
389 |
-
|
390 |
-
$this->assertTrue($object->updateOptionItem('term/hidden', true)->save());
|
391 |
-
|
392 |
-
// Reset all internal cache
|
393 |
-
$this->_resetSubjects();
|
394 |
-
ContentHooks::bootstrap()->resetCache();
|
395 |
-
|
396 |
-
$menu = wp_get_nav_menu_items(AAM_UNITTEST_NAV_MENU_NAME);
|
397 |
-
|
398 |
-
$this->assertCount(0, array_filter($menu, function($item) {
|
399 |
-
return $item->object_id === AAM_UNITTEST_CATEGORY_ID && $item->object === 'category';
|
400 |
-
}));
|
401 |
-
}
|
402 |
-
|
403 |
-
/**
|
404 |
-
* Test that access is denied to browse the category
|
405 |
-
*
|
406 |
-
* @return void
|
407 |
-
*
|
408 |
-
* @access public
|
409 |
-
* @version 6.0.0
|
410 |
-
*/
|
411 |
-
public function testTermBrowseAccessOption()
|
412 |
-
{
|
413 |
-
global $wp_query;
|
414 |
-
|
415 |
-
$user = AAM::getUser();
|
416 |
-
$role = $user->getParent(); // Administrator role
|
417 |
-
|
418 |
-
$object = $role->getObject(
|
419 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
420 |
-
);
|
421 |
-
|
422 |
-
$this->assertTrue($object->updateOptionItem('term/browse', true)->save());
|
423 |
-
|
424 |
-
$wp_query->is_category = true;
|
425 |
-
$wp_query->queried_object = get_term(AAM_UNITTEST_CATEGORY_ID, 'category');
|
426 |
-
|
427 |
-
// Override the default handlers so we can suppress die exit
|
428 |
-
add_filter('wp_die_handler', function() {
|
429 |
-
return function($message, $title) {
|
430 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
431 |
-
};
|
432 |
-
}, PHP_INT_MAX);
|
433 |
-
|
434 |
-
// Capture the WP Die message
|
435 |
-
ob_start();
|
436 |
-
do_action('wp');
|
437 |
-
$content = ob_get_contents();
|
438 |
-
ob_end_clean();
|
439 |
-
|
440 |
-
$this->assertStringContainsString(
|
441 |
-
'Access denied to browse this category', $content
|
442 |
-
);
|
443 |
-
|
444 |
-
// Reset WP Query
|
445 |
-
remove_all_filters('wp_die_handler', PHP_INT_MAX);
|
446 |
-
|
447 |
-
unset($wp_query->is_category);
|
448 |
-
unset($wp_query->queried_object);
|
449 |
-
}
|
450 |
-
|
451 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/PlusPackage/ContentVisibilityTest.php
DELETED
@@ -1,204 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\PlusPackage;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Post,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait,
|
17 |
-
AAM\AddOn\PlusPackage\Object\Term,
|
18 |
-
AAM\AddOn\PlusPackage\Object\Type,
|
19 |
-
AAM\AddOn\PlusPackage\Hooks\ContentHooks;
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Test cases for the Plus Package content visibility management
|
23 |
-
*
|
24 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
25 |
-
* @version 6.0.0
|
26 |
-
*/
|
27 |
-
class ContentVisibilityTest extends TestCase
|
28 |
-
{
|
29 |
-
use ResetTrait,
|
30 |
-
AuthUserTrait;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Test that page is hidden when parent page is hidden to
|
34 |
-
*
|
35 |
-
* @return void
|
36 |
-
*
|
37 |
-
* @access public
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testInheritanceFromParentPost()
|
41 |
-
{
|
42 |
-
$user = AAM::getUser();
|
43 |
-
$object = $user->getObject(
|
44 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_PAGE_LEVEL_1_ID
|
45 |
-
);
|
46 |
-
|
47 |
-
// Check if save returns positive result
|
48 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
49 |
-
|
50 |
-
// Reset all internal cache
|
51 |
-
$this->_resetSubjects();
|
52 |
-
ContentHooks::bootstrap()->resetCache();
|
53 |
-
|
54 |
-
$posts = get_posts(array(
|
55 |
-
'post_type' => 'page',
|
56 |
-
'fields' => 'ids',
|
57 |
-
'numberposts' => -1,
|
58 |
-
'suppress_filters' => false
|
59 |
-
));
|
60 |
-
|
61 |
-
$this->assertFalse(in_array(AAM_UNITTEST_PAGE_LEVEL_2_ID, $posts));
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Test that post is hidden when parent term states so
|
66 |
-
*
|
67 |
-
* @return void
|
68 |
-
*
|
69 |
-
* @access public
|
70 |
-
* @version 6.0.0
|
71 |
-
*/
|
72 |
-
public function testInheritanceFromParentTerm()
|
73 |
-
{
|
74 |
-
$user = AAM::getUser();
|
75 |
-
$object = $user->getObject(
|
76 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
77 |
-
);
|
78 |
-
|
79 |
-
// Check if save returns positive result
|
80 |
-
$this->assertTrue($object->updateOptionItem('post/hidden', true)->save());
|
81 |
-
|
82 |
-
// Reset all internal cache
|
83 |
-
$this->_resetSubjects();
|
84 |
-
ContentHooks::bootstrap()->resetCache();
|
85 |
-
|
86 |
-
$posts = get_posts(array(
|
87 |
-
'post_type' => 'post',
|
88 |
-
'fields' => 'ids',
|
89 |
-
'numberposts' => -1,
|
90 |
-
'suppress_filters' => false
|
91 |
-
));
|
92 |
-
|
93 |
-
$this->assertFalse(in_array(AAM_UNITTEST_POST_ID, $posts));
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Test that posts are hidden when the entire post type states so
|
98 |
-
*
|
99 |
-
* @return void
|
100 |
-
*
|
101 |
-
* @access public
|
102 |
-
* @version 6.0.0
|
103 |
-
*/
|
104 |
-
public function testInheritanceFromParentType()
|
105 |
-
{
|
106 |
-
$user = AAM::getUser();
|
107 |
-
$object = $user->getObject(
|
108 |
-
Type::OBJECT_TYPE, 'post'
|
109 |
-
);
|
110 |
-
|
111 |
-
// Check if save returns positive result
|
112 |
-
$this->assertTrue($object->updateOptionItem('post/hidden', true)->save());
|
113 |
-
|
114 |
-
// Reset all internal cache
|
115 |
-
$this->_resetSubjects();
|
116 |
-
ContentHooks::bootstrap()->resetCache();
|
117 |
-
|
118 |
-
$posts = get_posts(array(
|
119 |
-
'post_type' => 'post',
|
120 |
-
'fields' => 'ids',
|
121 |
-
'numberposts' => -1,
|
122 |
-
'suppress_filters' => false
|
123 |
-
));
|
124 |
-
|
125 |
-
$this->assertCount(0, $posts);
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Test that post if visible if explicitly defined so
|
130 |
-
*
|
131 |
-
* @return void
|
132 |
-
*
|
133 |
-
* @access public
|
134 |
-
* @version 6.0.0
|
135 |
-
*/
|
136 |
-
public function testInheritanceFromParentTermButOverwritten()
|
137 |
-
{
|
138 |
-
$user = AAM::getUser();
|
139 |
-
$object = $user->getObject(
|
140 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
141 |
-
);
|
142 |
-
|
143 |
-
// Check if save returns positive result
|
144 |
-
$this->assertTrue($object->updateOptionItem('post/hidden', true)->save());
|
145 |
-
|
146 |
-
$post = $user->getObject(
|
147 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
148 |
-
);
|
149 |
-
|
150 |
-
// Check if save returns positive result
|
151 |
-
$this->assertTrue($post->updateOptionItem('hidden', false)->save());
|
152 |
-
|
153 |
-
// Reset all internal cache
|
154 |
-
$this->_resetSubjects();
|
155 |
-
ContentHooks::bootstrap()->resetCache();
|
156 |
-
|
157 |
-
$posts = get_posts(array(
|
158 |
-
'post_type' => 'post',
|
159 |
-
'fields' => 'ids',
|
160 |
-
'numberposts' => -1,
|
161 |
-
'suppress_filters' => false
|
162 |
-
));
|
163 |
-
|
164 |
-
$this->assertContains(AAM_UNITTEST_POST_ID, $posts);
|
165 |
-
}
|
166 |
-
|
167 |
-
/**
|
168 |
-
* Test that post if visible if explicitly defined so
|
169 |
-
*
|
170 |
-
* @return void
|
171 |
-
*
|
172 |
-
* @access public
|
173 |
-
* @version 6.0.0
|
174 |
-
*/
|
175 |
-
public function testInheritanceFromParentTypeButOverwritten()
|
176 |
-
{
|
177 |
-
$user = AAM::getUser();
|
178 |
-
$type = $user->getObject(Type::OBJECT_TYPE, 'post');
|
179 |
-
|
180 |
-
// Check if save returns positive result
|
181 |
-
$this->assertTrue($type->updateOptionItem('post/hidden', true)->save());
|
182 |
-
|
183 |
-
$term = $user->getObject(
|
184 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
185 |
-
);
|
186 |
-
|
187 |
-
// Check if save returns positive result
|
188 |
-
$this->assertTrue($term->updateOptionItem('post/hidden', false)->save());
|
189 |
-
|
190 |
-
// Reset all internal cache
|
191 |
-
$this->_resetSubjects();
|
192 |
-
ContentHooks::bootstrap()->resetCache();
|
193 |
-
|
194 |
-
$posts = get_posts(array(
|
195 |
-
'post_type' => 'post',
|
196 |
-
'fields' => 'ids',
|
197 |
-
'numberposts' => -1,
|
198 |
-
'suppress_filters' => false
|
199 |
-
));
|
200 |
-
|
201 |
-
$this->assertContains(AAM_UNITTEST_POST_ID, $posts);
|
202 |
-
}
|
203 |
-
|
204 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/PlusPackage/DefaultCategoryTest.php
DELETED
@@ -1,226 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\PlusPackage;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM\AddOn\PlusPackage\Main,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthUserTrait,
|
18 |
-
AAM\AddOn\PlusPackage\Object\System;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test default category assignment to a post
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class DefaultCategoryTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test the new default category is assigned to post that has no categories
|
33 |
-
* attached
|
34 |
-
*
|
35 |
-
* @return void
|
36 |
-
*
|
37 |
-
* @access public
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testPostSaveCategoryAssignment()
|
41 |
-
{
|
42 |
-
// Get original post terms
|
43 |
-
$terms = wp_get_object_terms(AAM_UNITTEST_POST_ID, 'category', array(
|
44 |
-
'fields' => 'ids'
|
45 |
-
));
|
46 |
-
|
47 |
-
// Remove all the terms from the post(
|
48 |
-
wp_remove_object_terms(AAM_UNITTEST_POST_ID, $terms, 'category');
|
49 |
-
|
50 |
-
// Set the default category
|
51 |
-
$system = AAM::getUser()->getObject(System::OBJECT_TYPE);
|
52 |
-
$this->assertTrue(
|
53 |
-
$system->updateOptionItem(
|
54 |
-
'defaultTerm.post.category', AAM_UNITTEST_CATEGORY_LEVEL_1_ID
|
55 |
-
)->save()
|
56 |
-
);
|
57 |
-
|
58 |
-
// Reset all internal cache
|
59 |
-
$this->_resetSubjects();
|
60 |
-
|
61 |
-
wp_update_post(array(
|
62 |
-
'ID' => AAM_UNITTEST_POST_ID
|
63 |
-
));
|
64 |
-
|
65 |
-
$new_terms = wp_get_object_terms(AAM_UNITTEST_POST_ID, 'category', array(
|
66 |
-
'fields' => 'ids'
|
67 |
-
));
|
68 |
-
|
69 |
-
$this->assertContains(AAM_UNITTEST_CATEGORY_LEVEL_1_ID, $new_terms);
|
70 |
-
|
71 |
-
// Restore original categories
|
72 |
-
wp_set_object_terms(AAM_UNITTEST_POST_ID, $terms, 'category');
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Test the new default category is not assigned to post that has already
|
77 |
-
* category(s) attached
|
78 |
-
*
|
79 |
-
* @return void
|
80 |
-
*
|
81 |
-
* @access public
|
82 |
-
* @version 6.0.0
|
83 |
-
*/
|
84 |
-
public function testPostSaveCategoryPreserved()
|
85 |
-
{
|
86 |
-
// Get original post terms
|
87 |
-
$terms = wp_get_object_terms(AAM_UNITTEST_POST_ID, 'category', array(
|
88 |
-
'fields' => 'ids'
|
89 |
-
));
|
90 |
-
|
91 |
-
// Make sure that we have at least one category attached
|
92 |
-
$this->assertGreaterThanOrEqual(1, count($terms));
|
93 |
-
|
94 |
-
// Set the default category
|
95 |
-
$system = AAM::getUser()->getObject(System::OBJECT_TYPE);
|
96 |
-
$this->assertTrue(
|
97 |
-
$system->updateOptionItem(
|
98 |
-
'defaultTerm.post.category', AAM_UNITTEST_CATEGORY_LEVEL_1_ID
|
99 |
-
)->save()
|
100 |
-
);
|
101 |
-
|
102 |
-
// Reset all internal cache
|
103 |
-
$this->_resetSubjects();
|
104 |
-
|
105 |
-
wp_update_post(array(
|
106 |
-
'ID' => AAM_UNITTEST_POST_ID
|
107 |
-
));
|
108 |
-
|
109 |
-
$new_terms = wp_get_object_terms(AAM_UNITTEST_POST_ID, 'category', array(
|
110 |
-
'fields' => 'ids'
|
111 |
-
));
|
112 |
-
|
113 |
-
$this->assertEquals($terms, $new_terms);
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Test assigning default category to attachment when none is specified
|
118 |
-
*
|
119 |
-
* @return void
|
120 |
-
*
|
121 |
-
* @access public
|
122 |
-
* @version 6.0.0
|
123 |
-
*/
|
124 |
-
public function testAttachmentUpdateCategoryAssignment()
|
125 |
-
{
|
126 |
-
// Enable media category
|
127 |
-
$this->assertTrue(AAM_Core_Config::set('core.settings.mediaCategory', true));
|
128 |
-
Main::bootstrap()->registerTaxonomies();
|
129 |
-
|
130 |
-
// Get original post terms
|
131 |
-
$terms = wp_get_object_terms(AAM_UNITTEST_ATTACHMENT_ID, 'media_category', array(
|
132 |
-
'fields' => 'ids'
|
133 |
-
));
|
134 |
-
|
135 |
-
// Remove all the terms from the post(
|
136 |
-
wp_remove_object_terms(AAM_UNITTEST_ATTACHMENT_ID, $terms, 'media_category');
|
137 |
-
|
138 |
-
// Set the default category
|
139 |
-
$system = AAM::getUser()->getObject(System::OBJECT_TYPE);
|
140 |
-
$this->assertTrue(
|
141 |
-
$system->updateOptionItem(
|
142 |
-
'defaultTerm.attachment.media_category', AAM_UNITTEST_MEDIA_CATEGORY_ID
|
143 |
-
)->save()
|
144 |
-
);
|
145 |
-
|
146 |
-
// Reset all internal cache
|
147 |
-
$this->_resetSubjects();
|
148 |
-
|
149 |
-
wp_update_post(array(
|
150 |
-
'ID' => AAM_UNITTEST_ATTACHMENT_ID
|
151 |
-
));
|
152 |
-
|
153 |
-
$new_terms = wp_get_object_terms(AAM_UNITTEST_ATTACHMENT_ID, 'media_category', array(
|
154 |
-
'fields' => 'ids'
|
155 |
-
));
|
156 |
-
|
157 |
-
$this->assertContains(AAM_UNITTEST_MEDIA_CATEGORY_ID, $new_terms);
|
158 |
-
|
159 |
-
// Restore original categories
|
160 |
-
wp_set_object_terms(AAM_UNITTEST_ATTACHMENT_ID, $terms, 'media_category');
|
161 |
-
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* Test assigning default category to new attachment
|
165 |
-
*
|
166 |
-
* @return void
|
167 |
-
*
|
168 |
-
* @access public
|
169 |
-
* @version 6.0.0
|
170 |
-
*/
|
171 |
-
public function testAttachmentAddCategoryAssignment()
|
172 |
-
{
|
173 |
-
// Enable media category
|
174 |
-
$this->assertTrue(AAM_Core_Config::set('core.settings.mediaCategory', true));
|
175 |
-
Main::bootstrap()->registerTaxonomies();
|
176 |
-
|
177 |
-
// Set the default category
|
178 |
-
$system = AAM::getUser()->getObject(System::OBJECT_TYPE);
|
179 |
-
$this->assertTrue(
|
180 |
-
$system->updateOptionItem(
|
181 |
-
'defaultTerm.attachment.media_category', AAM_UNITTEST_MEDIA_CATEGORY_ID
|
182 |
-
)->save()
|
183 |
-
);
|
184 |
-
|
185 |
-
// Reset all internal cache
|
186 |
-
$this->_resetSubjects();
|
187 |
-
|
188 |
-
$id = wp_insert_post(array(
|
189 |
-
'post_type' => 'attachment',
|
190 |
-
'post_title' => 'Dummy Attachment'
|
191 |
-
));
|
192 |
-
|
193 |
-
$new_terms = wp_get_object_terms($id, 'media_category', array(
|
194 |
-
'fields' => 'ids'
|
195 |
-
));
|
196 |
-
|
197 |
-
$this->assertContains(AAM_UNITTEST_MEDIA_CATEGORY_ID, $new_terms);
|
198 |
-
|
199 |
-
// Restore original categories
|
200 |
-
wp_delete_post($id, true);
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Test that default_category option is adjusted to a new value
|
205 |
-
*
|
206 |
-
* @return void
|
207 |
-
*
|
208 |
-
* @access public
|
209 |
-
* @version 6.0.0
|
210 |
-
*/
|
211 |
-
public function testGetDefaultCategoryOption()
|
212 |
-
{
|
213 |
-
// Set the default category
|
214 |
-
$system = AAM::getUser()->getObject(System::OBJECT_TYPE);
|
215 |
-
$this->assertTrue(
|
216 |
-
$system->updateOptionItem(
|
217 |
-
'defaultTerm.post.category', AAM_UNITTEST_CATEGORY_LEVEL_2_ID
|
218 |
-
)->save()
|
219 |
-
);
|
220 |
-
|
221 |
-
$this->assertEquals(
|
222 |
-
AAM_UNITTEST_CATEGORY_LEVEL_2_ID, get_option('default_category')
|
223 |
-
);
|
224 |
-
}
|
225 |
-
|
226 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/PlusPackage/TermRESTfulAccessTest.php
DELETED
@@ -1,221 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\PlusPackage;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
WP_REST_Request,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait,
|
17 |
-
AAM\AddOn\PlusPackage\Object\Term,
|
18 |
-
AAM\AddOn\PlusPackage\Object\Taxonomy;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test cases for the Plus Package term access management
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class TermRESTfulAccessTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test that term is hidden while going through RESTful API endpoint
|
33 |
-
*
|
34 |
-
* @return void
|
35 |
-
*
|
36 |
-
* @access public
|
37 |
-
* @version 6.0.0
|
38 |
-
*/
|
39 |
-
public function testVisibilityTermDirectly()
|
40 |
-
{
|
41 |
-
$user = AAM::getUser();
|
42 |
-
$object = $user->getObject(
|
43 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
44 |
-
);
|
45 |
-
|
46 |
-
// Check if save returns positive result
|
47 |
-
$this->assertTrue($object->updateOptionItem('term/hidden', true)->save());
|
48 |
-
|
49 |
-
$server = rest_get_server();
|
50 |
-
|
51 |
-
// Verify that term is no longer in the list of terms
|
52 |
-
$request = new WP_REST_Request('GET', '/wp/v2/categories');
|
53 |
-
$request->set_param('context', 'view');
|
54 |
-
|
55 |
-
$data = $server->dispatch($request)->get_data();
|
56 |
-
|
57 |
-
// First, confirm that post is in the array of posts
|
58 |
-
$this->assertCount(0, array_filter($data, function($term) {
|
59 |
-
return $term['id'] === AAM_UNITTEST_CATEGORY_ID;
|
60 |
-
}));
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Test that term is restricted while going through RESTful API endpoint
|
65 |
-
*
|
66 |
-
* @return void
|
67 |
-
*
|
68 |
-
* @access public
|
69 |
-
* @version 6.0.0
|
70 |
-
*/
|
71 |
-
public function testRestrictedTermDirectly()
|
72 |
-
{
|
73 |
-
$user = AAM::getUser();
|
74 |
-
$object = $user->getObject(
|
75 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
76 |
-
);
|
77 |
-
|
78 |
-
// Check if save returns positive result
|
79 |
-
$this->assertTrue($object->updateOptionItem('term/restricted', true)->save());
|
80 |
-
|
81 |
-
$server = rest_get_server();
|
82 |
-
|
83 |
-
// Verify that term is no longer in the list of terms
|
84 |
-
$request = new WP_REST_Request('GET', '/wp/v2/categories/' . AAM_UNITTEST_CATEGORY_ID);
|
85 |
-
$request->set_param('context', 'view');
|
86 |
-
|
87 |
-
$response = $server->dispatch($request);
|
88 |
-
|
89 |
-
$this->assertEquals(403, $response->get_status());
|
90 |
-
$this->assertEquals('term_access_restricted', $response->get_data()['code']);
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Test that term is not editable while going through RESTful API endpoint
|
95 |
-
*
|
96 |
-
* @return void
|
97 |
-
*
|
98 |
-
* @access public
|
99 |
-
* @version 6.0.0
|
100 |
-
*/
|
101 |
-
public function testEditableTermDirectly()
|
102 |
-
{
|
103 |
-
$user = AAM::getUser();
|
104 |
-
$object = $user->getObject(
|
105 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
106 |
-
);
|
107 |
-
|
108 |
-
// Check if save returns positive result
|
109 |
-
$this->assertTrue($object->updateOptionItem('term/edit', true)->save());
|
110 |
-
|
111 |
-
$server = rest_get_server();
|
112 |
-
|
113 |
-
// Verify that term is no longer in the list of terms
|
114 |
-
$request = new WP_REST_Request('POST', '/wp/v2/categories/' . AAM_UNITTEST_CATEGORY_ID);
|
115 |
-
$request->set_param('description', 'Test');
|
116 |
-
|
117 |
-
$response = $server->dispatch($request);
|
118 |
-
|
119 |
-
$this->assertEquals(403, $response->get_status());
|
120 |
-
$this->assertEquals('rest_cannot_update', $response->get_data()['code']);
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Test that access is restricted to create a new ter
|
125 |
-
*
|
126 |
-
* @return void
|
127 |
-
*
|
128 |
-
* @access public
|
129 |
-
* @version 6.0.0
|
130 |
-
*/
|
131 |
-
public function testCreationTermDirectly()
|
132 |
-
{
|
133 |
-
global $wp_taxonomies;
|
134 |
-
|
135 |
-
$user = AAM::getUser();
|
136 |
-
$object = $user->getObject(Taxonomy::OBJECT_TYPE, 'category');
|
137 |
-
|
138 |
-
// Check if save returns positive result
|
139 |
-
$this->assertTrue($object->updateOptionItem('term/edit', true)->save());
|
140 |
-
|
141 |
-
// Emulate new taxonomy registration
|
142 |
-
do_action('registered_taxonomy', 'category', 'post');
|
143 |
-
|
144 |
-
$server = rest_get_server();
|
145 |
-
|
146 |
-
// Verify that term is no longer in the list of terms
|
147 |
-
$request = new WP_REST_Request('POST', '/wp/v2/categories');
|
148 |
-
$request->set_param('name', 'Test');
|
149 |
-
$request->set_param('description', 'Test');
|
150 |
-
|
151 |
-
$response = $server->dispatch($request);
|
152 |
-
|
153 |
-
$this->assertEquals(403, $response->get_status());
|
154 |
-
$this->assertEquals('rest_cannot_create', $response->get_data()['code']);
|
155 |
-
|
156 |
-
// Restore original
|
157 |
-
$wp_taxonomies['category']->cap->edit_terms = 'edit_categories';
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Test that term cannot be deleted while going through RESTful API endpoint
|
162 |
-
*
|
163 |
-
* @return void
|
164 |
-
*
|
165 |
-
* @access public
|
166 |
-
* @version 6.0.0
|
167 |
-
*/
|
168 |
-
public function testDeleteTermDirectly()
|
169 |
-
{
|
170 |
-
$user = AAM::getUser();
|
171 |
-
$object = $user->getObject(
|
172 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
173 |
-
);
|
174 |
-
|
175 |
-
// Check if save returns positive result
|
176 |
-
$this->assertTrue($object->updateOptionItem('term/delete', true)->save());
|
177 |
-
|
178 |
-
$server = rest_get_server();
|
179 |
-
|
180 |
-
// Verify that term is no longer in the list of terms
|
181 |
-
$request = new WP_REST_Request('DELETE', '/wp/v2/categories/' . AAM_UNITTEST_CATEGORY_ID);
|
182 |
-
|
183 |
-
$response = $server->dispatch($request);
|
184 |
-
|
185 |
-
$this->assertEquals(403, $response->get_status());
|
186 |
-
$this->assertEquals('rest_cannot_delete', $response->get_data()['code']);
|
187 |
-
}
|
188 |
-
|
189 |
-
/**
|
190 |
-
* Test that term cannot be assigned to a post while going through RESTful
|
191 |
-
* API endpoint
|
192 |
-
*
|
193 |
-
* @return void
|
194 |
-
*
|
195 |
-
* @access public
|
196 |
-
* @version 6.0.0
|
197 |
-
*/
|
198 |
-
public function testAssignTermDirectly()
|
199 |
-
{
|
200 |
-
$user = AAM::getUser();
|
201 |
-
$object = $user->getObject(
|
202 |
-
Term::OBJECT_TYPE, AAM_UNITTEST_CATEGORY_ID . '|category'
|
203 |
-
);
|
204 |
-
|
205 |
-
// Check if save returns positive result
|
206 |
-
$this->assertTrue($object->updateOptionItem('term/assign', true)->save());
|
207 |
-
|
208 |
-
$server = rest_get_server();
|
209 |
-
|
210 |
-
// Verify that term is no longer in the list of terms
|
211 |
-
$request = new WP_REST_Request('POST', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
212 |
-
$request->set_param('context', 'edit');
|
213 |
-
$request->set_param('categories', array(AAM_UNITTEST_CATEGORY_ID));
|
214 |
-
|
215 |
-
$response = $server->dispatch($request);
|
216 |
-
|
217 |
-
$this->assertEquals(403, $response->get_status());
|
218 |
-
$this->assertEquals('rest_cannot_assign_term', $response->get_data()['code']);
|
219 |
-
}
|
220 |
-
|
221 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/PlusPackage/UriAccessTest.php
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\PlusPackage;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Service_Uri,
|
14 |
-
AAM_Core_Object_Uri,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test URI access enhancement
|
20 |
-
*
|
21 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class UriAccessTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Test the wild card URI access rule
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testWildCardMatch()
|
37 |
-
{
|
38 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
39 |
-
$result = $object->updateOptionItem('*', array(
|
40 |
-
'type' => 'default',
|
41 |
-
'action' => null
|
42 |
-
))->save();
|
43 |
-
|
44 |
-
$this->assertTrue($result);
|
45 |
-
|
46 |
-
// Override the default handlers so we can suppress die exit
|
47 |
-
add_filter('wp_die_handler', function() {
|
48 |
-
return function($message, $title) {
|
49 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
50 |
-
};
|
51 |
-
}, PHP_INT_MAX);
|
52 |
-
$_SERVER['REQUEST_URI'] = '/';
|
53 |
-
|
54 |
-
// Reset all internal cache
|
55 |
-
$this->_resetSubjects();
|
56 |
-
|
57 |
-
ob_start();
|
58 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
59 |
-
$content = ob_get_contents();
|
60 |
-
ob_end_clean();
|
61 |
-
|
62 |
-
$this->assertStringContainsString('Access Denied', $content);
|
63 |
-
}
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Test the wild card override rule
|
67 |
-
*
|
68 |
-
* The entire website is denied but only one specific URI is allowed
|
69 |
-
*
|
70 |
-
* @return void
|
71 |
-
*
|
72 |
-
* @access public
|
73 |
-
* @version 6.0.0
|
74 |
-
*/
|
75 |
-
public function testWildCardOverride()
|
76 |
-
{
|
77 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
78 |
-
|
79 |
-
// Deny access ot the entire site
|
80 |
-
$this->assertTrue($object->updateOptionItem('*', array(
|
81 |
-
'type' => 'default',
|
82 |
-
'action' => null
|
83 |
-
))->save());
|
84 |
-
|
85 |
-
// Allow to only one specific URI
|
86 |
-
$this->assertTrue($object->updateOptionItem('/hello-world', array(
|
87 |
-
'type' => 'allow',
|
88 |
-
'action' => null
|
89 |
-
))->save());
|
90 |
-
|
91 |
-
// Reset all internal cache
|
92 |
-
$this->_resetSubjects();
|
93 |
-
|
94 |
-
$match = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE)->findMatch(
|
95 |
-
'/hello-world'
|
96 |
-
);
|
97 |
-
|
98 |
-
$this->assertEquals($match['type'], 'allow');
|
99 |
-
}
|
100 |
-
|
101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Addon/RoleHierarchy/RoleHierarchyTest.php
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Addon\RoleHierarchy;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Menu,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test cases for the Role Hierarchy addon
|
20 |
-
*
|
21 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class RoleHierarchyTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait,
|
27 |
-
AuthUserTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test that role can have a parent role and settings are propagated properly
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testRoleInheritance()
|
38 |
-
{
|
39 |
-
$contributor = AAM::api()->getRole('contributor');
|
40 |
-
$object = $contributor->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
41 |
-
|
42 |
-
// Set fake settings for the Contributor
|
43 |
-
$this->assertTrue($object->updateOptionItem('index.php', true)->save());
|
44 |
-
|
45 |
-
// Fake the fact that Subscriber has a parent role Contributor
|
46 |
-
AAM::api()->updateConfig('system.role.subscriber.parent', 'contributor');
|
47 |
-
|
48 |
-
// Reset all internal cache
|
49 |
-
$this->_resetSubjects();
|
50 |
-
|
51 |
-
$subscriber = AAM::api()->getRole('subscriber');
|
52 |
-
$object = $subscriber->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
53 |
-
|
54 |
-
$this->assertEquals('contributor', $subscriber->getParent()->getId());
|
55 |
-
$this->assertTrue($object->isRestricted('index.php'));
|
56 |
-
}
|
57 |
-
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Core/GatewayTest.php
DELETED
@@ -1,90 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Core;
|
11 |
-
|
12 |
-
use AAM_Core_Gateway,
|
13 |
-
PHPUnit\Framework\TestCase;
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Test AAM core Gateway
|
17 |
-
*
|
18 |
-
* @package AAM\UnitTest
|
19 |
-
* @version 6.0.0
|
20 |
-
*/
|
21 |
-
class GatewayTest extends TestCase
|
22 |
-
{
|
23 |
-
/**
|
24 |
-
* Test all possible merging permutations with preference
|
25 |
-
*
|
26 |
-
* @return void
|
27 |
-
*
|
28 |
-
* @access public
|
29 |
-
* @dataProvider mergingPreferenceData
|
30 |
-
* @version 6.0.0
|
31 |
-
*/
|
32 |
-
public function testAccessOptionsMerging($set1, $set2, $preference, $expected)
|
33 |
-
{
|
34 |
-
$gateway = AAM_Core_Gateway::getInstance();
|
35 |
-
|
36 |
-
$this->assertSame(
|
37 |
-
$gateway->mergeSettings($set1, $set2, null, $preference), $expected
|
38 |
-
);
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Return the array of possible access option combinations
|
43 |
-
*
|
44 |
-
* @return array
|
45 |
-
*
|
46 |
-
* @access public
|
47 |
-
* @version 6.0.0
|
48 |
-
*/
|
49 |
-
public function mergingPreferenceData()
|
50 |
-
{
|
51 |
-
return array(
|
52 |
-
array(array('hidden' => true), array('hidden' => true), 'deny', array('hidden' => true)),
|
53 |
-
array(array('hidden' => true), array('hidden' => false), 'deny', array('hidden' => true)),
|
54 |
-
array(array('hidden' => false), array('hidden' => true), 'deny', array('hidden' => true)),
|
55 |
-
array(array('hidden' => false), array('hidden' => false), 'deny', array('hidden' => false)),
|
56 |
-
array(array('hidden' => true), array('hidden' => true), 'allow', array('hidden' => true)),
|
57 |
-
array(array('hidden' => true), array('hidden' => false), 'allow', array('hidden' => false)),
|
58 |
-
array(array('hidden' => false), array('hidden' => true), 'allow', array('hidden' => false)),
|
59 |
-
array(array('hidden' => false), array('hidden' => false), 'allow', array('hidden' => false)),
|
60 |
-
// One of the options is not defined
|
61 |
-
array(array('hidden' => true), array(), 'deny', array('hidden' => true)),
|
62 |
-
array(array('hidden' => false), array(), 'deny', array('hidden' => false)),
|
63 |
-
array(array(), array('hidden' => true), 'deny', array('hidden' => true)),
|
64 |
-
array(array(), array('hidden' => false), 'deny', array('hidden' => false)),
|
65 |
-
array(array('hidden' => true), array(), 'allow', array('hidden' => false)),
|
66 |
-
array(array('hidden' => false), array(), 'allow', array('hidden' => false)),
|
67 |
-
array(array(), array('hidden' => true), 'allow', array('hidden' => false)),
|
68 |
-
array(array(), array('hidden' => false), 'allow', array('hidden' => false)),
|
69 |
-
// Complex access options that are defined as array
|
70 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array('limited' => array('enabled' => true, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => true, 'threshold' => 2))),
|
71 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array('limited' => array('enabled' => false, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => true, 'threshold' => 1))),
|
72 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array('limited' => array('enabled' => true, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => true, 'threshold' => 2))),
|
73 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array('limited' => array('enabled' => false, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
74 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array('limited' => array('enabled' => true, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => true, 'threshold' => 2))),
|
75 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array('limited' => array('enabled' => false, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
76 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array('limited' => array('enabled' => true, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => false, 'threshold' => 1))),
|
77 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array('limited' => array('enabled' => false, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
78 |
-
// One of the options is not defined
|
79 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array(), 'deny', array('limited' => array('enabled' => true, 'threshold' => 1))),
|
80 |
-
array(array(), array('limited' => array('enabled' => true, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => true, 'threshold' => 2))),
|
81 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array(), 'deny', array('limited' => array('enabled' => false, 'threshold' => 1))),
|
82 |
-
array(array(), array('limited' => array('enabled' => false, 'threshold' => 2)), 'deny', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
83 |
-
array(array('limited' => array('enabled' => true, 'threshold' => 1)), array(), 'allow', array('limited' => array('enabled' => false, 'threshold' => 1))),
|
84 |
-
array(array('limited' => array('enabled' => false, 'threshold' => 1)), array(), 'allow', array('limited' => array('enabled' => false, 'threshold' => 1))),
|
85 |
-
array(array(), array('limited' => array('enabled' => true, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
86 |
-
array(array(), array('limited' => array('enabled' => false, 'threshold' => 2)), 'allow', array('limited' => array('enabled' => false, 'threshold' => 2))),
|
87 |
-
);
|
88 |
-
}
|
89 |
-
|
90 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Core/SubjectLoadTest.php
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
use PHPUnit\Framework\TestCase;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Test if proper subject is picked correctly
|
14 |
-
*
|
15 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
16 |
-
* @version 6.0.0
|
17 |
-
*/
|
18 |
-
class SubjectLoadTest extends TestCase
|
19 |
-
{
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Test that AAM loaded Visitor subject
|
23 |
-
*
|
24 |
-
* AAM has to load Visitor subject when there is no indicators or authentication
|
25 |
-
*/
|
26 |
-
public function testLoadedVisitorType()
|
27 |
-
{
|
28 |
-
$subject = AAM::getUser();
|
29 |
-
|
30 |
-
$this->assertSame('AAM_Core_Subject_Visitor', get_class($subject));
|
31 |
-
}
|
32 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Libs/AuthManagerUserTrait.php
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Libs;
|
11 |
-
|
12 |
-
/**
|
13 |
-
*
|
14 |
-
* @version 6.0.0
|
15 |
-
*/
|
16 |
-
trait AuthManagerUserTrait
|
17 |
-
{
|
18 |
-
/**
|
19 |
-
* @inheritdoc
|
20 |
-
*/
|
21 |
-
public static function setUpBeforeClass()
|
22 |
-
{
|
23 |
-
// Set current User. Emulate that this is admin login
|
24 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_SUBADMIN_USER_ID);
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @inheritdoc
|
29 |
-
*/
|
30 |
-
public static function tearDownAfterClass()
|
31 |
-
{
|
32 |
-
// Unset the forced user
|
33 |
-
wp_set_current_user(0);
|
34 |
-
}
|
35 |
-
|
36 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Libs/AuthMultiRoleUserTrait.php
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Libs;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM_Core_Subject_User;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Trait that setup multi-role support
|
18 |
-
*
|
19 |
-
* The `AAM_UNITTEST_AUTH_MULTIROLE_USER_ID` constant that is defined in the main
|
20 |
-
* phpunit.xml.dist config, has to point to the existing WP user that has more than
|
21 |
-
* one role assigned
|
22 |
-
*
|
23 |
-
* @package AAM\UnitTest
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
trait AuthMultiRoleUserTrait
|
27 |
-
{
|
28 |
-
|
29 |
-
/**
|
30 |
-
* @inheritdoc
|
31 |
-
*/
|
32 |
-
public static function setUpBeforeClass()
|
33 |
-
{
|
34 |
-
if (is_subclass_of(self::class, 'AAM\UnitTest\Libs\MultiRoleOptionInterface')) {
|
35 |
-
// Enable Multiple Role Support
|
36 |
-
AAM_Core_Config::set('core.settings.multiSubject', true);
|
37 |
-
}
|
38 |
-
|
39 |
-
// Set current User. Emulate that this is admin login
|
40 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_MULTIROLE_USER_ID);
|
41 |
-
|
42 |
-
// Override AAM current user
|
43 |
-
AAM::getInstance()->setUser(
|
44 |
-
new AAM_Core_Subject_User(AAM_UNITTEST_AUTH_MULTIROLE_USER_ID)
|
45 |
-
);
|
46 |
-
}
|
47 |
-
|
48 |
-
/**
|
49 |
-
* @inheritdoc
|
50 |
-
*/
|
51 |
-
public static function tearDownAfterClass()
|
52 |
-
{
|
53 |
-
// Unset the forced user
|
54 |
-
wp_set_current_user(0);
|
55 |
-
}
|
56 |
-
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Libs/AuthUserTrait.php
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Libs;
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Test access policy integration with core AAM objects
|
14 |
-
*
|
15 |
-
* @version 6.0.0
|
16 |
-
*/
|
17 |
-
trait AuthUserTrait
|
18 |
-
{
|
19 |
-
/**
|
20 |
-
* @inheritdoc
|
21 |
-
*/
|
22 |
-
public static function setUpBeforeClass()
|
23 |
-
{
|
24 |
-
// Set current User. Emulate that this is admin login
|
25 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_USER_ID);
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* @inheritdoc
|
30 |
-
*/
|
31 |
-
public static function tearDownAfterClass()
|
32 |
-
{
|
33 |
-
// Unset the forced user
|
34 |
-
wp_set_current_user(0);
|
35 |
-
}
|
36 |
-
|
37 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Libs/MultiRoleOptionInterface.php
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Libs;
|
11 |
-
|
12 |
-
/**
|
13 |
-
*
|
14 |
-
* @version 6.0.0
|
15 |
-
*/
|
16 |
-
interface MultiRoleOptionInterface
|
17 |
-
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Libs/ResetTrait.php
DELETED
@@ -1,92 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Libs;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_API,
|
14 |
-
AAM_Core_Config,
|
15 |
-
AAM_Core_AccessSettings,
|
16 |
-
AAM_Core_Policy_Factory;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Reset access settings after each test
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
trait ResetTrait
|
25 |
-
{
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Reset all AAM settings to the default
|
29 |
-
*
|
30 |
-
* @return void
|
31 |
-
*
|
32 |
-
* @access protected
|
33 |
-
* @version 6.0.0
|
34 |
-
*/
|
35 |
-
protected function tearDown()
|
36 |
-
{
|
37 |
-
// Clear all AAM settings
|
38 |
-
AAM_Core_API::clearSettings();
|
39 |
-
|
40 |
-
// Reset Access Settings repository
|
41 |
-
AAM_Core_AccessSettings::getInstance()->reset();
|
42 |
-
|
43 |
-
// Also clear all the internal caching
|
44 |
-
$this->_resetSubjects();
|
45 |
-
|
46 |
-
if (is_subclass_of(self::class, 'AAM\UnitTest\Libs\MultiRoleOptionInterface')) {
|
47 |
-
// Enable Multiple Role Support
|
48 |
-
AAM_Core_Config::set('core.settings.multiSubject', true);
|
49 |
-
}
|
50 |
-
|
51 |
-
// Clear WP core cache
|
52 |
-
wp_cache_flush();
|
53 |
-
|
54 |
-
// Reset internal AAM config cache
|
55 |
-
AAM_Core_Config::bootstrap();
|
56 |
-
|
57 |
-
// Reset Access Policy Factory cache
|
58 |
-
AAM_Core_Policy_Factory::reset();
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Reset all subjects
|
63 |
-
*
|
64 |
-
* AAM Subject has internal cache that stored already initiated objects for
|
65 |
-
* performance reasons. Reset the cache to allow inheritance mechanism to go
|
66 |
-
* through.
|
67 |
-
*
|
68 |
-
* @return void
|
69 |
-
*
|
70 |
-
* @access private
|
71 |
-
* @see AAM_Core_Subject::getObject
|
72 |
-
* @link https://aamplugin.com/reference/plugin#multiple-roles-support
|
73 |
-
* @version 6.0.0
|
74 |
-
*/
|
75 |
-
private function _resetSubjects()
|
76 |
-
{
|
77 |
-
$subject = AAM::getUser();
|
78 |
-
|
79 |
-
do {
|
80 |
-
// Take in consideration that a subject can have multiple parent subjects
|
81 |
-
// when "Multiple Roles Support" is enabled
|
82 |
-
$subject->flushCache();
|
83 |
-
if ($subject->hasSiblings()) {
|
84 |
-
$siblings = $subject->getSiblings();
|
85 |
-
array_walk($siblings, function($sibling) {
|
86 |
-
$sibling->flushCache();
|
87 |
-
});
|
88 |
-
}
|
89 |
-
} while ($subject = $subject->getParent());
|
90 |
-
}
|
91 |
-
|
92 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyConditionTest.php
DELETED
@@ -1,543 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM_Core_Policy_Condition,
|
13 |
-
PHPUnit\Framework\TestCase;
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Test policy condition evaluator
|
17 |
-
*
|
18 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
19 |
-
* @version 6.0.0
|
20 |
-
*/
|
21 |
-
class PolicyConditionTest extends TestCase
|
22 |
-
{
|
23 |
-
/**
|
24 |
-
* Validate Between condition evaluator
|
25 |
-
*
|
26 |
-
* @param array $condition
|
27 |
-
* @param boolean $expectedResult
|
28 |
-
*
|
29 |
-
* @return void
|
30 |
-
*
|
31 |
-
* @access public
|
32 |
-
* @dataProvider betweenDataProvider
|
33 |
-
* @version 6.0.0
|
34 |
-
*/
|
35 |
-
public function testBetweenCondition($condition, $expectedResult)
|
36 |
-
{
|
37 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
38 |
-
|
39 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* Between condition data provider
|
44 |
-
*
|
45 |
-
* @return void
|
46 |
-
*
|
47 |
-
* @access public
|
48 |
-
* @version 6.0.0
|
49 |
-
*/
|
50 |
-
public function betweenDataProvider()
|
51 |
-
{
|
52 |
-
return array(
|
53 |
-
array(array('Between' => array(10 => array(5, 15))), true),
|
54 |
-
array(array('Between' => array(10 => array(array(1, 3), array(5, 12)))), true),
|
55 |
-
array(array('Between' => array(21 => array(array(1, 3), array(5, 12), array(20, 21)))), true),
|
56 |
-
array(array('Between' => array(1 => array(5, 15))), false)
|
57 |
-
);
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* Validate Equals condition evaluator
|
62 |
-
*
|
63 |
-
* @param array $condition
|
64 |
-
* @param boolean $expectedResult
|
65 |
-
*
|
66 |
-
* @return void
|
67 |
-
*
|
68 |
-
* @access public
|
69 |
-
* @dataProvider equalsDataProvider
|
70 |
-
* @version 6.0.0
|
71 |
-
*/
|
72 |
-
public function testEqualsCondition($condition, $expectedResult)
|
73 |
-
{
|
74 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
75 |
-
|
76 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Equals condition data provider
|
81 |
-
*
|
82 |
-
* @return void
|
83 |
-
*
|
84 |
-
* @access public
|
85 |
-
* @version 6.0.0
|
86 |
-
*/
|
87 |
-
public function equalsDataProvider()
|
88 |
-
{
|
89 |
-
// Note! Left side of the condition should never be boolean
|
90 |
-
return array(
|
91 |
-
array(array('Equals' => array(0 => null)), false),
|
92 |
-
array(array('Equals' => array(5 => 4)), false),
|
93 |
-
array(array('Equals' => array(1 => 1)), true),
|
94 |
-
array(array('Equals' => array(1 => '1')), false),
|
95 |
-
array(array('Equals' => array('hello' => 'hello')), true),
|
96 |
-
array(array('Equals' => array('hello' => 'hello1')), false),
|
97 |
-
);
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Validate NotEquals condition evaluator
|
102 |
-
*
|
103 |
-
* @param array $condition
|
104 |
-
* @param boolean $expectedResult
|
105 |
-
*
|
106 |
-
* @return void
|
107 |
-
*
|
108 |
-
* @access public
|
109 |
-
* @dataProvider notEqualsDataProvider
|
110 |
-
* @version 6.0.0
|
111 |
-
*/
|
112 |
-
public function testNotEqualsCondition($condition, $expectedResult)
|
113 |
-
{
|
114 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
115 |
-
|
116 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
117 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* NotEquals condition data provider
|
121 |
-
*
|
122 |
-
* @return void
|
123 |
-
*
|
124 |
-
* @access public
|
125 |
-
* @version 6.0.0
|
126 |
-
*/
|
127 |
-
public function notEqualsDataProvider()
|
128 |
-
{
|
129 |
-
// Note! Left side of the condition should never be boolean
|
130 |
-
return array(
|
131 |
-
array(array('NotEquals' => array(0 => null)), true),
|
132 |
-
array(array('NotEquals' => array(5 => 4)), true),
|
133 |
-
array(array('NotEquals' => array(1 => 1)), false),
|
134 |
-
array(array('NotEquals' => array(1 => '1')), true),
|
135 |
-
array(array('NotEquals' => array('2a' => 2)), true),
|
136 |
-
array(array('NotEquals' => array('hello' => 'hello')), false),
|
137 |
-
array(array('NotEquals' => array('hello' => 'hello1')), true),
|
138 |
-
);
|
139 |
-
}
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Validate Greater condition evaluator
|
143 |
-
*
|
144 |
-
* @param array $condition
|
145 |
-
* @param boolean $expectedResult
|
146 |
-
*
|
147 |
-
* @return void
|
148 |
-
*
|
149 |
-
* @access public
|
150 |
-
* @dataProvider greaterDataProvider
|
151 |
-
* @version 6.0.0
|
152 |
-
*/
|
153 |
-
public function testGreaterCondition($condition, $expectedResult)
|
154 |
-
{
|
155 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
156 |
-
|
157 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Greater condition data provider
|
162 |
-
*
|
163 |
-
* @return void
|
164 |
-
*
|
165 |
-
* @access public
|
166 |
-
* @version 6.0.0
|
167 |
-
*/
|
168 |
-
public function greaterDataProvider()
|
169 |
-
{
|
170 |
-
return array(
|
171 |
-
array(array('Greater' => array(5 => 1)), true),
|
172 |
-
array(array('Greater' => array(15 => 15)), false),
|
173 |
-
array(array('Greater' => array(3 => 5)), false)
|
174 |
-
);
|
175 |
-
}
|
176 |
-
|
177 |
-
/**
|
178 |
-
* Validate Less condition evaluator
|
179 |
-
*
|
180 |
-
* @param array $condition
|
181 |
-
* @param boolean $expectedResult
|
182 |
-
*
|
183 |
-
* @return void
|
184 |
-
*
|
185 |
-
* @access public
|
186 |
-
* @dataProvider lessDataProvider
|
187 |
-
* @version 6.0.0
|
188 |
-
*/
|
189 |
-
public function testLessCondition($condition, $expectedResult)
|
190 |
-
{
|
191 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
192 |
-
|
193 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
194 |
-
}
|
195 |
-
|
196 |
-
/**
|
197 |
-
* Less condition data provider
|
198 |
-
*
|
199 |
-
* @return void
|
200 |
-
*
|
201 |
-
* @access public
|
202 |
-
* @version 6.0.0
|
203 |
-
*/
|
204 |
-
public function lessDataProvider()
|
205 |
-
{
|
206 |
-
return array(
|
207 |
-
array(array('Less' => array(5 => 10)), true),
|
208 |
-
array(array('Less' => array(15 => 15)), false),
|
209 |
-
array(array('Less' => array(13 => 5)), false)
|
210 |
-
);
|
211 |
-
}
|
212 |
-
|
213 |
-
/**
|
214 |
-
* Validate greater or equals condition evaluator
|
215 |
-
*
|
216 |
-
* @param array $condition
|
217 |
-
* @param boolean $expectedResult
|
218 |
-
*
|
219 |
-
* @return void
|
220 |
-
*
|
221 |
-
* @access public
|
222 |
-
* @dataProvider greaterOrEqualsDataProvider
|
223 |
-
* @version 6.0.0
|
224 |
-
*/
|
225 |
-
public function testGreaterOrEqualsCondition($condition, $expectedResult)
|
226 |
-
{
|
227 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
228 |
-
|
229 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* Greater or equals condition data provider
|
234 |
-
*
|
235 |
-
* @return void
|
236 |
-
*
|
237 |
-
* @access public
|
238 |
-
* @version 6.0.0
|
239 |
-
*/
|
240 |
-
public function greaterOrEqualsDataProvider()
|
241 |
-
{
|
242 |
-
return array(
|
243 |
-
array(array('GreaterOrEquals' => array(5 => 1)), true),
|
244 |
-
array(array('GreaterOrEquals' => array(15 => 15)), true),
|
245 |
-
array(array('GreaterOrEquals' => array(3 => 5)), false)
|
246 |
-
);
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Validate Less or equals condition evaluator
|
251 |
-
*
|
252 |
-
* @param array $condition
|
253 |
-
* @param boolean $expectedResult
|
254 |
-
*
|
255 |
-
* @return void
|
256 |
-
*
|
257 |
-
* @access public
|
258 |
-
* @dataProvider lessOrEqualsDataProvider
|
259 |
-
* @version 6.0.0
|
260 |
-
*/
|
261 |
-
public function testLessOrEqualsCondition($condition, $expectedResult)
|
262 |
-
{
|
263 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
264 |
-
|
265 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
266 |
-
}
|
267 |
-
|
268 |
-
/**
|
269 |
-
* Less or equals condition data provider
|
270 |
-
*
|
271 |
-
* @return void
|
272 |
-
*
|
273 |
-
* @access public
|
274 |
-
* @version 6.0.0
|
275 |
-
*/
|
276 |
-
public function lessOrEqualsDataProvider()
|
277 |
-
{
|
278 |
-
return array(
|
279 |
-
array(array('LessOrEquals' => array(5 => 10)), true),
|
280 |
-
array(array('LessOrEquals' => array(15 => 15)), true),
|
281 |
-
array(array('LessOrEquals' => array(13 => 5)), false)
|
282 |
-
);
|
283 |
-
}
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Validate In condition evaluator
|
287 |
-
*
|
288 |
-
* @param array $condition
|
289 |
-
* @param boolean $expectedResult
|
290 |
-
*
|
291 |
-
* @return void
|
292 |
-
*
|
293 |
-
* @access public
|
294 |
-
* @dataProvider inDataProvider
|
295 |
-
* @version 6.0.0
|
296 |
-
*/
|
297 |
-
public function testInCondition($condition, $expectedResult)
|
298 |
-
{
|
299 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
300 |
-
|
301 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
302 |
-
}
|
303 |
-
|
304 |
-
/**
|
305 |
-
* In condition data provider
|
306 |
-
*
|
307 |
-
* @return void
|
308 |
-
*
|
309 |
-
* @access public
|
310 |
-
* @version 6.0.0
|
311 |
-
*/
|
312 |
-
public function inDataProvider()
|
313 |
-
{
|
314 |
-
return array(
|
315 |
-
array(array('In' => array('test' => array('test', 'test1'))), true),
|
316 |
-
array(array('In' => array(2 => array(2, 5, 7))), true),
|
317 |
-
array(array('In' => array('no' => array('yes', 'maybe'))), false)
|
318 |
-
);
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Validate NotIn condition evaluator
|
323 |
-
*
|
324 |
-
* @param array $condition
|
325 |
-
* @param boolean $expectedResult
|
326 |
-
*
|
327 |
-
* @return void
|
328 |
-
*
|
329 |
-
* @access public
|
330 |
-
* @dataProvider notInDataProvider
|
331 |
-
* @version 6.0.0
|
332 |
-
*/
|
333 |
-
public function testNotInCondition($condition, $expectedResult)
|
334 |
-
{
|
335 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
336 |
-
|
337 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
338 |
-
}
|
339 |
-
|
340 |
-
/**
|
341 |
-
* NotIn condition data provider
|
342 |
-
*
|
343 |
-
* @return void
|
344 |
-
*
|
345 |
-
* @access public
|
346 |
-
* @version 6.0.0
|
347 |
-
*/
|
348 |
-
public function notInDataProvider()
|
349 |
-
{
|
350 |
-
return array(
|
351 |
-
array(array('NotIn' => array('test' => array('test', 'test1'))), false),
|
352 |
-
array(array('NotIn' => array(2 => array(2, 5, 7))), false),
|
353 |
-
array(array('NotIn' => array('no' => array('yes', 'maybe'))), true)
|
354 |
-
);
|
355 |
-
}
|
356 |
-
|
357 |
-
/**
|
358 |
-
* Validate Like condition evaluator
|
359 |
-
*
|
360 |
-
* @param array $condition
|
361 |
-
* @param boolean $expectedResult
|
362 |
-
*
|
363 |
-
* @return void
|
364 |
-
*
|
365 |
-
* @access public
|
366 |
-
* @dataProvider likeDataProvider
|
367 |
-
* @version 6.0.0
|
368 |
-
*/
|
369 |
-
public function testLikeCondition($condition, $expectedResult)
|
370 |
-
{
|
371 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
372 |
-
|
373 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
374 |
-
}
|
375 |
-
|
376 |
-
/**
|
377 |
-
* Like condition data provider
|
378 |
-
*
|
379 |
-
* @return void
|
380 |
-
*
|
381 |
-
* @access public
|
382 |
-
* @version 6.0.0
|
383 |
-
*/
|
384 |
-
public function likeDataProvider()
|
385 |
-
{
|
386 |
-
return array(
|
387 |
-
array(array('Like' => array('Lucy van Pelt' => 'Lucy*')), true),
|
388 |
-
array(array('Like' => array('Lucy van Pelt' => '*Pelt')), true),
|
389 |
-
array(array('Like' => array('Lucy van Pelt' => 'Lucy*Pelt')), true),
|
390 |
-
array(array('Like' => array('Lucy van Pelt' => 'Johny*Pelt')), false)
|
391 |
-
);
|
392 |
-
}
|
393 |
-
|
394 |
-
/**
|
395 |
-
* Validate NotLike condition evaluator
|
396 |
-
*
|
397 |
-
* @param array $condition
|
398 |
-
* @param boolean $expectedResult
|
399 |
-
*
|
400 |
-
* @return void
|
401 |
-
*
|
402 |
-
* @access public
|
403 |
-
* @dataProvider notLikeDataProvider
|
404 |
-
* @version 6.0.0
|
405 |
-
*/
|
406 |
-
public function testNotLikeCondition($condition, $expectedResult)
|
407 |
-
{
|
408 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
409 |
-
|
410 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
411 |
-
}
|
412 |
-
|
413 |
-
/**
|
414 |
-
* NotLike condition data provider
|
415 |
-
*
|
416 |
-
* @return void
|
417 |
-
*
|
418 |
-
* @access public
|
419 |
-
* @version 6.0.0
|
420 |
-
*/
|
421 |
-
public function notLikeDataProvider()
|
422 |
-
{
|
423 |
-
return array(
|
424 |
-
array(array('NotLike' => array('Lucy van Pelt' => 'Lucy*')), false),
|
425 |
-
array(array('NotLike' => array('Lucy van Pelt' => '*Pelt')), false),
|
426 |
-
array(array('NotLike' => array('Lucy van Pelt' => 'Lucy*Pelt')), false),
|
427 |
-
array(array('NotLike' => array('Lucy van Pelt' => 'Johny*Pelt')), true)
|
428 |
-
);
|
429 |
-
}
|
430 |
-
|
431 |
-
/**
|
432 |
-
* Validate RegEx condition evaluator
|
433 |
-
*
|
434 |
-
* @param array $condition
|
435 |
-
* @param boolean $expectedResult
|
436 |
-
*
|
437 |
-
* @return void
|
438 |
-
*
|
439 |
-
* @access public
|
440 |
-
* @dataProvider regExDataProvider
|
441 |
-
* @version 6.0.0
|
442 |
-
*/
|
443 |
-
public function testRegExCondition($condition, $expectedResult)
|
444 |
-
{
|
445 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
446 |
-
|
447 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
448 |
-
}
|
449 |
-
|
450 |
-
/**
|
451 |
-
* RegEx condition data provider
|
452 |
-
*
|
453 |
-
* @return void
|
454 |
-
*
|
455 |
-
* @access public
|
456 |
-
* @version 6.0.0
|
457 |
-
*/
|
458 |
-
public function regExDataProvider()
|
459 |
-
{
|
460 |
-
return array(
|
461 |
-
array(array('RegEx' => array('Hello World' => '/^[\w\s]+$/i')), true),
|
462 |
-
array(array('RegEx' => array('Hello World!' => '/^[\w]+$/')), false)
|
463 |
-
);
|
464 |
-
}
|
465 |
-
|
466 |
-
/**
|
467 |
-
* Validate condition type casting
|
468 |
-
*
|
469 |
-
* @param array $condition
|
470 |
-
* @param boolean $expectedResult
|
471 |
-
*
|
472 |
-
* @return void
|
473 |
-
*
|
474 |
-
* @access public
|
475 |
-
* @dataProvider typeCastingDataProvider
|
476 |
-
* @version 6.0.0
|
477 |
-
*/
|
478 |
-
public function testTypeCasting($condition, $expectedResult)
|
479 |
-
{
|
480 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
481 |
-
|
482 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
483 |
-
}
|
484 |
-
|
485 |
-
/**
|
486 |
-
* Type casting data provider
|
487 |
-
*
|
488 |
-
* @return void
|
489 |
-
*
|
490 |
-
* @access public
|
491 |
-
* @version 6.0.0
|
492 |
-
*/
|
493 |
-
public function typeCastingDataProvider()
|
494 |
-
{
|
495 |
-
return array(
|
496 |
-
array(array('Equals' => array('(*int)1' => 1)), true),
|
497 |
-
array(array('Equals' => array('(*bool)false' => false)), true),
|
498 |
-
array(array('Equals' => array('(*boolean)true' => true)), true),
|
499 |
-
array(array('Equals' => array('(*string)1' => '1')), true),
|
500 |
-
array(array('Equals' => array('(*null)' => null)), true),
|
501 |
-
array(array('Equals' => array('(*array)[2,3]' => array(2,3))), true),
|
502 |
-
array(array('Equals' => array('(*ip)192.168.1.1' => inet_pton('192.168.1.1'))), true)
|
503 |
-
);
|
504 |
-
}
|
505 |
-
|
506 |
-
/**
|
507 |
-
* Validate complex condition
|
508 |
-
*
|
509 |
-
* @param array $condition
|
510 |
-
* @param boolean $expectedResult
|
511 |
-
*
|
512 |
-
* @return void
|
513 |
-
*
|
514 |
-
* @access public
|
515 |
-
* @dataProvider complexDataProvider
|
516 |
-
* @version 6.0.0
|
517 |
-
*/
|
518 |
-
public function testComplexCondition($condition, $expectedResult)
|
519 |
-
{
|
520 |
-
$manager = AAM_Core_Policy_Condition::getInstance();
|
521 |
-
|
522 |
-
$this->assertEquals($expectedResult, $manager->evaluate($condition));
|
523 |
-
}
|
524 |
-
|
525 |
-
/**
|
526 |
-
* Complex condition data provider
|
527 |
-
*
|
528 |
-
* @return void
|
529 |
-
*
|
530 |
-
* @access public
|
531 |
-
* @version 6.0.0
|
532 |
-
*/
|
533 |
-
public function complexDataProvider()
|
534 |
-
{
|
535 |
-
return array(
|
536 |
-
array(array(
|
537 |
-
'Equals' => array('(*int)1' => 1),
|
538 |
-
'NotEquals' => array('2a' => 2)
|
539 |
-
), true)
|
540 |
-
);
|
541 |
-
}
|
542 |
-
|
543 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyManagerTest.php
DELETED
@@ -1,170 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Policy,
|
14 |
-
AAM_Core_Policy_Manager,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Test policy manager
|
21 |
-
*
|
22 |
-
* Make sure that access policies are parsed properly
|
23 |
-
*
|
24 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
25 |
-
* @version 6.0.0
|
26 |
-
*/
|
27 |
-
class PolicyManagerTest extends TestCase
|
28 |
-
{
|
29 |
-
use ResetTrait,
|
30 |
-
AuthUserTrait;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Test simple policy load
|
34 |
-
*
|
35 |
-
* @return void
|
36 |
-
*
|
37 |
-
* @access public
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testSimplePolicy()
|
41 |
-
{
|
42 |
-
$stub = $this->prepareManagerStub('simple-policy');
|
43 |
-
|
44 |
-
$this->assertEquals($stub->getTree(), array(
|
45 |
-
'Statement' => array(
|
46 |
-
'backendmenu:edit.php' => array(
|
47 |
-
'Effect' => 'deny'
|
48 |
-
)
|
49 |
-
),
|
50 |
-
'Param' => array()
|
51 |
-
));
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
* Test simple policy load
|
56 |
-
*
|
57 |
-
* @return void
|
58 |
-
*
|
59 |
-
* @access public
|
60 |
-
* @version 6.0.0
|
61 |
-
*/
|
62 |
-
public function testSimplePolicyWithAction()
|
63 |
-
{
|
64 |
-
$stub = $this->prepareManagerStub('simple-policy-with-action');
|
65 |
-
|
66 |
-
$this->assertEquals($stub->getTree(), array(
|
67 |
-
'Statement' => array(
|
68 |
-
'capability:switch_themes:aam:toggle' => array(
|
69 |
-
'Effect' => 'deny'
|
70 |
-
)
|
71 |
-
),
|
72 |
-
'Param' => array()
|
73 |
-
));
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Test that site options are overwritten by policy
|
78 |
-
*
|
79 |
-
* @return void
|
80 |
-
*
|
81 |
-
* @access public
|
82 |
-
* @version 6.0.0
|
83 |
-
*/
|
84 |
-
public function testOptionOverridePolicy()
|
85 |
-
{
|
86 |
-
$stub = $this->prepareManagerStub('option-override-policy');
|
87 |
-
|
88 |
-
$this->assertEquals($stub->getTree(), array(
|
89 |
-
'Statement' => array(),
|
90 |
-
'Param' => array(
|
91 |
-
'option:unittest' => array(
|
92 |
-
'Key' => 'option:unittest',
|
93 |
-
'Value' => 'unititest.me'
|
94 |
-
)
|
95 |
-
)
|
96 |
-
));
|
97 |
-
|
98 |
-
$this->assertEquals('unititest.me', get_option('unittest'));
|
99 |
-
$this->assertEquals('unititest.me', get_site_option('unittest'));
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Test that dynamic markers are replaced with actual value
|
104 |
-
*
|
105 |
-
* @return void
|
106 |
-
*
|
107 |
-
* @access public
|
108 |
-
* @version 6.0.0
|
109 |
-
*/
|
110 |
-
public function testDynamicResourcePolicy()
|
111 |
-
{
|
112 |
-
$stub = $this->prepareManagerStub('dynamic-resource');
|
113 |
-
|
114 |
-
$this->assertArrayHasKey('post:post:1:read', $stub->getTree()['Statement']);
|
115 |
-
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* Test that dynamic markers are replaced with actual value
|
119 |
-
*
|
120 |
-
* @return void
|
121 |
-
*
|
122 |
-
* @access public
|
123 |
-
* @version 6.0.0
|
124 |
-
*/
|
125 |
-
public function testDynamicParamPolicy()
|
126 |
-
{
|
127 |
-
$stub = $this->prepareManagerStub('dynamic-param');
|
128 |
-
|
129 |
-
$this->assertArrayHasKey('hello-world-admin', $stub->getTree()['Param']);
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* Prepare proper policy manager stub
|
134 |
-
*
|
135 |
-
* @param string $policy_file
|
136 |
-
*
|
137 |
-
* @return object
|
138 |
-
*
|
139 |
-
* @access protected
|
140 |
-
* @version 6.0.0
|
141 |
-
*/
|
142 |
-
protected function prepareManagerStub($policy_file)
|
143 |
-
{
|
144 |
-
// Fake the assigned policy to the user
|
145 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Policy::OBJECT_TYPE);
|
146 |
-
$object->updateOptionItem(1, true)->save();
|
147 |
-
|
148 |
-
// Create a stub for the SomeClass class.
|
149 |
-
$stub = $this->getMockBuilder(AAM_Core_Policy_Manager::class)
|
150 |
-
->setConstructorArgs(array(AAM::getUser()))
|
151 |
-
->setMethods(array('fetchPolicies'))
|
152 |
-
->getMock();
|
153 |
-
|
154 |
-
// Configure the stub
|
155 |
-
$stub->method('fetchPolicies')->willReturn(array(
|
156 |
-
(object) array(
|
157 |
-
'ID' => 1,
|
158 |
-
'post_content' => file_get_contents(
|
159 |
-
__DIR__ . '/policies/' . $policy_file . '.json'
|
160 |
-
)
|
161 |
-
)
|
162 |
-
));
|
163 |
-
|
164 |
-
// Initialize the policy tree
|
165 |
-
$stub->initialize();
|
166 |
-
|
167 |
-
return $stub;
|
168 |
-
}
|
169 |
-
|
170 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyServiceIntegrationTest.php
DELETED
@@ -1,413 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Uri,
|
14 |
-
AAM_Core_Object_Post,
|
15 |
-
AAM_Core_Object_Menu,
|
16 |
-
AAM_Core_Object_Policy,
|
17 |
-
AAM_Core_Policy_Factory,
|
18 |
-
AAM_Core_Object_Toolbar,
|
19 |
-
AAM_Core_Object_Metabox,
|
20 |
-
PHPUnit\Framework\TestCase,
|
21 |
-
AAM\UnitTest\Libs\ResetTrait,
|
22 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Test access policy integration with core AAM services
|
26 |
-
*
|
27 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
28 |
-
* @version 6.0.0
|
29 |
-
*/
|
30 |
-
class PolicyServiceIntegrationTest extends TestCase
|
31 |
-
{
|
32 |
-
use ResetTrait,
|
33 |
-
AuthUserTrait;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Test that Access Policy integrates with Admin Menu service
|
37 |
-
*
|
38 |
-
* @return void
|
39 |
-
*
|
40 |
-
* @access public
|
41 |
-
* @version 6.0.0
|
42 |
-
*/
|
43 |
-
public function testAdminMenuIntegration()
|
44 |
-
{
|
45 |
-
$this->preparePlayground('admin-menu');
|
46 |
-
|
47 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
48 |
-
|
49 |
-
$this->assertTrue($object->isRestricted('edit.php'));
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Test that Access Policy integrates with Toolbar service
|
54 |
-
*
|
55 |
-
* @return void
|
56 |
-
*
|
57 |
-
* @access public
|
58 |
-
* @version 6.0.0
|
59 |
-
*/
|
60 |
-
public function testToolbarIntegration()
|
61 |
-
{
|
62 |
-
$this->preparePlayground('toolbar');
|
63 |
-
|
64 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
65 |
-
|
66 |
-
$this->assertTrue($object->isHidden('about'));
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Test that Access Policy integrates with Metaboxes & Widgets service
|
71 |
-
*
|
72 |
-
* @return void
|
73 |
-
*
|
74 |
-
* @access public
|
75 |
-
* @version 6.0.0
|
76 |
-
*/
|
77 |
-
public function testMetaboxIntegration()
|
78 |
-
{
|
79 |
-
$this->preparePlayground('metabox');
|
80 |
-
|
81 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
82 |
-
|
83 |
-
$this->assertTrue($object->isHidden('widgets', 'WP_Widget_Pages'));
|
84 |
-
$this->assertTrue($object->isHidden('aam_policy', 'revisionsdiv'));
|
85 |
-
}
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Test that Access Policy integrates with Content service for simple actions
|
89 |
-
*
|
90 |
-
* @return void
|
91 |
-
*
|
92 |
-
* @access public
|
93 |
-
* @version 6.0.0
|
94 |
-
*/
|
95 |
-
public function testContentSimpleActionsIntegration()
|
96 |
-
{
|
97 |
-
$this->preparePlayground('post-simple-actions');
|
98 |
-
|
99 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
100 |
-
|
101 |
-
$this->assertFalse($object->isAllowedTo('edit'));
|
102 |
-
$this->assertFalse($object->isAllowedTo('delete'));
|
103 |
-
$this->assertFalse($object->isAllowedTo('publish'));
|
104 |
-
$this->assertFalse($object->isAllowedTo('comment'));
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Test that Access Policy integrates with Content service for Restricted action
|
109 |
-
*
|
110 |
-
* @return void
|
111 |
-
*
|
112 |
-
* @access public
|
113 |
-
* @version 6.0.0
|
114 |
-
*/
|
115 |
-
public function testContentRestrictedIntegration()
|
116 |
-
{
|
117 |
-
$this->preparePlayground('post-restricted');
|
118 |
-
|
119 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
120 |
-
|
121 |
-
$this->assertTrue($object->is('restricted'));
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Test that Access Policy integrates with Content service for Hidden action
|
126 |
-
*
|
127 |
-
* @return void
|
128 |
-
*
|
129 |
-
* @access public
|
130 |
-
* @version 6.0.0
|
131 |
-
*/
|
132 |
-
public function testContentHiddenIntegration()
|
133 |
-
{
|
134 |
-
$this->preparePlayground('post-hidden');
|
135 |
-
|
136 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
137 |
-
|
138 |
-
$this->assertTrue($object->is('hidden'));
|
139 |
-
|
140 |
-
// Verify that post is no longer in the list of posts
|
141 |
-
$posts = get_posts(array(
|
142 |
-
'post_type' => 'post',
|
143 |
-
'fields' => 'ids',
|
144 |
-
'suppress_filters' => false
|
145 |
-
));
|
146 |
-
|
147 |
-
// First, confirm that post is in the array of posts
|
148 |
-
$this->assertFalse(in_array(1, $posts));
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* Test that Access Policy integrates with Content service for Password protected
|
153 |
-
* action
|
154 |
-
*
|
155 |
-
* @return void
|
156 |
-
*
|
157 |
-
* @access public
|
158 |
-
* @version 6.0.0
|
159 |
-
*/
|
160 |
-
public function testContentComplexActionsIntegration()
|
161 |
-
{
|
162 |
-
$this->preparePlayground('post-complex-actions');
|
163 |
-
|
164 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
165 |
-
|
166 |
-
$this->assertTrue($object->is('protected'));
|
167 |
-
$this->assertEquals(array(
|
168 |
-
'enabled' => true,
|
169 |
-
'password' => '123456'
|
170 |
-
), $object->get('protected'));
|
171 |
-
|
172 |
-
$this->assertTrue($object->has('teaser'));
|
173 |
-
$this->assertEquals(array(
|
174 |
-
'enabled' => true,
|
175 |
-
'message' => 'This is just a teaser message'
|
176 |
-
), $object->get('teaser'));
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Test that Access Policy integrates with Content service for Redirected action
|
181 |
-
* where page ID is specified
|
182 |
-
*
|
183 |
-
* @return void
|
184 |
-
*
|
185 |
-
* @access public
|
186 |
-
* @version 6.0.0
|
187 |
-
*/
|
188 |
-
public function testContentRedirectPageIdIntegration()
|
189 |
-
{
|
190 |
-
$this->preparePlayground('post-redirect-page-id');
|
191 |
-
|
192 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
193 |
-
|
194 |
-
$this->assertTrue($object->is('redirected'));
|
195 |
-
$this->assertEquals(array(
|
196 |
-
'enabled' => true,
|
197 |
-
'type' => 'page',
|
198 |
-
'httpCode' => 301,
|
199 |
-
'destination' => 2
|
200 |
-
), $object->get('redirected'));
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Test that Access Policy integrates with Content service for Redirected action
|
205 |
-
* where page slug is specified
|
206 |
-
*
|
207 |
-
* @return void
|
208 |
-
*
|
209 |
-
* @access public
|
210 |
-
* @version 6.0.0
|
211 |
-
*/
|
212 |
-
public function testContentRedirectPageSlugIntegration()
|
213 |
-
{
|
214 |
-
$this->preparePlayground('post-redirect-page-slug');
|
215 |
-
|
216 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
217 |
-
|
218 |
-
$this->assertTrue($object->is('redirected'));
|
219 |
-
$this->assertEquals(array(
|
220 |
-
'enabled' => true,
|
221 |
-
'type' => 'page',
|
222 |
-
'httpCode' => 301,
|
223 |
-
'destination' => get_page_by_path('sample-page', OBJECT)->ID
|
224 |
-
), $object->get('redirected'));
|
225 |
-
}
|
226 |
-
|
227 |
-
/**
|
228 |
-
* Test that Access Policy integrates with Content service for Redirected action
|
229 |
-
* where URL is specified
|
230 |
-
*
|
231 |
-
* @return void
|
232 |
-
*
|
233 |
-
* @access public
|
234 |
-
* @version 6.0.0
|
235 |
-
*/
|
236 |
-
public function testContentRedirectUrlIntegration()
|
237 |
-
{
|
238 |
-
$this->preparePlayground('post-redirect-url');
|
239 |
-
|
240 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
241 |
-
|
242 |
-
$this->assertTrue($object->is('redirected'));
|
243 |
-
$this->assertEquals(array(
|
244 |
-
'enabled' => true,
|
245 |
-
'type' => 'url',
|
246 |
-
'httpCode' => 307,
|
247 |
-
'destination' => 'https://aamplugin.com'
|
248 |
-
), $object->get('redirected'));
|
249 |
-
}
|
250 |
-
|
251 |
-
/**
|
252 |
-
* Test that Access Policy integrates with Content service for Redirected action
|
253 |
-
* where callback is specified
|
254 |
-
*
|
255 |
-
* @return void
|
256 |
-
*
|
257 |
-
* @access public
|
258 |
-
* @version 6.0.0
|
259 |
-
*/
|
260 |
-
public function testContentRedirectCallbackIntegration()
|
261 |
-
{
|
262 |
-
$this->preparePlayground('post-redirect-callback');
|
263 |
-
|
264 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Post::OBJECT_TYPE, 1);
|
265 |
-
|
266 |
-
$this->assertTrue($object->is('redirected'));
|
267 |
-
$this->assertEquals(array(
|
268 |
-
'enabled' => true,
|
269 |
-
'type' => 'callback',
|
270 |
-
'httpCode' => 307,
|
271 |
-
'destination' => 'AAM\Callback\Main::helloWorld'
|
272 |
-
), $object->get('redirected'));
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Test that Access Policy integrates with URI service for all possible permutation
|
277 |
-
* of actions
|
278 |
-
*
|
279 |
-
* @return void
|
280 |
-
*
|
281 |
-
* @access public
|
282 |
-
* @version 6.0.0
|
283 |
-
*/
|
284 |
-
public function testUriIntegration()
|
285 |
-
{
|
286 |
-
$this->preparePlayground('uri');
|
287 |
-
|
288 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
289 |
-
|
290 |
-
$this->assertEquals(array(
|
291 |
-
'type' => 'default',
|
292 |
-
), $object->findMatch('/hello-world-1/'));
|
293 |
-
|
294 |
-
$this->assertEquals(array(
|
295 |
-
'type' => 'message',
|
296 |
-
'action' => 'Access Is Denied',
|
297 |
-
'code' => 307
|
298 |
-
), $object->findMatch('/hello-world-2/'));
|
299 |
-
|
300 |
-
$this->assertEquals(array(
|
301 |
-
'type' => 'page',
|
302 |
-
'action' => 2,
|
303 |
-
'code' => 307
|
304 |
-
), $object->findMatch('/hello-world-3/'));
|
305 |
-
|
306 |
-
$this->assertEquals(array(
|
307 |
-
'type' => 'page',
|
308 |
-
'action' => get_page_by_path('sample-page', OBJECT, 'page')->ID,
|
309 |
-
'code' => 307
|
310 |
-
), $object->findMatch('/hello-world-4/'));
|
311 |
-
|
312 |
-
$this->assertEquals(array(
|
313 |
-
'type' => 'url',
|
314 |
-
'action' => '/another-location',
|
315 |
-
'code' => 303
|
316 |
-
), $object->findMatch('/hello-world-5/'));
|
317 |
-
|
318 |
-
$this->assertEquals(array(
|
319 |
-
'type' => 'callback',
|
320 |
-
'action' => 'AAM\\Callback\\Main::helloWorld',
|
321 |
-
'code' => 307
|
322 |
-
), $object->findMatch('/hello-world-6/'));
|
323 |
-
|
324 |
-
$this->assertEquals(array(
|
325 |
-
'type' => 'login',
|
326 |
-
'action' => null,
|
327 |
-
'code' => 401
|
328 |
-
), $object->findMatch('/hello-world-7/'));
|
329 |
-
}
|
330 |
-
|
331 |
-
/**
|
332 |
-
* Test ability to toggle the ability activate/deactivate individual plugin with
|
333 |
-
* Access Policy
|
334 |
-
*
|
335 |
-
* @return void
|
336 |
-
*
|
337 |
-
* @access public
|
338 |
-
* @version 6.0.0
|
339 |
-
*/
|
340 |
-
public function testSinglePluginIntegration()
|
341 |
-
{
|
342 |
-
// Making sure that current user can activate/deactivate plugin
|
343 |
-
$this->assertTrue(current_user_can('activate_plugin', 'advanced-access-manager'));
|
344 |
-
$this->assertTrue(current_user_can('deactivate_plugin', 'advanced-access-manager'));
|
345 |
-
|
346 |
-
$this->preparePlayground('single-plugin');
|
347 |
-
|
348 |
-
// Making sure that current user no longer has these privileges
|
349 |
-
$this->assertFalse(current_user_can('activate_plugin', 'advanced-access-manager'));
|
350 |
-
$this->assertFalse(current_user_can('deactivate_plugin', 'advanced-access-manager'));
|
351 |
-
}
|
352 |
-
|
353 |
-
/**
|
354 |
-
* Test ability to toggle the ability activate/deactivate individual plugin with
|
355 |
-
* Access Policy
|
356 |
-
*
|
357 |
-
* @return void
|
358 |
-
*
|
359 |
-
* @access public
|
360 |
-
* @version 6.0.0
|
361 |
-
*/
|
362 |
-
public function testAllPluginsIntegration()
|
363 |
-
{
|
364 |
-
// Making sure that current user can perform all 4 basic actions
|
365 |
-
$this->assertTrue(current_user_can('install_plugins'));
|
366 |
-
$this->assertTrue(current_user_can('update_plugins'));
|
367 |
-
$this->assertTrue(current_user_can('edit_plugins'));
|
368 |
-
$this->assertTrue(current_user_can('delete_plugins'));
|
369 |
-
|
370 |
-
$this->preparePlayground('plugins');
|
371 |
-
|
372 |
-
// Making sure that current user no longer has these privileges
|
373 |
-
$this->assertFalse(current_user_can('install_plugins'));
|
374 |
-
$this->assertFalse(current_user_can('update_plugins'));
|
375 |
-
$this->assertFalse(current_user_can('edit_plugins'));
|
376 |
-
$this->assertFalse(current_user_can('delete_plugins'));
|
377 |
-
}
|
378 |
-
|
379 |
-
/**
|
380 |
-
* Prepare the environment
|
381 |
-
*
|
382 |
-
* Update Unit Test access policy with proper policy
|
383 |
-
*
|
384 |
-
* @param string $policy_file
|
385 |
-
*
|
386 |
-
* @return void
|
387 |
-
*
|
388 |
-
* @access protected
|
389 |
-
* @version 6.0.0
|
390 |
-
*/
|
391 |
-
protected function preparePlayground($policy_file)
|
392 |
-
{
|
393 |
-
// Update existing Access Policy with new policy
|
394 |
-
wp_update_post(array(
|
395 |
-
'ID' => AAM_UNITTEST_ACCESS_POLICY_ID,
|
396 |
-
'post_content' => file_get_contents(
|
397 |
-
__DIR__ . '/policies/' . $policy_file . '.json'
|
398 |
-
)
|
399 |
-
));
|
400 |
-
|
401 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Policy::OBJECT_TYPE);
|
402 |
-
$this->assertTrue(
|
403 |
-
$object->updateOptionItem(AAM_UNITTEST_ACCESS_POLICY_ID, true)->save()
|
404 |
-
);
|
405 |
-
|
406 |
-
// Reset all internal cache
|
407 |
-
$this->_resetSubjects();
|
408 |
-
|
409 |
-
// Reset Access Policy Factory cache
|
410 |
-
AAM_Core_Policy_Factory::reset();
|
411 |
-
}
|
412 |
-
|
413 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyTokenTest.php
DELETED
@@ -1,236 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Jwt_Issuer,
|
14 |
-
AAM_Core_Policy_Token,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test policy token evaluator
|
20 |
-
*
|
21 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class PolicyTokenTest extends TestCase
|
25 |
-
{
|
26 |
-
|
27 |
-
use ResetTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Validate correct USER token evaluation
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testUserTokenEvaluation()
|
38 |
-
{
|
39 |
-
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
40 |
-
|
41 |
-
// Set current User. Emulate that this is admin login
|
42 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_USER_ID);
|
43 |
-
|
44 |
-
$caps = array();
|
45 |
-
foreach ((array) AAM::getUser()->allcaps as $cap => $effect) {
|
46 |
-
if (!empty($effect)) {
|
47 |
-
$caps[] = $cap;
|
48 |
-
}
|
49 |
-
}
|
50 |
-
|
51 |
-
$cases = array(
|
52 |
-
array('${USER.ID}', 1),
|
53 |
-
array('${USER.ip}', '127.0.0.1'),
|
54 |
-
array('${USER.ipAddress}', '127.0.0.1'),
|
55 |
-
array('${USER.authenticated}', true),
|
56 |
-
array('${USER.isAuthenticated}', true),
|
57 |
-
array('${USER.capabilities}', json_encode($caps)),
|
58 |
-
array('${USER.caps}', json_encode($caps)),
|
59 |
-
);
|
60 |
-
|
61 |
-
foreach($cases as $case) {
|
62 |
-
$this->assertEquals(
|
63 |
-
$case[1], AAM_Core_Policy_Token::evaluate($case[0], array($case[0]))
|
64 |
-
);
|
65 |
-
}
|
66 |
-
|
67 |
-
// Reset user
|
68 |
-
wp_set_current_user(0);
|
69 |
-
unset($_SERVER['REMOTE_ADDR']);
|
70 |
-
}
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Validate correct USER_META token evaluation
|
74 |
-
*
|
75 |
-
* @return void
|
76 |
-
*
|
77 |
-
* @access public
|
78 |
-
* @version 6.0.0
|
79 |
-
*/
|
80 |
-
public function testUserMetaTokenEvaluation()
|
81 |
-
{
|
82 |
-
// Set current User. Emulate that this is admin login
|
83 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_USER_ID);
|
84 |
-
|
85 |
-
add_user_meta(AAM_UNITTEST_AUTH_USER_ID, 'aam_unittest', 'hello');
|
86 |
-
|
87 |
-
$this->assertEquals(
|
88 |
-
'hello',
|
89 |
-
AAM_Core_Policy_Token::evaluate(
|
90 |
-
'${USER_META.aam_unittest}', array('${USER_META.aam_unittest}')
|
91 |
-
)
|
92 |
-
);
|
93 |
-
|
94 |
-
// Reset user
|
95 |
-
wp_set_current_user(0);
|
96 |
-
unset($_SERVER['REMOTE_ADDR']);
|
97 |
-
delete_user_meta(AAM_UNITTEST_AUTH_USER_ID, 'aam_unittest');
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Test DATETIME token evaluation
|
102 |
-
*
|
103 |
-
* @return void
|
104 |
-
*
|
105 |
-
* @access public
|
106 |
-
* @version 6.0.0
|
107 |
-
*/
|
108 |
-
public function testDateTimeTokenEvaluation()
|
109 |
-
{
|
110 |
-
$this->assertEquals(
|
111 |
-
date('Y-m-d'),
|
112 |
-
AAM_Core_Policy_Token::evaluate(
|
113 |
-
'${DATETIME.Y-m-d}', array('${DATETIME.Y-m-d}')
|
114 |
-
)
|
115 |
-
);
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Test HTTP_* and PHP_* tokens evaluation
|
120 |
-
*
|
121 |
-
* @return void
|
122 |
-
*
|
123 |
-
* @access public
|
124 |
-
* @version 6.0.0
|
125 |
-
*/
|
126 |
-
public function testHttpTokensEvaluation()
|
127 |
-
{
|
128 |
-
// Fake data
|
129 |
-
$_GET['aam_test'] = "1a";
|
130 |
-
$_POST['aam_test'] = "1b";
|
131 |
-
$_COOKIE['aam_test'] = "1c";
|
132 |
-
$_SERVER['aam_test'] = "1d";
|
133 |
-
|
134 |
-
$this->assertEquals(
|
135 |
-
'1a', AAM_Core_Policy_Token::evaluate('${HTTP_GET.aam_test}', array('${HTTP_GET.aam_test}'))
|
136 |
-
);
|
137 |
-
|
138 |
-
$this->assertEquals(
|
139 |
-
'1a', AAM_Core_Policy_Token::evaluate('${HTTP_QUERY.aam_test}', array('${HTTP_QUERY.aam_test}'))
|
140 |
-
);
|
141 |
-
|
142 |
-
$this->assertEquals(
|
143 |
-
'1b', AAM_Core_Policy_Token::evaluate('${HTTP_POST.aam_test}', array('${HTTP_POST.aam_test}'))
|
144 |
-
);
|
145 |
-
|
146 |
-
$this->assertEquals(
|
147 |
-
'1c', AAM_Core_Policy_Token::evaluate('${HTTP_COOKIE.aam_test}', array('${HTTP_COOKIE.aam_test}'))
|
148 |
-
);
|
149 |
-
|
150 |
-
$this->assertEquals(
|
151 |
-
'1d', AAM_Core_Policy_Token::evaluate('${PHP_SERVER.aam_test}', array('${PHP_SERVER.aam_test}'))
|
152 |
-
);
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* Test ARGS token evaluation
|
157 |
-
*
|
158 |
-
* @return void
|
159 |
-
*
|
160 |
-
* @access public
|
161 |
-
* @version 6.0.0
|
162 |
-
*/
|
163 |
-
public function testArgTokenEvaluation()
|
164 |
-
{
|
165 |
-
$this->assertEquals(
|
166 |
-
'1a',
|
167 |
-
AAM_Core_Policy_Token::evaluate(
|
168 |
-
'${ARGS.test}', array('${ARGS.test}'), array('test' => '1a')
|
169 |
-
)
|
170 |
-
);
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Test CONST token evaluation
|
175 |
-
*
|
176 |
-
* @return void
|
177 |
-
*
|
178 |
-
* @access public
|
179 |
-
* @version 6.0.0
|
180 |
-
*/
|
181 |
-
public function testConstTokenEvaluation()
|
182 |
-
{
|
183 |
-
$this->assertEquals(
|
184 |
-
AAM_VERSION,
|
185 |
-
AAM_Core_Policy_Token::evaluate(
|
186 |
-
'${CONST.AAM_VERSION}', array('${CONST.AAM_VERSION}')
|
187 |
-
)
|
188 |
-
);
|
189 |
-
}
|
190 |
-
|
191 |
-
/**
|
192 |
-
* Test WP_OPTION token evaluation
|
193 |
-
*
|
194 |
-
* @return void
|
195 |
-
*
|
196 |
-
* @access public
|
197 |
-
* @version 6.0.0
|
198 |
-
*/
|
199 |
-
public function testWpOptionTokenEvaluation()
|
200 |
-
{
|
201 |
-
$this->assertEquals(
|
202 |
-
get_option('siteurl'),
|
203 |
-
AAM_Core_Policy_Token::evaluate(
|
204 |
-
'${WP_OPTION.siteurl}', array('${WP_OPTION.siteurl}')
|
205 |
-
)
|
206 |
-
);
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* Test JWT token evaluation
|
211 |
-
*
|
212 |
-
* @return void
|
213 |
-
*
|
214 |
-
* @access public
|
215 |
-
* @version 6.0.0
|
216 |
-
*/
|
217 |
-
public function testJwtTokenEvaluation()
|
218 |
-
{
|
219 |
-
// generate token
|
220 |
-
$result = AAM_Core_Jwt_Issuer::getInstance()->issueToken(
|
221 |
-
array('testProp' => 'helloWorld')
|
222 |
-
);
|
223 |
-
|
224 |
-
$_SERVER['HTTP_AUTHENTICATION'] = $result->token;
|
225 |
-
|
226 |
-
$this->assertEquals(
|
227 |
-
'helloWorld',
|
228 |
-
AAM_Core_Policy_Token::evaluate(
|
229 |
-
'${JWT.testProp}', array('${JWT.testProp}')
|
230 |
-
)
|
231 |
-
);
|
232 |
-
|
233 |
-
unset($_SERVER['HTTP_AUTHENTICATION']);
|
234 |
-
}
|
235 |
-
|
236 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyUserRoleIntegrationTest.php
DELETED
@@ -1,143 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_API,
|
14 |
-
AAM_Core_Config,
|
15 |
-
AAM_Core_Policy_Factory,
|
16 |
-
AAM_Core_AccessSettings,
|
17 |
-
PHPUnit\Framework\TestCase;
|
18 |
-
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test access policy integration with core user roles system
|
22 |
-
*
|
23 |
-
* @version 6.0.0
|
24 |
-
*/
|
25 |
-
class PolicyUserRoleIntegrationTest extends TestCase
|
26 |
-
{
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Test that policy allows to assign or deprive specific capabilities
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testCapabilityAdded()
|
37 |
-
{
|
38 |
-
$this->preparePlayground('capability-changes');
|
39 |
-
|
40 |
-
// Reset current user to trigger policy changes
|
41 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_USER_ID);
|
42 |
-
|
43 |
-
$this->assertFalse(current_user_can('switch_themes'));
|
44 |
-
$this->assertTrue(current_user_can('hello_world'));
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Test that policy allows to add new role to user
|
49 |
-
*
|
50 |
-
* @return void
|
51 |
-
*
|
52 |
-
* @access public
|
53 |
-
* @version 6.0.0
|
54 |
-
*/
|
55 |
-
public function testAddedRole()
|
56 |
-
{
|
57 |
-
$this->preparePlayground('role-add');
|
58 |
-
|
59 |
-
// Reset current user to trigger policy changes
|
60 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_USER_ID);
|
61 |
-
|
62 |
-
$this->assertContains('administrator', AAM::getUser()->roles);
|
63 |
-
$this->assertContains('contributor', AAM::getUser()->roles);
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Test that policy allows to add new role to user
|
68 |
-
*
|
69 |
-
* @return void
|
70 |
-
*
|
71 |
-
* @access public
|
72 |
-
* @version 6.0.0
|
73 |
-
*/
|
74 |
-
public function testRemovedRole()
|
75 |
-
{
|
76 |
-
$this->preparePlayground('role-remove', AAM_UNITTEST_AUTH_MULTIROLE_USER_ID);
|
77 |
-
|
78 |
-
// Reset current user to trigger policy changes
|
79 |
-
wp_set_current_user(AAM_UNITTEST_AUTH_MULTIROLE_USER_ID);
|
80 |
-
|
81 |
-
$this->assertFalse(in_array('editor', AAM::getUser()->roles, true));
|
82 |
-
$this->assertContains('subscriber', AAM::getUser()->roles);
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Prepare the environment
|
87 |
-
*
|
88 |
-
* Update Unit Test access policy with proper policy
|
89 |
-
*
|
90 |
-
* @param string $policy_file
|
91 |
-
* @param int $user
|
92 |
-
*
|
93 |
-
* @return void
|
94 |
-
*
|
95 |
-
* @access protected
|
96 |
-
* @version 6.0.0
|
97 |
-
*/
|
98 |
-
protected function preparePlayground($policy_file, $user = AAM_UNITTEST_AUTH_USER_ID)
|
99 |
-
{
|
100 |
-
// Update existing Access Policy with new policy
|
101 |
-
wp_update_post(array(
|
102 |
-
'ID' => AAM_UNITTEST_ACCESS_POLICY_ID,
|
103 |
-
'post_content' => file_get_contents(
|
104 |
-
__DIR__ . '/policies/' . $policy_file . '.json'
|
105 |
-
)
|
106 |
-
));
|
107 |
-
|
108 |
-
$settings = AAM_Core_AccessSettings::getInstance();
|
109 |
-
$settings->set(sprintf(
|
110 |
-
'user.%d.policy.%d', $user, AAM_UNITTEST_ACCESS_POLICY_ID
|
111 |
-
), true);
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* Reset all AAM settings to the default
|
116 |
-
*
|
117 |
-
* @return void
|
118 |
-
*
|
119 |
-
* @access protected
|
120 |
-
* @version 6.0.0
|
121 |
-
*/
|
122 |
-
protected function tearDown()
|
123 |
-
{
|
124 |
-
// Clear all AAM settings
|
125 |
-
AAM_Core_API::clearSettings();
|
126 |
-
|
127 |
-
// Reset Access Settings repository
|
128 |
-
AAM_Core_AccessSettings::getInstance()->reset();
|
129 |
-
|
130 |
-
// Unset the forced user
|
131 |
-
wp_set_current_user(0);
|
132 |
-
|
133 |
-
// Clear WP core cache
|
134 |
-
wp_cache_flush();
|
135 |
-
|
136 |
-
// Reset internal AAM config cache
|
137 |
-
AAM_Core_Config::bootstrap();
|
138 |
-
|
139 |
-
// Reset Access Policy Factory cache
|
140 |
-
AAM_Core_Policy_Factory::reset();
|
141 |
-
}
|
142 |
-
|
143 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/PolicyValidationTest.php
DELETED
@@ -1,125 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AccessPolicy;
|
11 |
-
|
12 |
-
use AAM_Backend_View_Helper,
|
13 |
-
AAM_Core_Policy_Validator,
|
14 |
-
PHPUnit\Framework\TestCase;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Test policy validator
|
18 |
-
*
|
19 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
20 |
-
* @version 6.0.0
|
21 |
-
*/
|
22 |
-
class PolicyValidationTest extends TestCase
|
23 |
-
{
|
24 |
-
/**
|
25 |
-
* Test that error is triggered when policy is empty
|
26 |
-
*
|
27 |
-
* @return void
|
28 |
-
*
|
29 |
-
* @access public
|
30 |
-
* @version 6.0.0
|
31 |
-
*/
|
32 |
-
public function testEmptyPolicy()
|
33 |
-
{
|
34 |
-
$validator = new AAM_Core_Policy_Validator('[]');
|
35 |
-
|
36 |
-
$this->assertEquals(array(
|
37 |
-
__('The policy document is empty', AAM_KEY)
|
38 |
-
), $validator->validate());
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Test that error is triggered when policy contains invalid JSON
|
43 |
-
*
|
44 |
-
* @return void
|
45 |
-
*
|
46 |
-
* @access public
|
47 |
-
* @version 6.0.0
|
48 |
-
*/
|
49 |
-
public function testInvalidJsonPolicy()
|
50 |
-
{
|
51 |
-
$validator = new AAM_Core_Policy_Validator('--');
|
52 |
-
|
53 |
-
$this->assertEquals(array(
|
54 |
-
__('The policy is not valid JSON object', AAM_KEY)
|
55 |
-
), $validator->validate());
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Test that error is triggered when missing dependency
|
60 |
-
*
|
61 |
-
* @return void
|
62 |
-
*
|
63 |
-
* @access public
|
64 |
-
* @version 6.0.0
|
65 |
-
*/
|
66 |
-
public function testMissingDependencyPolicy()
|
67 |
-
{
|
68 |
-
$validator = new AAM_Core_Policy_Validator('{
|
69 |
-
"Dependency": {
|
70 |
-
"advanced-access-manager-x": "^1.0.0"
|
71 |
-
}
|
72 |
-
}');
|
73 |
-
|
74 |
-
$this->assertEquals(array(
|
75 |
-
AAM_Backend_View_Helper::preparePhrase(
|
76 |
-
"The plugin [advanced-access-manager-x] is required by the policy",
|
77 |
-
'b'
|
78 |
-
)
|
79 |
-
), $validator->validate());
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Test that error is triggered when dependency version is not satisfied
|
84 |
-
*
|
85 |
-
* @return void
|
86 |
-
*
|
87 |
-
* @access public
|
88 |
-
* @version 6.0.0
|
89 |
-
*/
|
90 |
-
public function testLowDependencyPolicy()
|
91 |
-
{
|
92 |
-
$validator = new AAM_Core_Policy_Validator('{
|
93 |
-
"Dependency": {
|
94 |
-
"advanced-access-manager": "<6.0.0"
|
95 |
-
}
|
96 |
-
}');
|
97 |
-
|
98 |
-
$this->assertEquals(array(
|
99 |
-
AAM_Backend_View_Helper::preparePhrase(
|
100 |
-
"The dependency [advanced-access-manager] does not satisfy version requirement by the policy",
|
101 |
-
'b'
|
102 |
-
)
|
103 |
-
), $validator->validate());
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Test that there is no error when everything is ok
|
108 |
-
*
|
109 |
-
* @return void
|
110 |
-
*
|
111 |
-
* @access public
|
112 |
-
* @version 6.0.0
|
113 |
-
*/
|
114 |
-
public function testValidDependencyPolicy()
|
115 |
-
{
|
116 |
-
$validator = new AAM_Core_Policy_Validator('{
|
117 |
-
"Dependency": {
|
118 |
-
"advanced-access-manager": ">=' . AAM_VERSION . '"
|
119 |
-
}
|
120 |
-
}');
|
121 |
-
|
122 |
-
$this->assertEquals(0, count($validator->validate()));
|
123 |
-
}
|
124 |
-
|
125 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/admin-menu.json
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"BackendMenu:edit.php"
|
8 |
-
]
|
9 |
-
}
|
10 |
-
]
|
11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/capability-changes.json
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Capability:switch_themes"
|
8 |
-
]
|
9 |
-
},
|
10 |
-
{
|
11 |
-
"Effect": "allow",
|
12 |
-
"Resource": [
|
13 |
-
"Capability:hello_world"
|
14 |
-
]
|
15 |
-
}
|
16 |
-
]
|
17 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/dynamic-param.json
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Param": [
|
4 |
-
{
|
5 |
-
"Key": "hello-world-${USER.user_nicename}",
|
6 |
-
"Value": "hello"
|
7 |
-
}
|
8 |
-
]
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/dynamic-resource.json
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Post:post:${USER.ID}"
|
8 |
-
],
|
9 |
-
"Action": ["Read"]
|
10 |
-
}
|
11 |
-
]
|
12 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/metabox.json
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Widget:widgets|wp_widget_pages",
|
8 |
-
"Metabox:aam_policy|revisionsdiv"
|
9 |
-
]
|
10 |
-
}
|
11 |
-
]
|
12 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/option-override-policy.json
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Param": [
|
4 |
-
{
|
5 |
-
"Key": "option:unittest",
|
6 |
-
"Value": "unititest.me"
|
7 |
-
}
|
8 |
-
]
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/plugins.json
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": {
|
4 |
-
"Effect": "deny",
|
5 |
-
"Resource": "Plugin",
|
6 |
-
"Action": ["WP:install", "WP:edit", "WP:update", "WP:delete"]
|
7 |
-
}
|
8 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-complex-actions.json
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": "Read",
|
8 |
-
"Metadata": {
|
9 |
-
"Password": {
|
10 |
-
"Value": "123456"
|
11 |
-
},
|
12 |
-
"Teaser": {
|
13 |
-
"Value": "This is just a teaser message"
|
14 |
-
}
|
15 |
-
}
|
16 |
-
}
|
17 |
-
]
|
18 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-hidden.json
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": ["List"]
|
8 |
-
}
|
9 |
-
]
|
10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-redirect-callback.json
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": "Read",
|
8 |
-
"Metadata": {
|
9 |
-
"Redirect": {
|
10 |
-
"Type": "callback",
|
11 |
-
"Callback": "AAM\\\\Callback\\\\Main::helloWorld"
|
12 |
-
}
|
13 |
-
}
|
14 |
-
}
|
15 |
-
]
|
16 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-redirect-page-id.json
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": "Read",
|
8 |
-
"Metadata": {
|
9 |
-
"Redirect": {
|
10 |
-
"Type": "page",
|
11 |
-
"Id": 2,
|
12 |
-
"Code": 301
|
13 |
-
}
|
14 |
-
}
|
15 |
-
}
|
16 |
-
]
|
17 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-redirect-page-slug.json
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": "Read",
|
8 |
-
"Metadata": {
|
9 |
-
"Redirect": {
|
10 |
-
"Type": "page",
|
11 |
-
"Slug": "sample-page",
|
12 |
-
"Code": 301
|
13 |
-
}
|
14 |
-
}
|
15 |
-
}
|
16 |
-
]
|
17 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-redirect-url.json
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": {
|
4 |
-
"Effect": "deny",
|
5 |
-
"Resource": "Post:post:1",
|
6 |
-
"Action": "Read",
|
7 |
-
"Metadata": {
|
8 |
-
"Redirect": {
|
9 |
-
"Type": "url",
|
10 |
-
"URL": "https://aamplugin.com"
|
11 |
-
}
|
12 |
-
}
|
13 |
-
}
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-restricted.json
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": ["Read"]
|
8 |
-
}
|
9 |
-
]
|
10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/post-simple-actions.json
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "Post:post:1",
|
7 |
-
"Action": ["Edit", "Delete", "Publish", "Comment"]
|
8 |
-
}
|
9 |
-
]
|
10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/role-add.json
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "allow",
|
6 |
-
"Resource": [
|
7 |
-
"Role:contributor"
|
8 |
-
]
|
9 |
-
}
|
10 |
-
]
|
11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/role-remove.json
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Role:editor"
|
8 |
-
]
|
9 |
-
}
|
10 |
-
]
|
11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/simple-policy-with-action.json
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Capability:switch_themes"
|
8 |
-
],
|
9 |
-
"Action": "AAM:toggle"
|
10 |
-
}
|
11 |
-
]
|
12 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/simple-policy.json
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": {
|
4 |
-
"Effect": "deny",
|
5 |
-
"Resource": [
|
6 |
-
"BackendMenu:edit.php"
|
7 |
-
]
|
8 |
-
}
|
9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/single-plugin.json
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": {
|
4 |
-
"Effect": "deny",
|
5 |
-
"Resource": [
|
6 |
-
"Plugin:advanced-access-manager"
|
7 |
-
],
|
8 |
-
"Action": ["WP:deactivate", "WP:activate"]
|
9 |
-
}
|
10 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/toolbar.json
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": [
|
7 |
-
"Toolbar:about"
|
8 |
-
]
|
9 |
-
}
|
10 |
-
]
|
11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AccessPolicy/policies/uri.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Version": "1.0.0",
|
3 |
-
"Statement": [
|
4 |
-
{
|
5 |
-
"Effect": "deny",
|
6 |
-
"Resource": "URI:/hello-world-1"
|
7 |
-
},
|
8 |
-
{
|
9 |
-
"Effect": "deny",
|
10 |
-
"Resource": "URI:/hello-world-2",
|
11 |
-
"Metadata": {
|
12 |
-
"Type": "message",
|
13 |
-
"Message": "Access Is Denied"
|
14 |
-
}
|
15 |
-
},
|
16 |
-
{
|
17 |
-
"Effect": "deny",
|
18 |
-
"Resource": "URI:/hello-world-3",
|
19 |
-
"Metadata": {
|
20 |
-
"Type": "page",
|
21 |
-
"Id": 2
|
22 |
-
}
|
23 |
-
},
|
24 |
-
{
|
25 |
-
"Effect": "deny",
|
26 |
-
"Resource": "URI:/hello-world-4",
|
27 |
-
"Metadata": {
|
28 |
-
"Type": "page",
|
29 |
-
"Slug": "sample-page"
|
30 |
-
}
|
31 |
-
},
|
32 |
-
{
|
33 |
-
"Effect": "deny",
|
34 |
-
"Resource": "URI:/hello-world-5",
|
35 |
-
"Metadata": {
|
36 |
-
"Type": "url",
|
37 |
-
"URL": "/another-location",
|
38 |
-
"Code": 303
|
39 |
-
}
|
40 |
-
},
|
41 |
-
{
|
42 |
-
"Effect": "deny",
|
43 |
-
"Resource": "URI:/hello-world-6",
|
44 |
-
"Metadata": {
|
45 |
-
"Type": "callback",
|
46 |
-
"Callback": "AAM\\\\Callback\\\\Main::helloWorld"
|
47 |
-
}
|
48 |
-
},
|
49 |
-
{
|
50 |
-
"Effect": "deny",
|
51 |
-
"Resource": "URI:/hello-world-7",
|
52 |
-
"Metadata": {
|
53 |
-
"Type": "login"
|
54 |
-
}
|
55 |
-
}
|
56 |
-
]
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AdminMenu/MultipleRoleInheritanceTest.php
DELETED
@@ -1,182 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AdminMenu;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM_Core_Object_Menu,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthMultiRoleUserTrait,
|
18 |
-
AAM\UnitTest\Libs\MultiRoleOptionInterface;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test AAM access settings inheritance mechanism for multiple roles per user for
|
22 |
-
* the Admin Menu service
|
23 |
-
*
|
24 |
-
* Admin Menu is available only for authenticated users so no Visitors are tested
|
25 |
-
*
|
26 |
-
* @package AAM\UnitTest
|
27 |
-
* @version 6.0.0
|
28 |
-
*/
|
29 |
-
class MultipleRoleInheritanceTest extends TestCase implements MultiRoleOptionInterface
|
30 |
-
{
|
31 |
-
use ResetTrait,
|
32 |
-
AuthMultiRoleUserTrait;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Test that access settings are inherited from multiple parent roles
|
36 |
-
*
|
37 |
-
* This test is designed to verify that access settings are propagated property
|
38 |
-
* when there access settings defined for multiple parent roles.
|
39 |
-
*
|
40 |
-
* A. Test that settings can be stored for the parent roles;
|
41 |
-
* B. Test that access settings are propagated property to the User level
|
42 |
-
*
|
43 |
-
* @return void
|
44 |
-
*
|
45 |
-
* @access public
|
46 |
-
* @version 6.0.0
|
47 |
-
*/
|
48 |
-
public function testInheritanceMergeFromMultipleRoles()
|
49 |
-
{
|
50 |
-
$user = AAM::getUser();
|
51 |
-
$role = $user->getParent();
|
52 |
-
|
53 |
-
// Make sure that we have parent roles defined properly
|
54 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
55 |
-
|
56 |
-
// Save access settings for the base role and iterate over each sibling and
|
57 |
-
// add additional settings
|
58 |
-
$object = $role->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
59 |
-
$this->assertTrue($object->updateOptionItem('index.php?id=0', true)->save());
|
60 |
-
|
61 |
-
foreach($role->getSiblings() as $i => $sibling) {
|
62 |
-
// Save access settings for each role and make sure they are saved property
|
63 |
-
// Check if save returns positive result
|
64 |
-
$this->assertTrue(
|
65 |
-
$sibling->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true)->updateOptionItem(
|
66 |
-
'index.php?id=' . ($i + 1), ($i % 2 ? true : false)
|
67 |
-
)->save()
|
68 |
-
);
|
69 |
-
}
|
70 |
-
|
71 |
-
// Reset internal AAM cache
|
72 |
-
$this->_resetSubjects();
|
73 |
-
|
74 |
-
// Assert that we have both roles merged result is as following
|
75 |
-
// Array (
|
76 |
-
// index.php?id=0 => true,
|
77 |
-
// index.php?id=1 => false
|
78 |
-
// )
|
79 |
-
$option = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE)->getOption();
|
80 |
-
$this->assertSame(
|
81 |
-
array('index.php?id=0' => true, 'index.php?id=1' => false), $option
|
82 |
-
);
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Test that access settings are merged with default "deny" precedence correctly
|
87 |
-
*
|
88 |
-
* @return void
|
89 |
-
*
|
90 |
-
* @access public
|
91 |
-
* @version 6.0.0
|
92 |
-
*/
|
93 |
-
public function testInheritanceDenyPrecedenceFromMultipleRoles()
|
94 |
-
{
|
95 |
-
$user = AAM::getUser();
|
96 |
-
$role = $user->getParent();
|
97 |
-
|
98 |
-
// Make sure that we have parent roles defined properly
|
99 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
100 |
-
|
101 |
-
// Save access settings for the base role and iterate over each sibling and
|
102 |
-
// add additional settings
|
103 |
-
$this->assertTrue(
|
104 |
-
$role->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true)->updateOptionItem(
|
105 |
-
'index.php', true
|
106 |
-
)->save()
|
107 |
-
);
|
108 |
-
|
109 |
-
foreach($role->getSiblings() as $sibling) {
|
110 |
-
// Save access settings for each role and make sure they are saved property
|
111 |
-
// Check if save returns positive result
|
112 |
-
$this->assertTrue(
|
113 |
-
$sibling->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true)->updateOptionItem(
|
114 |
-
'index.php', false
|
115 |
-
)->save()
|
116 |
-
);
|
117 |
-
}
|
118 |
-
|
119 |
-
// Reset internal AAM cache
|
120 |
-
$this->_resetSubjects();
|
121 |
-
|
122 |
-
// Assert that we have both roles merged result is as following
|
123 |
-
// Array (
|
124 |
-
// index.php => true
|
125 |
-
// )
|
126 |
-
$option = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE)->getOption();
|
127 |
-
$this->assertSame(
|
128 |
-
array('index.php' => true), $option
|
129 |
-
);
|
130 |
-
}
|
131 |
-
|
132 |
-
/**
|
133 |
-
* Test that access settings are merged correctly with "allowed" precedence
|
134 |
-
* correctly
|
135 |
-
*
|
136 |
-
* @return void
|
137 |
-
* @version 6.0.0
|
138 |
-
*/
|
139 |
-
public function testInheritanceAllowPrecedenceFromMultipleRoles()
|
140 |
-
{
|
141 |
-
$user = AAM::getUser();
|
142 |
-
$role = $user->getParent();
|
143 |
-
|
144 |
-
// Make sure that we have parent roles defined properly
|
145 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
146 |
-
|
147 |
-
// Save access settings for the base role and iterate over each sibling and
|
148 |
-
// add additional settings
|
149 |
-
$this->assertTrue(
|
150 |
-
$role->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true)->updateOptionItem(
|
151 |
-
'index.php', true
|
152 |
-
)->save()
|
153 |
-
);
|
154 |
-
|
155 |
-
foreach($role->getSiblings() as $sibling) {
|
156 |
-
// Save access settings for each role and make sure they are saved property
|
157 |
-
// Check if save returns positive result
|
158 |
-
$this->assertTrue(
|
159 |
-
$sibling->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true)->updateOptionItem(
|
160 |
-
'index.php', false
|
161 |
-
)->save()
|
162 |
-
);
|
163 |
-
}
|
164 |
-
|
165 |
-
// Override the default "deny" precedence
|
166 |
-
AAM_Core_Config::set(
|
167 |
-
sprintf('core.settings.%s.merge.preference', AAM_Core_Object_Menu::OBJECT_TYPE),
|
168 |
-
'allow'
|
169 |
-
);
|
170 |
-
|
171 |
-
// Reset internal AAM cache
|
172 |
-
$this->_resetSubjects();
|
173 |
-
|
174 |
-
// Assert that we have both roles merged result is as following
|
175 |
-
// Array (
|
176 |
-
// index.php => false
|
177 |
-
// )
|
178 |
-
$option = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE)->getOption();
|
179 |
-
$this->assertSame(array('index.php' => false), $option);
|
180 |
-
}
|
181 |
-
|
182 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/AdminMenu/SingleRoleInheritanceTest.php
DELETED
@@ -1,226 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AdminMenu;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Menu,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM access settings inheritance mechanism for the Admin Menu service
|
20 |
-
*
|
21 |
-
* Admin Menu is available only for authenticated users so no Visitors are tested
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class SingleRoleInheritanceTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test to insure that access settings are stored property on the User level
|
33 |
-
*
|
34 |
-
* A. Test that "index.php" is stored to the database with "true" flag and true
|
35 |
-
* is returned by AAM_Core_Subject_User::updateOption method;
|
36 |
-
* B. Test that information is actually stored property in the database and can
|
37 |
-
* be retrieved successfully.
|
38 |
-
*
|
39 |
-
* @return void
|
40 |
-
*
|
41 |
-
* @access public
|
42 |
-
* @see AAM_Core_Subject_User::updateOption
|
43 |
-
* @version 6.0.0
|
44 |
-
*/
|
45 |
-
public function testSaveAdminMenuOption()
|
46 |
-
{
|
47 |
-
$user = AAM::getUser();
|
48 |
-
$object = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
49 |
-
|
50 |
-
// Check if save returns positive result
|
51 |
-
$this->assertTrue($object->updateOptionItem('index.php', true)->save());
|
52 |
-
|
53 |
-
// Read from the database saved values and assert that we have
|
54 |
-
// Array (
|
55 |
-
// index.php => true
|
56 |
-
// )
|
57 |
-
$option = $user->readOption('menu');
|
58 |
-
$this->assertSame(array('index.php' => true), $option);
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Test that access settings are inherited from the parent role property
|
63 |
-
*
|
64 |
-
* This test is designed to verify that access settings are propagated property
|
65 |
-
* when there is only one role assigned to a user.
|
66 |
-
*
|
67 |
-
* A. Test that settings can be stored for the parent role;
|
68 |
-
* B. Test that access settings are propagated property to the User level
|
69 |
-
*
|
70 |
-
* @return void
|
71 |
-
*
|
72 |
-
* @access public
|
73 |
-
* @version 6.0.0
|
74 |
-
*/
|
75 |
-
public function testInheritanceFromSingleRole()
|
76 |
-
{
|
77 |
-
$user = AAM::getUser();
|
78 |
-
$parent = $user->getParent();
|
79 |
-
$object = $parent->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
80 |
-
|
81 |
-
// Make sure that we have parent role defined
|
82 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($parent));
|
83 |
-
|
84 |
-
// Save access settings for the role and make sure they are saved property
|
85 |
-
// Check if save returns positive result
|
86 |
-
$this->assertTrue($object->updateOptionItem('index.php', true)->save());
|
87 |
-
|
88 |
-
// Read from the database saved values and assert that we have
|
89 |
-
// Array (
|
90 |
-
// index.php => true
|
91 |
-
// )
|
92 |
-
$option = $parent->readOption('menu');
|
93 |
-
$this->assertSame(array('index.php' => true), $option);
|
94 |
-
|
95 |
-
// Finally verify that access settings are propagated property to the User
|
96 |
-
// Level
|
97 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
98 |
-
$this->assertSame(array('index.php' => true), $menu->getOption());
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Test that access settings are propagated and merged properly
|
103 |
-
*
|
104 |
-
* The test is designed to verify that access settings are propagated properly
|
105 |
-
* from the parent role and merged well with explicitly defined access settings on
|
106 |
-
* the User level.
|
107 |
-
*
|
108 |
-
* The expected result is to have combined array of access settings from the parent
|
109 |
-
* role and specific user.
|
110 |
-
*
|
111 |
-
* A. Test that access settings are stored for the parent role;
|
112 |
-
* B. Test that access settings are stored for the user;
|
113 |
-
* C. Test that access settings are propagated and merged properly;
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*
|
117 |
-
* @access public
|
118 |
-
* @version 6.0.0
|
119 |
-
*/
|
120 |
-
public function testInheritanceMergeFromSingleRole()
|
121 |
-
{
|
122 |
-
$user = AAM::getUser();
|
123 |
-
$parent = $user->getParent();
|
124 |
-
|
125 |
-
$object = $parent->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
126 |
-
|
127 |
-
// Save access settings for the role and make sure they are saved property
|
128 |
-
// Check if save returns positive result
|
129 |
-
$this->assertTrue($object->updateOptionItem('update.php', true)->save());
|
130 |
-
|
131 |
-
// Save access setting for the user and make sure they are saved property
|
132 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
133 |
-
$this->assertTrue($menu->updateOptionItem('post.php?post_type=page', false)->save());
|
134 |
-
|
135 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
136 |
-
$this->_resetSubjects();
|
137 |
-
|
138 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
139 |
-
$this->assertSame(
|
140 |
-
array('update.php' => true, 'post.php?post_type=page' => false),
|
141 |
-
$menu->getOption()
|
142 |
-
);
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Test that the full inheritance mechanism is working as expected
|
147 |
-
*
|
148 |
-
* Make sure that access settings are propagated and merged properly from the top
|
149 |
-
* (Default Level)to the bottom (User Level).
|
150 |
-
*
|
151 |
-
* A. Assert that access settings are stored properly for each Access Level;
|
152 |
-
* B. Assert that access settings are merged properly and assigned to User Level;
|
153 |
-
*
|
154 |
-
* @return void
|
155 |
-
*
|
156 |
-
* @access public
|
157 |
-
* @version 6.0.0
|
158 |
-
*/
|
159 |
-
public function testFullInheritanceChainSingeRole()
|
160 |
-
{
|
161 |
-
$user = AAM::getUser();
|
162 |
-
$role = $user->getParent();
|
163 |
-
$default = $role->getParent();
|
164 |
-
|
165 |
-
$userMenu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
166 |
-
$roleMenu = $role->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
167 |
-
$defaultMenu = $default->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
168 |
-
|
169 |
-
// Save access settings for all subjects
|
170 |
-
$this->assertTrue($userMenu->updateOptionItem('update.php', true)->save());
|
171 |
-
$this->assertTrue($roleMenu->updateOptionItem('post.php?post_type=page', true)->save());
|
172 |
-
$this->assertTrue($defaultMenu->updateOptionItem('customize.php', true)->save());
|
173 |
-
|
174 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
175 |
-
$this->_resetSubjects();
|
176 |
-
|
177 |
-
// All settings has to be merged into one array
|
178 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
179 |
-
$this->assertSame(
|
180 |
-
array(
|
181 |
-
'customize.php' => true,
|
182 |
-
'post.php?post_type=page' => true,
|
183 |
-
'update.php' => true
|
184 |
-
),
|
185 |
-
$menu->getOption()
|
186 |
-
);
|
187 |
-
}
|
188 |
-
|
189 |
-
/**
|
190 |
-
* Test that access settings overwrite works as expected
|
191 |
-
*
|
192 |
-
* The expected result is lower Access Level overwrite access settings from the
|
193 |
-
* higher Access Level.
|
194 |
-
*
|
195 |
-
* A. Assert that access settings are stored properly for the parent role;
|
196 |
-
* B. Assert that access settings are stored properly for the specific user;
|
197 |
-
* C. Assert that access settings are overwritten properly on the User Level;
|
198 |
-
*
|
199 |
-
* @return void
|
200 |
-
*
|
201 |
-
* @access public
|
202 |
-
* @version 6.0.0
|
203 |
-
*/
|
204 |
-
public function testInheritanceOverrideForSingleRole()
|
205 |
-
{
|
206 |
-
$user = AAM::getUser();
|
207 |
-
$parent = $user->getParent();
|
208 |
-
|
209 |
-
$object = $parent->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
210 |
-
|
211 |
-
// Save access settings for the role and make sure they are saved property
|
212 |
-
// Check if save returns positive result
|
213 |
-
$this->assertTrue($object->updateOptionItem('update.php', true)->save());
|
214 |
-
|
215 |
-
// Save access setting for the user and make sure they are saved property
|
216 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE, null, true);
|
217 |
-
$this->assertTrue($menu->updateOptionItem('update.php', false)->save());
|
218 |
-
|
219 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
220 |
-
$this->_resetSubjects();
|
221 |
-
|
222 |
-
$menu = $user->getObject(AAM_Core_Object_Menu::OBJECT_TYPE);
|
223 |
-
$this->assertSame(array('update.php' => false), $menu->getOption());
|
224 |
-
}
|
225 |
-
|
226 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Capabilities/CapabilityManagerTest.php
DELETED
@@ -1,345 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Capability;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Subject_Role,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\AuthUserTrait,
|
16 |
-
AAM_Backend_Feature_Main_Capability;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test Capability manager features
|
20 |
-
*
|
21 |
-
* @version 6.0.0
|
22 |
-
*/
|
23 |
-
class CapabilityManagerTest extends TestCase
|
24 |
-
{
|
25 |
-
|
26 |
-
use AuthUserTrait;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Test if capabilities can be added properly for defined role
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testAssignCapabilityToRole()
|
37 |
-
{
|
38 |
-
global $wpdb;
|
39 |
-
|
40 |
-
$stub = $this->prepareRoleStub(
|
41 |
-
// Create a map of arguments to return values
|
42 |
-
array(
|
43 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
44 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, true),
|
45 |
-
),
|
46 |
-
// Subject callback
|
47 |
-
function() {
|
48 |
-
return new AAM_Core_Subject_Role('subscriber');
|
49 |
-
}
|
50 |
-
);
|
51 |
-
|
52 |
-
// Check if save returns positive result
|
53 |
-
$this->assertEquals(
|
54 |
-
$stub->save(), wp_json_encode(array('status' => 'success'))
|
55 |
-
);
|
56 |
-
|
57 |
-
// Verify that created capability actually is inside the user_roles option
|
58 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
59 |
-
|
60 |
-
$this->assertTrue(
|
61 |
-
array_key_exists('aam_test_cap_a', $option['subscriber']['capabilities'])
|
62 |
-
);
|
63 |
-
|
64 |
-
$this->assertTrue($option['subscriber']['capabilities']['aam_test_cap_a']);
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Test if capabilities can be added properly for the defined role and also
|
69 |
-
* current user
|
70 |
-
*
|
71 |
-
* @return void
|
72 |
-
*
|
73 |
-
* @access public
|
74 |
-
* @version 6.0.0
|
75 |
-
*/
|
76 |
-
public function testAssignCapabilityToRoleAndCurrentUser()
|
77 |
-
{
|
78 |
-
global $wpdb;
|
79 |
-
|
80 |
-
$stub = $this->prepareRoleStub(
|
81 |
-
// Create a map of arguments to return values
|
82 |
-
array(
|
83 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_c'),
|
84 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, true),
|
85 |
-
array('assignToMe', FILTER_VALIDATE_BOOLEAN, null, true)
|
86 |
-
),
|
87 |
-
// Subject callback
|
88 |
-
function() {
|
89 |
-
return new AAM_Core_Subject_Role('subscriber');
|
90 |
-
}
|
91 |
-
);
|
92 |
-
|
93 |
-
// Check if save returns positive result
|
94 |
-
$this->assertEquals(
|
95 |
-
$stub->save(), wp_json_encode(array('status' => 'success'))
|
96 |
-
);
|
97 |
-
|
98 |
-
// Verify that created capability actually is inside the user_roles option
|
99 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
100 |
-
|
101 |
-
$this->assertTrue(
|
102 |
-
array_key_exists('aam_test_cap_c', $option['subscriber']['capabilities'])
|
103 |
-
);
|
104 |
-
|
105 |
-
$this->assertTrue($option['subscriber']['capabilities']['aam_test_cap_c']);
|
106 |
-
|
107 |
-
$this->assertTrue(AAM::getUser()->hasCapability('aam_test_cap_c'));
|
108 |
-
|
109 |
-
// Clean-up after execution
|
110 |
-
AAM::getUser()->removeCapability('aam_test_cap_c');
|
111 |
-
$stub->delete();
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* Test if capabilities can be deprived properly for defined role
|
116 |
-
*
|
117 |
-
* @return void
|
118 |
-
*
|
119 |
-
* @access public
|
120 |
-
* @version 6.0.0
|
121 |
-
*/
|
122 |
-
public function testDepriveCapabilityToRole()
|
123 |
-
{
|
124 |
-
global $wpdb;
|
125 |
-
|
126 |
-
$stub = $this->prepareRoleStub(
|
127 |
-
// Create a map of arguments to return values
|
128 |
-
array(
|
129 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
130 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, false),
|
131 |
-
),
|
132 |
-
// Subject callback
|
133 |
-
function() {
|
134 |
-
return new AAM_Core_Subject_Role('subscriber');
|
135 |
-
}
|
136 |
-
);
|
137 |
-
|
138 |
-
// Check if save returns positive result
|
139 |
-
$this->assertEquals(
|
140 |
-
$stub->save(), wp_json_encode(array('status' => 'success'))
|
141 |
-
);
|
142 |
-
|
143 |
-
// Verify that created capability actually is inside the user_roles option
|
144 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
145 |
-
|
146 |
-
$this->assertTrue(
|
147 |
-
array_key_exists('aam_test_cap_a', $option['subscriber']['capabilities'])
|
148 |
-
);
|
149 |
-
|
150 |
-
$this->assertFalse($option['subscriber']['capabilities']['aam_test_cap_a']);
|
151 |
-
}
|
152 |
-
|
153 |
-
/**
|
154 |
-
* Test if capabilities can be deleted from the very specific role
|
155 |
-
*
|
156 |
-
* @return void
|
157 |
-
*
|
158 |
-
* @access public
|
159 |
-
* @version 6.0.0
|
160 |
-
*/
|
161 |
-
public function testCapabilityDeletionFromRole()
|
162 |
-
{
|
163 |
-
global $wpdb;
|
164 |
-
|
165 |
-
$stub = $this->prepareRoleStub(
|
166 |
-
// Create a map of arguments to return values
|
167 |
-
array(
|
168 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
169 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, true),
|
170 |
-
array('subjectOnly', FILTER_VALIDATE_BOOLEAN, null, true)
|
171 |
-
),
|
172 |
-
// Subject callback
|
173 |
-
function() {
|
174 |
-
return new AAM_Core_Subject_Role('subscriber');
|
175 |
-
}
|
176 |
-
);
|
177 |
-
|
178 |
-
// Insert the test capability before it'll be deleted
|
179 |
-
$stub->save();
|
180 |
-
|
181 |
-
// Delete the test capability from the subject
|
182 |
-
$this->assertEquals(
|
183 |
-
$stub->delete(), wp_json_encode(array('status' => 'success'))
|
184 |
-
);
|
185 |
-
|
186 |
-
// Confirm that deleted capability is no longer in the subscriber role
|
187 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
188 |
-
|
189 |
-
$this->assertFalse(
|
190 |
-
array_key_exists('aam_test_cap_a', $option['subscriber']['capabilities'])
|
191 |
-
);
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* Test if capabilities can be deleted from all roles
|
196 |
-
*
|
197 |
-
* @return void
|
198 |
-
*
|
199 |
-
* @access public
|
200 |
-
* @version 6.0.0
|
201 |
-
*/
|
202 |
-
public function testCapabilityDeletionFromAllRoles()
|
203 |
-
{
|
204 |
-
global $wpdb;
|
205 |
-
|
206 |
-
// Prepare and insert test capability for the "subscriber" editor
|
207 |
-
$stubA = $this->prepareRoleStub(
|
208 |
-
// Create a map of arguments to return values
|
209 |
-
array(
|
210 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
211 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, true),
|
212 |
-
array('subjectOnly', FILTER_VALIDATE_BOOLEAN, null, false)
|
213 |
-
),
|
214 |
-
// Subject callback
|
215 |
-
function() {
|
216 |
-
return new AAM_Core_Subject_Role('subscriber');
|
217 |
-
}
|
218 |
-
);
|
219 |
-
// Insert the test capability before it'll be deleted
|
220 |
-
$this->assertEquals(
|
221 |
-
$stubA->save(), wp_json_encode(array('status' => 'success'))
|
222 |
-
);
|
223 |
-
|
224 |
-
// Prepare and insert test capability for the "editor" role
|
225 |
-
$stubB = $this->prepareRoleStub(
|
226 |
-
// Create a map of arguments to return values
|
227 |
-
array(
|
228 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
229 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, true)
|
230 |
-
),
|
231 |
-
// Subject callback
|
232 |
-
function() {
|
233 |
-
return new AAM_Core_Subject_Role('editor');
|
234 |
-
}
|
235 |
-
);
|
236 |
-
// Insert the test capability before it'll be deleted
|
237 |
-
$this->assertEquals(
|
238 |
-
$stubB->save(), wp_json_encode(array('status' => 'success'))
|
239 |
-
);
|
240 |
-
|
241 |
-
// Delete the test capability from all roles
|
242 |
-
$this->assertEquals(
|
243 |
-
$stubA->delete(), wp_json_encode(array('status' => 'success'))
|
244 |
-
);
|
245 |
-
|
246 |
-
// Confirm that deleted capability is no longer in the subscriber & editor
|
247 |
-
// roles
|
248 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
249 |
-
|
250 |
-
$this->assertFalse(
|
251 |
-
array_key_exists('aam_test_cap_a', $option['subscriber']['capabilities'])
|
252 |
-
);
|
253 |
-
|
254 |
-
$this->assertFalse(
|
255 |
-
array_key_exists('aam_test_cap_a', $option['editor']['capabilities'])
|
256 |
-
);
|
257 |
-
}
|
258 |
-
|
259 |
-
/**
|
260 |
-
* Test if capabilities can be updated properly for the defined subject
|
261 |
-
*
|
262 |
-
* @return void
|
263 |
-
*
|
264 |
-
* @access public
|
265 |
-
* @version 6.0.0
|
266 |
-
*/
|
267 |
-
public function testUpdateCapability()
|
268 |
-
{
|
269 |
-
global $wpdb;
|
270 |
-
|
271 |
-
$stubA = $this->prepareRoleStub(
|
272 |
-
// Create a map of arguments to return values
|
273 |
-
array(
|
274 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
275 |
-
array('effect', FILTER_VALIDATE_BOOLEAN, null, false),
|
276 |
-
),
|
277 |
-
// Subject callback
|
278 |
-
function() {
|
279 |
-
return new AAM_Core_Subject_Role('subscriber');
|
280 |
-
}
|
281 |
-
);
|
282 |
-
|
283 |
-
// Check if save returns positive result
|
284 |
-
$this->assertEquals(
|
285 |
-
$stubA->save(), wp_json_encode(array('status' => 'success'))
|
286 |
-
);
|
287 |
-
|
288 |
-
// Create a new stub that will update the test capability
|
289 |
-
$stubB = $this->prepareRoleStub(
|
290 |
-
// Create a map of arguments to return values
|
291 |
-
array(
|
292 |
-
array('capability', FILTER_DEFAULT, null, 'aam_test_cap_a'),
|
293 |
-
array('updated', FILTER_DEFAULT, null, 'aam_test_cap_b')
|
294 |
-
),
|
295 |
-
// Subject callback
|
296 |
-
function() {
|
297 |
-
return new AAM_Core_Subject_Role('subscriber');
|
298 |
-
}
|
299 |
-
);
|
300 |
-
|
301 |
-
// Check if save returns positive result
|
302 |
-
$this->assertEquals(
|
303 |
-
$stubB->update(), wp_json_encode(array('status' => 'success'))
|
304 |
-
);
|
305 |
-
|
306 |
-
// Verify that capability actually is updated the user_roles option
|
307 |
-
$option = get_option(sprintf('%suser_roles', $wpdb->prefix));
|
308 |
-
|
309 |
-
$this->assertFalse(
|
310 |
-
array_key_exists('aam_test_cap_a', $option['subscriber']['capabilities'])
|
311 |
-
);
|
312 |
-
|
313 |
-
$this->assertTrue(
|
314 |
-
array_key_exists('aam_test_cap_b', $option['subscriber']['capabilities'])
|
315 |
-
);
|
316 |
-
|
317 |
-
$this->assertFalse($option['subscriber']['capabilities']['aam_test_cap_b']);
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Prepare proper subject stub
|
322 |
-
*
|
323 |
-
* @param array $paramMap
|
324 |
-
* @param callback $callback
|
325 |
-
*
|
326 |
-
* @return object
|
327 |
-
*
|
328 |
-
* @access protected
|
329 |
-
* @version 6.0.0
|
330 |
-
*/
|
331 |
-
protected function prepareRoleStub($paramMap, $callback)
|
332 |
-
{
|
333 |
-
// Create a stub for the SomeClass class.
|
334 |
-
$stub = $this->getMockBuilder(AAM_Backend_Feature_Main_Capability::class)
|
335 |
-
->setMethods(array('getFromPost', 'getSubject'))
|
336 |
-
->getMock();
|
337 |
-
|
338 |
-
// Configure the stub
|
339 |
-
$stub->method('getFromPost')->will($this->returnValueMap($paramMap));
|
340 |
-
$stub->method('getSubject')->will($this->returnCallback($callback));
|
341 |
-
|
342 |
-
return $stub;
|
343 |
-
}
|
344 |
-
|
345 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/Callback.php
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\Content;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const REDIRECT_URL = 'https://aamplugin.com/redirect';
|
8 |
-
|
9 |
-
public static function redirectCallback()
|
10 |
-
{
|
11 |
-
return self::REDIRECT_URL;
|
12 |
-
}
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/MultipleRoleInheritanceTest.php
DELETED
@@ -1,190 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Content;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM_Core_Object_Post,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthMultiRoleUserTrait,
|
18 |
-
AAM\UnitTest\Libs\MultiRoleOptionInterface;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test AAM access settings inheritance mechanism for multiple roles per user for
|
22 |
-
* the Content service
|
23 |
-
*
|
24 |
-
* @package AAM\UnitTest
|
25 |
-
* @version 6.0.0
|
26 |
-
*/
|
27 |
-
class MultipleRoleInheritanceTest extends TestCase implements MultiRoleOptionInterface
|
28 |
-
{
|
29 |
-
use ResetTrait,
|
30 |
-
AuthMultiRoleUserTrait;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Test that access settings are inherited from multiple parent roles
|
34 |
-
*
|
35 |
-
* This test is designed to verify that access settings are propagated property
|
36 |
-
* when there access settings defined for multiple parent roles.
|
37 |
-
*
|
38 |
-
* A. Test that settings can be stored for the parent roles;
|
39 |
-
* B. Test that access settings are propagated property to the User level
|
40 |
-
*
|
41 |
-
* @return void
|
42 |
-
*
|
43 |
-
* @access public
|
44 |
-
* @version 6.0.0
|
45 |
-
*/
|
46 |
-
public function testInheritanceMergeFromMultipleRoles()
|
47 |
-
{
|
48 |
-
$user = AAM::getUser();
|
49 |
-
$role = $user->getParent();
|
50 |
-
|
51 |
-
// Make sure that we have parent roles defined properly
|
52 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
53 |
-
|
54 |
-
// Save access settings for the base role and iterate over each sibling and
|
55 |
-
// add additional settings
|
56 |
-
$this->assertTrue(
|
57 |
-
$role->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true)->updateOptionItem(
|
58 |
-
'limited',
|
59 |
-
array(
|
60 |
-
'enabled' => true,
|
61 |
-
'threshold' => 1
|
62 |
-
)
|
63 |
-
)->save()
|
64 |
-
);
|
65 |
-
|
66 |
-
// Set the access settings for the next Sibling
|
67 |
-
$sibling = $role->getSiblings()[0];
|
68 |
-
|
69 |
-
$sibling->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true)->updateOptionItem(
|
70 |
-
'hidden',
|
71 |
-
false
|
72 |
-
)->save();
|
73 |
-
|
74 |
-
// Reset internal AAM cache
|
75 |
-
$this->_resetSubjects();
|
76 |
-
|
77 |
-
// Assert that we have both roles merged result is as following
|
78 |
-
// Array (
|
79 |
-
// limited => Array (
|
80 |
-
// enabled => true,
|
81 |
-
// threshold => 1
|
82 |
-
// ),
|
83 |
-
// hidden => false
|
84 |
-
// )
|
85 |
-
$object = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID);
|
86 |
-
|
87 |
-
$this->assertSame(
|
88 |
-
array(
|
89 |
-
'limited' => array(
|
90 |
-
'enabled' => true,
|
91 |
-
'threshold' => 1
|
92 |
-
),
|
93 |
-
'hidden' => false
|
94 |
-
),
|
95 |
-
$object->getOption()
|
96 |
-
);
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Test that access settings are merged with default "deny" preference correctly
|
101 |
-
*
|
102 |
-
* @return void
|
103 |
-
*
|
104 |
-
* @access public
|
105 |
-
* @version 6.0.0
|
106 |
-
*/
|
107 |
-
public function testInheritanceDenyPreferenceFromMultipleRoles()
|
108 |
-
{
|
109 |
-
$user = AAM::getUser();
|
110 |
-
$role = $user->getParent();
|
111 |
-
|
112 |
-
// Make sure that we have parent roles defined properly
|
113 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
114 |
-
|
115 |
-
// Save access settings for the base role and iterate over each sibling and
|
116 |
-
// add additional settings
|
117 |
-
$this->assertTrue(
|
118 |
-
$role->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true)->updateOptionItem(
|
119 |
-
'hidden', true
|
120 |
-
)->save()
|
121 |
-
);
|
122 |
-
|
123 |
-
// Set the access settings for the next Sibling
|
124 |
-
$sibling = $role->getSiblings()[0];
|
125 |
-
|
126 |
-
$sibling->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true)->updateOptionItem(
|
127 |
-
'hidden',
|
128 |
-
false
|
129 |
-
)->save();
|
130 |
-
|
131 |
-
// Reset internal AAM cache
|
132 |
-
$this->_resetSubjects();
|
133 |
-
|
134 |
-
// Assert that we have both roles merged result is as following
|
135 |
-
// Array (
|
136 |
-
// hidden => true
|
137 |
-
// )
|
138 |
-
$option = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID)->getOption();
|
139 |
-
$this->assertSame(array('hidden' => true), $option);
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Test that access settings are merged with default "deny" preference correctly
|
144 |
-
*
|
145 |
-
* In this test, the first role will have explicitly defined access settings that
|
146 |
-
* deny access, while the second role has no settings defined. This way the
|
147 |
-
* expected outcome should be access allowed.
|
148 |
-
*
|
149 |
-
* @return void
|
150 |
-
*
|
151 |
-
* @access public
|
152 |
-
* @version 6.0.0
|
153 |
-
*/
|
154 |
-
public function testInheritanceAllowPreferenceFromMultipleRoles()
|
155 |
-
{
|
156 |
-
$user = AAM::getUser();
|
157 |
-
$role = $user->getParent();
|
158 |
-
|
159 |
-
// Make sure that we have parent roles defined properly
|
160 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
161 |
-
|
162 |
-
// Save access settings for the base role and iterate over each sibling and
|
163 |
-
// add additional settings
|
164 |
-
$this->assertTrue(
|
165 |
-
$role->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true)->updateOptionItem(
|
166 |
-
'limited', array('enabled' => true, 'threshold' => 10)
|
167 |
-
)->save()
|
168 |
-
);
|
169 |
-
|
170 |
-
// Override the default "deny" precedence
|
171 |
-
AAM_Core_Config::set(
|
172 |
-
sprintf('core.settings.%s.merge.preference', AAM_Core_Object_Post::OBJECT_TYPE),
|
173 |
-
'allow'
|
174 |
-
);
|
175 |
-
|
176 |
-
// Reset internal AAM cache
|
177 |
-
$this->_resetSubjects();
|
178 |
-
|
179 |
-
// Assert that we have both roles merged result is as following
|
180 |
-
// Array (
|
181 |
-
// limited => Array (
|
182 |
-
// enabled => false,
|
183 |
-
// threshold => 10
|
184 |
-
// )
|
185 |
-
// )
|
186 |
-
$option = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID)->getOption();
|
187 |
-
$this->assertSame(array('limited' => array('enabled' => false, 'threshold' => 10)), $option);
|
188 |
-
}
|
189 |
-
|
190 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/RESTfulSingleRoleAccessControlTest.php
DELETED
@@ -1,579 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Content;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
WP_REST_Request,
|
14 |
-
AAM_Service_Content,
|
15 |
-
AAM_Core_Object_Post,
|
16 |
-
PHPUnit\Framework\TestCase,
|
17 |
-
AAM\UnitTest\Libs\ResetTrait,
|
18 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test that content access settings through the WP RESTful API
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class RESTfulSingleRoleAccessControlTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test that user is not allowed to access the post when access settings are set
|
33 |
-
* so on the User Level
|
34 |
-
*
|
35 |
-
* @return void
|
36 |
-
*
|
37 |
-
* @access public
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testRestrictedOption()
|
41 |
-
{
|
42 |
-
$user = AAM::getUser();
|
43 |
-
$object = $user->getObject(
|
44 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
45 |
-
);
|
46 |
-
|
47 |
-
// Check if save returns positive result
|
48 |
-
$this->assertTrue($object->updateOptionItem('restricted', true)->save());
|
49 |
-
|
50 |
-
// Reset all internal cache
|
51 |
-
$this->_resetSubjects();
|
52 |
-
|
53 |
-
$server = rest_get_server();
|
54 |
-
|
55 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
56 |
-
$request->set_param('context', 'view');
|
57 |
-
|
58 |
-
$data = $server->dispatch($request)->get_data();
|
59 |
-
|
60 |
-
$this->assertEquals('post_access_restricted', $data['code']);
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Test that user does not have the ability to see hidden post
|
65 |
-
*
|
66 |
-
* @return void
|
67 |
-
*
|
68 |
-
* @access public
|
69 |
-
* @version 6.0.0
|
70 |
-
*/
|
71 |
-
public function testHiddenOption()
|
72 |
-
{
|
73 |
-
$server = rest_get_server();
|
74 |
-
|
75 |
-
// Hide the post
|
76 |
-
$user = AAM::getUser();
|
77 |
-
$object = $user->getObject(
|
78 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
79 |
-
);
|
80 |
-
|
81 |
-
// Check if save returns positive result
|
82 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
83 |
-
|
84 |
-
// Reset all internal cache
|
85 |
-
$this->_resetSubjects();
|
86 |
-
|
87 |
-
// Verify that post is no longer in the list of posts
|
88 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts');
|
89 |
-
$request->set_param('context', 'view');
|
90 |
-
|
91 |
-
$data = $server->dispatch($request)->get_data();
|
92 |
-
|
93 |
-
// First, confirm that post is in the array of posts
|
94 |
-
$this->assertCount(0, array_filter($data, function($post) {
|
95 |
-
return $post['id'] === AAM_UNITTEST_POST_ID;
|
96 |
-
}));
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Test that content is limited with the Teaser message and enabled excerpt
|
101 |
-
* shortcode
|
102 |
-
*
|
103 |
-
* @return void
|
104 |
-
*
|
105 |
-
* @access public
|
106 |
-
* @version 6.0.0
|
107 |
-
*/
|
108 |
-
public function testTeaserMessageOption()
|
109 |
-
{
|
110 |
-
$user = AAM::getUser();
|
111 |
-
$object = $user->getObject(
|
112 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
113 |
-
);
|
114 |
-
|
115 |
-
// Check if save returns positive result
|
116 |
-
$this->assertTrue($object->updateOptionItem('teaser', array(
|
117 |
-
'enabled' => true,
|
118 |
-
'message' => 'Test teaser with [excerpt]'
|
119 |
-
))->save());
|
120 |
-
|
121 |
-
// Reset all internal cache
|
122 |
-
$this->_resetSubjects();
|
123 |
-
|
124 |
-
// Confirm that teaser message is returned instead of actual content
|
125 |
-
$server = rest_get_server();
|
126 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
127 |
-
$request->set_param('context', 'view');
|
128 |
-
|
129 |
-
$data = $server->dispatch($request)->get_data();
|
130 |
-
|
131 |
-
$this->assertSame(
|
132 |
-
$data['content']['rendered'], 'Test teaser with ' . $object->post_excerpt
|
133 |
-
);
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Test the LIMITED option
|
138 |
-
*
|
139 |
-
* @return void
|
140 |
-
*
|
141 |
-
* @access public
|
142 |
-
* @version 6.0.0
|
143 |
-
*/
|
144 |
-
public function testLimitedOption()
|
145 |
-
{
|
146 |
-
// Limit the post
|
147 |
-
$user = AAM::getUser();
|
148 |
-
$object = $user->getObject(
|
149 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
150 |
-
);
|
151 |
-
|
152 |
-
// Check if save returns positive result
|
153 |
-
$this->assertTrue($object->updateOptionItem('limited', array(
|
154 |
-
'enabled' => true,
|
155 |
-
'threshold' => 1
|
156 |
-
))->save());
|
157 |
-
|
158 |
-
// Faking the fact that user already seen this post once
|
159 |
-
update_user_meta(
|
160 |
-
AAM_UNITTEST_AUTH_USER_ID,
|
161 |
-
sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, AAM_UNITTEST_POST_ID),
|
162 |
-
1
|
163 |
-
);
|
164 |
-
|
165 |
-
// Reset all internal cache
|
166 |
-
$this->_resetSubjects();
|
167 |
-
|
168 |
-
$server = rest_get_server();
|
169 |
-
|
170 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
171 |
-
$request->set_param('context', 'view');
|
172 |
-
|
173 |
-
$data = $server->dispatch($request)->get_data();
|
174 |
-
|
175 |
-
$this->assertEquals('post_access_exceeded_limit', $data['code']);
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Test that view counter is incremented after each view
|
180 |
-
*
|
181 |
-
* @return void
|
182 |
-
*
|
183 |
-
* @access public
|
184 |
-
* @version 6.0.0
|
185 |
-
*/
|
186 |
-
public function testLimitedIncrementedCounterOption()
|
187 |
-
{
|
188 |
-
// Limit the post
|
189 |
-
$user = AAM::getUser();
|
190 |
-
$object = $user->getObject(
|
191 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
192 |
-
);
|
193 |
-
|
194 |
-
// Check if save returns positive result
|
195 |
-
$this->assertTrue($object->updateOptionItem('limited', array(
|
196 |
-
'enabled' => true,
|
197 |
-
'threshold' => 10
|
198 |
-
))->save());
|
199 |
-
|
200 |
-
// Tracking key
|
201 |
-
$key = sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, AAM_UNITTEST_POST_ID);
|
202 |
-
|
203 |
-
// Faking the fact that user already seen this post once
|
204 |
-
update_user_meta(AAM_UNITTEST_AUTH_USER_ID, $key, 1);
|
205 |
-
|
206 |
-
// Reset all internal cache
|
207 |
-
$this->_resetSubjects();
|
208 |
-
|
209 |
-
$server = rest_get_server();
|
210 |
-
|
211 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
212 |
-
$request->set_param('context', 'view');
|
213 |
-
|
214 |
-
$status = $server->dispatch($request)->get_status();
|
215 |
-
|
216 |
-
$this->assertEquals(200, $status);
|
217 |
-
$this->assertEquals(2, get_user_meta(AAM_UNITTEST_AUTH_USER_ID, $key, true));
|
218 |
-
}
|
219 |
-
|
220 |
-
/**
|
221 |
-
* Test that user does not have the ability to comment on a post
|
222 |
-
*
|
223 |
-
* @return void
|
224 |
-
*
|
225 |
-
* @access public
|
226 |
-
* @version 6.0.0
|
227 |
-
*/
|
228 |
-
public function testCommentingOption()
|
229 |
-
{
|
230 |
-
$user = AAM::getUser();
|
231 |
-
$object = $user->getObject(
|
232 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
233 |
-
);
|
234 |
-
|
235 |
-
// Verify that commenting for this feature is set as open
|
236 |
-
$this->assertEquals($object->comment_status, 'open');
|
237 |
-
|
238 |
-
// Check if save returns positive result
|
239 |
-
$this->assertTrue($object->updateOptionItem('comment', true)->save());
|
240 |
-
|
241 |
-
// Reset all internal cache
|
242 |
-
$this->_resetSubjects();
|
243 |
-
|
244 |
-
$server = rest_get_server();
|
245 |
-
|
246 |
-
$request = new WP_REST_Request('POST', '/wp/v2/comments');
|
247 |
-
$request->set_param('post', AAM_UNITTEST_POST_ID);
|
248 |
-
$request->set_param('content', 'Test comment');
|
249 |
-
|
250 |
-
$data = $server->dispatch($request)->get_data();
|
251 |
-
|
252 |
-
$this->assertEquals('rest_comment_closed', $data['code']);
|
253 |
-
}
|
254 |
-
|
255 |
-
/**
|
256 |
-
* Test that REDIRECTED to Existing Page option is working as expected
|
257 |
-
*
|
258 |
-
* @return void
|
259 |
-
*
|
260 |
-
* @access public
|
261 |
-
* @version 6.0.0
|
262 |
-
*/
|
263 |
-
public function testRedirectPageOption()
|
264 |
-
{
|
265 |
-
$user = AAM::getUser();
|
266 |
-
$object = $user->getObject(
|
267 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
268 |
-
);
|
269 |
-
|
270 |
-
// Check if save returns positive result
|
271 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
272 |
-
'enabled' => true,
|
273 |
-
'type' => 'page',
|
274 |
-
'destination' => AAM_UNITTEST_PAGE_ID,
|
275 |
-
'httpCode' => 301
|
276 |
-
))->save());
|
277 |
-
|
278 |
-
// Reset all internal cache
|
279 |
-
$this->_resetSubjects();
|
280 |
-
|
281 |
-
$server = rest_get_server();
|
282 |
-
|
283 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
284 |
-
$request->set_param('context', 'view');
|
285 |
-
|
286 |
-
$data = $server->dispatch($request)->get_data();
|
287 |
-
|
288 |
-
$this->assertEquals('post_access_redirected', $data['code']);
|
289 |
-
$this->assertEquals(get_page_link(AAM_UNITTEST_PAGE_ID), $data['location']);
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Test that REDIRECTED to URL option is working as expected
|
294 |
-
*
|
295 |
-
* @return void
|
296 |
-
*
|
297 |
-
* @access public
|
298 |
-
* @version 6.0.0
|
299 |
-
*/
|
300 |
-
public function testRedirectURLOption()
|
301 |
-
{
|
302 |
-
$user = AAM::getUser();
|
303 |
-
$object = $user->getObject(
|
304 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
305 |
-
);
|
306 |
-
|
307 |
-
// Check if save returns positive result
|
308 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
309 |
-
'enabled' => true,
|
310 |
-
'type' => 'url',
|
311 |
-
'destination' => 'https://aamplugin.com',
|
312 |
-
'httpCode' => 307
|
313 |
-
))->save());
|
314 |
-
|
315 |
-
// Reset all internal cache
|
316 |
-
$this->_resetSubjects();
|
317 |
-
|
318 |
-
$server = rest_get_server();
|
319 |
-
|
320 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
321 |
-
$request->set_param('context', 'view');
|
322 |
-
|
323 |
-
$data = $server->dispatch($request)->get_data();
|
324 |
-
|
325 |
-
$this->assertEquals('post_access_redirected', $data['code']);
|
326 |
-
$this->assertEquals('https://aamplugin.com', $data['location']);
|
327 |
-
}
|
328 |
-
|
329 |
-
/**
|
330 |
-
* Test that REDIRECTED to PHP Callback option is working as expected
|
331 |
-
*
|
332 |
-
* @return void
|
333 |
-
*
|
334 |
-
* @access public
|
335 |
-
* @version 6.0.0
|
336 |
-
*/
|
337 |
-
public function testRedirectCallbackOption()
|
338 |
-
{
|
339 |
-
$user = AAM::getUser();
|
340 |
-
$object = $user->getObject(
|
341 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
342 |
-
);
|
343 |
-
|
344 |
-
// Check if save returns positive result
|
345 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
346 |
-
'enabled' => true,
|
347 |
-
'type' => 'callback',
|
348 |
-
// WordPress core strips slashes, so we have to double slash all this
|
349 |
-
'destination' => 'AAM\\UnitTest\\Service\\Content\\Callback::redirectCallback',
|
350 |
-
'httpCode' => 310
|
351 |
-
))->save());
|
352 |
-
|
353 |
-
// Reset all internal cache
|
354 |
-
$this->_resetSubjects();
|
355 |
-
|
356 |
-
$server = rest_get_server();
|
357 |
-
|
358 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
359 |
-
$request->set_param('context', 'view');
|
360 |
-
|
361 |
-
$data = $server->dispatch($request)->get_data();
|
362 |
-
|
363 |
-
$this->assertEquals('post_access_redirected', $data['code']);
|
364 |
-
$this->assertEquals(Callback::REDIRECT_URL, $data['location']);
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* Test PASSWORD PROTECTED option when password is enforced by AAM and is valid
|
369 |
-
*
|
370 |
-
* @return void
|
371 |
-
*
|
372 |
-
* @access public
|
373 |
-
* @version 6.0.0
|
374 |
-
*/
|
375 |
-
public function testAAMEnforcedPasswordValidOption()
|
376 |
-
{
|
377 |
-
$user = AAM::getUser();
|
378 |
-
$object = $user->getObject(
|
379 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
380 |
-
);
|
381 |
-
|
382 |
-
// Check if save returns positive result
|
383 |
-
$this->assertTrue($object->updateOptionItem('protected', array(
|
384 |
-
'enabled' => true,
|
385 |
-
'password' => '123456'
|
386 |
-
))->save());
|
387 |
-
|
388 |
-
// Reset all internal cache
|
389 |
-
$this->_resetSubjects();
|
390 |
-
|
391 |
-
$server = rest_get_server();
|
392 |
-
|
393 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
394 |
-
$request->set_param('context', 'view');
|
395 |
-
$request->set_param('password', '123456');
|
396 |
-
|
397 |
-
$this->assertEquals(200, $server->dispatch($request)->get_status());
|
398 |
-
}
|
399 |
-
|
400 |
-
/**
|
401 |
-
* Test PASSWORD PROTECTED option when password is enforced by AAM and is invalid
|
402 |
-
*
|
403 |
-
* @return void
|
404 |
-
*
|
405 |
-
* @access public
|
406 |
-
* @version 6.0.0
|
407 |
-
*/
|
408 |
-
public function testAAMEnforcedPasswordInvalidOption()
|
409 |
-
{
|
410 |
-
$user = AAM::getUser();
|
411 |
-
$object = $user->getObject(
|
412 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
413 |
-
);
|
414 |
-
|
415 |
-
// Check if save returns positive result
|
416 |
-
$this->assertTrue($object->updateOptionItem('protected', array(
|
417 |
-
'enabled' => true,
|
418 |
-
'password' => '123456'
|
419 |
-
))->save());
|
420 |
-
|
421 |
-
// Reset all internal cache
|
422 |
-
$this->_resetSubjects();
|
423 |
-
|
424 |
-
$server = rest_get_server();
|
425 |
-
|
426 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
427 |
-
$request->set_param('context', 'view');
|
428 |
-
$request->set_param('password', 'abs');
|
429 |
-
|
430 |
-
$response = $server->dispatch($request);
|
431 |
-
|
432 |
-
$this->assertEquals(401, $response->get_status());
|
433 |
-
$this->assertEquals('post_access_protected', $response->get_data()['code']);
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* Test CEASED option
|
438 |
-
*
|
439 |
-
* @return void
|
440 |
-
*
|
441 |
-
* @access public
|
442 |
-
* @version 6.0.0
|
443 |
-
*/
|
444 |
-
public function testCeasedOption()
|
445 |
-
{
|
446 |
-
// Hide the post
|
447 |
-
$user = AAM::getUser();
|
448 |
-
$object = $user->getObject(
|
449 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
450 |
-
);
|
451 |
-
|
452 |
-
// Check if save returns positive result
|
453 |
-
$this->assertTrue($object->updateOptionItem('ceased', array(
|
454 |
-
'enabled' => true,
|
455 |
-
'after' => '08/01/2019, 4:37 pm'
|
456 |
-
))->save());
|
457 |
-
|
458 |
-
// Reset all internal cache
|
459 |
-
$this->_resetSubjects();
|
460 |
-
|
461 |
-
$server = rest_get_server();
|
462 |
-
|
463 |
-
$request = new WP_REST_Request('GET', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
464 |
-
$request->set_param('context', 'view');
|
465 |
-
|
466 |
-
$response = $server->dispatch($request);
|
467 |
-
|
468 |
-
$this->assertEquals(401, $response->get_status());
|
469 |
-
$this->assertEquals('post_access_expired', $response->get_data()['code']);
|
470 |
-
}
|
471 |
-
|
472 |
-
/**
|
473 |
-
* Test that user does not have the ability to edit a post
|
474 |
-
*
|
475 |
-
* @return void
|
476 |
-
*
|
477 |
-
* @access public
|
478 |
-
* @version 6.0.0
|
479 |
-
*/
|
480 |
-
public function testEditOption()
|
481 |
-
{
|
482 |
-
$user = AAM::getUser();
|
483 |
-
$object = $user->getObject(
|
484 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
485 |
-
);
|
486 |
-
|
487 |
-
// Verify that editing is allowed for a specific post
|
488 |
-
$this->assertTrue(current_user_can('edit_post', AAM_UNITTEST_POST_ID));
|
489 |
-
|
490 |
-
// Check if save returns positive result
|
491 |
-
$this->assertTrue($object->updateOptionItem('edit', true)->save());
|
492 |
-
|
493 |
-
// Reset all internal cache
|
494 |
-
$this->_resetSubjects();
|
495 |
-
|
496 |
-
$server = rest_get_server();
|
497 |
-
|
498 |
-
$request = new WP_REST_Request('POST', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
499 |
-
$request->set_param('content', 'Test');
|
500 |
-
|
501 |
-
$response = $server->dispatch($request);
|
502 |
-
|
503 |
-
$this->assertEquals(403, $response->get_status());
|
504 |
-
$this->assertEquals('rest_cannot_edit', $response->get_data()['code']);
|
505 |
-
}
|
506 |
-
|
507 |
-
/**
|
508 |
-
* Test that user does not have the ability to delete a post
|
509 |
-
*
|
510 |
-
* @return void
|
511 |
-
*
|
512 |
-
* @access public
|
513 |
-
* @version 6.0.0
|
514 |
-
*/
|
515 |
-
public function testDeleteOption()
|
516 |
-
{
|
517 |
-
$user = AAM::getUser();
|
518 |
-
$object = $user->getObject(
|
519 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
520 |
-
);
|
521 |
-
|
522 |
-
// Verify that deletion is allowed for a specific post
|
523 |
-
$this->assertTrue(current_user_can('delete_post', AAM_UNITTEST_POST_ID));
|
524 |
-
|
525 |
-
// Check if save returns positive result
|
526 |
-
$this->assertTrue($object->updateOptionItem('delete', true)->save());
|
527 |
-
|
528 |
-
// Reset all internal cache
|
529 |
-
$this->_resetSubjects();
|
530 |
-
|
531 |
-
$server = rest_get_server();
|
532 |
-
|
533 |
-
$request = new WP_REST_Request('DELETE', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
534 |
-
$response = $server->dispatch($request);
|
535 |
-
|
536 |
-
$this->assertEquals(403, $response->get_status());
|
537 |
-
$this->assertEquals('rest_cannot_delete', $response->get_data()['code']);
|
538 |
-
}
|
539 |
-
|
540 |
-
/**
|
541 |
-
* Test that user does not have the ability to publish a post
|
542 |
-
*
|
543 |
-
* @return void
|
544 |
-
*
|
545 |
-
* @access public
|
546 |
-
* @version 6.0.0
|
547 |
-
*/
|
548 |
-
public function testPublishOption()
|
549 |
-
{
|
550 |
-
global $post;
|
551 |
-
|
552 |
-
$user = AAM::getUser();
|
553 |
-
$object = $user->getObject(
|
554 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
555 |
-
);
|
556 |
-
|
557 |
-
// Force global post
|
558 |
-
$post = get_post(AAM_UNITTEST_POST_ID);
|
559 |
-
|
560 |
-
// Verify that publishing is allowed for a specific post
|
561 |
-
$this->assertTrue(current_user_can('publish_post', AAM_UNITTEST_POST_ID));
|
562 |
-
|
563 |
-
// Check if save returns positive result
|
564 |
-
$this->assertTrue($object->updateOptionItem('publish', true)->save());
|
565 |
-
|
566 |
-
// Reset all internal cache
|
567 |
-
$this->_resetSubjects();
|
568 |
-
|
569 |
-
$server = rest_get_server();
|
570 |
-
|
571 |
-
$request = new WP_REST_Request('POST', '/wp/v2/posts/' . AAM_UNITTEST_POST_ID);
|
572 |
-
$request->set_param('status', 'publish');
|
573 |
-
$response = $server->dispatch($request);
|
574 |
-
|
575 |
-
$this->assertEquals(403, $response->get_status());
|
576 |
-
$this->assertEquals('rest_cannot_publish', $response->get_data()['code']);
|
577 |
-
}
|
578 |
-
|
579 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/SingleRoleAccessControlTest.php
DELETED
@@ -1,602 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Content;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_API,
|
14 |
-
AAM_Service_Content,
|
15 |
-
AAM_Core_Object_Post,
|
16 |
-
PHPUnit\Framework\TestCase,
|
17 |
-
AAM\UnitTest\Libs\ResetTrait,
|
18 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test that content access settings are applied and used properly with WordPress core
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class SingleRoleAccessControlTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test that user is not allowed to access the post when access settings are set
|
33 |
-
* so on the User Level
|
34 |
-
*
|
35 |
-
* @return void
|
36 |
-
*
|
37 |
-
* @access public
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testRestrictedOption()
|
41 |
-
{
|
42 |
-
$user = AAM::getUser();
|
43 |
-
$object = $user->getObject(
|
44 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
45 |
-
);
|
46 |
-
|
47 |
-
// Check if save returns positive result
|
48 |
-
$this->assertTrue($object->updateOptionItem('restricted', true)->save());
|
49 |
-
|
50 |
-
// Reset all internal cache
|
51 |
-
$this->_resetSubjects();
|
52 |
-
|
53 |
-
$post = $user->getObject(
|
54 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
55 |
-
);
|
56 |
-
|
57 |
-
// Make sure that AAM API returns correct result
|
58 |
-
$this->assertTrue($post->is('restricted'));
|
59 |
-
|
60 |
-
// Check that current user is not allowed to read_post
|
61 |
-
$this->assertFalse(current_user_can('read_post', AAM_UNITTEST_POST_ID));
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Test that user does not have the ability to see hidden post
|
66 |
-
*
|
67 |
-
* @return void
|
68 |
-
*
|
69 |
-
* @access public
|
70 |
-
* @version 6.0.0
|
71 |
-
*/
|
72 |
-
public function testHiddenOption()
|
73 |
-
{
|
74 |
-
$posts = get_posts(array(
|
75 |
-
'post_type' => 'post',
|
76 |
-
'fields' => 'ids',
|
77 |
-
'suppress_filters' => false
|
78 |
-
));
|
79 |
-
|
80 |
-
// First, confirm that post is in the array of posts
|
81 |
-
$this->assertTrue(in_array(AAM_UNITTEST_POST_ID, $posts));
|
82 |
-
|
83 |
-
// Hide the post
|
84 |
-
$user = AAM::getUser();
|
85 |
-
$object = $user->getObject(
|
86 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
87 |
-
);
|
88 |
-
|
89 |
-
// Check if save returns positive result
|
90 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
91 |
-
|
92 |
-
// Reset all internal cache
|
93 |
-
$this->_resetSubjects();
|
94 |
-
|
95 |
-
// Verify that post is no longer in the list of posts
|
96 |
-
$posts = get_posts(array(
|
97 |
-
'post_type' => 'post',
|
98 |
-
'fields' => 'ids',
|
99 |
-
'suppress_filters' => false
|
100 |
-
));
|
101 |
-
|
102 |
-
// First, confirm that post is in the array of posts
|
103 |
-
$this->assertFalse(in_array(AAM_UNITTEST_POST_ID, $posts));
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Test that content is limited with the Teaser message and enabled excerpt
|
108 |
-
* shortcode
|
109 |
-
*
|
110 |
-
* @return void
|
111 |
-
*
|
112 |
-
* @access public
|
113 |
-
* @version 6.0.0
|
114 |
-
*/
|
115 |
-
public function testTeaserMessageOption()
|
116 |
-
{
|
117 |
-
$user = AAM::getUser();
|
118 |
-
$object = $user->getObject(
|
119 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
120 |
-
);
|
121 |
-
|
122 |
-
// Check if save returns positive result
|
123 |
-
$this->assertTrue($object->updateOptionItem('teaser', array(
|
124 |
-
'enabled' => true,
|
125 |
-
'message' => 'Test teaser with [excerpt]'
|
126 |
-
))->save());
|
127 |
-
|
128 |
-
// Reset all internal cache
|
129 |
-
$this->_resetSubjects();
|
130 |
-
|
131 |
-
// Confirm that teaser message is returned instead of actual content
|
132 |
-
$GLOBALS['post'] = AAM_UNITTEST_POST_ID;
|
133 |
-
ob_start();
|
134 |
-
the_content();
|
135 |
-
$this->assertSame(
|
136 |
-
ob_get_contents(), 'Test teaser with ' . $object->post_excerpt
|
137 |
-
);
|
138 |
-
ob_end_clean();
|
139 |
-
}
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Test the LIMITED option
|
143 |
-
*
|
144 |
-
* Forcing $wp_query to trigger AAM_Service_Content::wp
|
145 |
-
*
|
146 |
-
* @return void
|
147 |
-
*
|
148 |
-
* @access public
|
149 |
-
* @see AAM_Service_Content::wp
|
150 |
-
* @version 6.0.0
|
151 |
-
*/
|
152 |
-
public function testLimitedOption()
|
153 |
-
{
|
154 |
-
global $wp_query;
|
155 |
-
|
156 |
-
// Limit the post
|
157 |
-
$user = AAM::getUser();
|
158 |
-
$object = $user->getObject(
|
159 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
160 |
-
);
|
161 |
-
|
162 |
-
// Check if save returns positive result
|
163 |
-
$this->assertTrue($object->updateOptionItem('limited', array(
|
164 |
-
'enabled' => true,
|
165 |
-
'threshold' => 1
|
166 |
-
))->save());
|
167 |
-
|
168 |
-
// Faking the fact that user already seen this post once
|
169 |
-
update_user_meta(
|
170 |
-
AAM_UNITTEST_AUTH_USER_ID,
|
171 |
-
sprintf(AAM_Service_Content::POST_COUNTER_DB_OPTION, AAM_UNITTEST_POST_ID),
|
172 |
-
1
|
173 |
-
);
|
174 |
-
|
175 |
-
// Reset all internal cache
|
176 |
-
$this->_resetSubjects();
|
177 |
-
|
178 |
-
// Forcing WP_Query to the right path
|
179 |
-
$wp_query->is_single = true;
|
180 |
-
$GLOBALS['post'] = get_post(AAM_UNITTEST_POST_ID);
|
181 |
-
|
182 |
-
// Override the default handlers so we can suppress die exit
|
183 |
-
add_filter('wp_die_handler', function() {
|
184 |
-
return function($message, $title) {
|
185 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
186 |
-
};
|
187 |
-
}, PHP_INT_MAX);
|
188 |
-
|
189 |
-
// Capture the WP Die message
|
190 |
-
ob_start();
|
191 |
-
do_action('wp');
|
192 |
-
$content = ob_get_contents();
|
193 |
-
ob_end_clean();
|
194 |
-
|
195 |
-
$this->assertStringContainsString(
|
196 |
-
'User exceeded allowed access number. Access denied.', $content
|
197 |
-
);
|
198 |
-
|
199 |
-
// Reset WP Query
|
200 |
-
remove_all_filters('wp_die_handler', PHP_INT_MAX);
|
201 |
-
|
202 |
-
$wp_query->is_single = null;
|
203 |
-
unset($GLOBALS['post']);
|
204 |
-
}
|
205 |
-
|
206 |
-
/**
|
207 |
-
* Test that user does not have the ability to comment on a post
|
208 |
-
*
|
209 |
-
* @return void
|
210 |
-
*
|
211 |
-
* @access public
|
212 |
-
* @version 6.0.0
|
213 |
-
*/
|
214 |
-
public function testCommentingOption()
|
215 |
-
{
|
216 |
-
$user = AAM::getUser();
|
217 |
-
$object = $user->getObject(
|
218 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
219 |
-
);
|
220 |
-
|
221 |
-
// Verify that commenting for this feature is set as open
|
222 |
-
$this->assertEquals($object->comment_status, 'open');
|
223 |
-
|
224 |
-
// Check if save returns positive result
|
225 |
-
$this->assertTrue($object->updateOptionItem('comment', true)->save());
|
226 |
-
|
227 |
-
// Reset all internal cache
|
228 |
-
$this->_resetSubjects();
|
229 |
-
|
230 |
-
// First, confirm that post is in the array of posts
|
231 |
-
$this->assertFalse(comments_open(AAM_UNITTEST_POST_ID));
|
232 |
-
}
|
233 |
-
|
234 |
-
/**
|
235 |
-
* Test that REDIRECTED to Existing Page option is working as expected
|
236 |
-
*
|
237 |
-
* @return void
|
238 |
-
*
|
239 |
-
* @access public
|
240 |
-
* @version 6.0.0
|
241 |
-
*/
|
242 |
-
public function testRedirectPageOption()
|
243 |
-
{
|
244 |
-
$user = AAM::getUser();
|
245 |
-
$object = $user->getObject(
|
246 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
247 |
-
);
|
248 |
-
|
249 |
-
// Check if save returns positive result
|
250 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
251 |
-
'enabled' => true,
|
252 |
-
'type' => 'page',
|
253 |
-
'destination' => AAM_UNITTEST_PAGE_ID,
|
254 |
-
'httpCode' => 301
|
255 |
-
))->save());
|
256 |
-
|
257 |
-
// Reset all internal cache
|
258 |
-
$this->_resetSubjects();
|
259 |
-
|
260 |
-
$service = AAM_Service_Content::getInstance();
|
261 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
262 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
263 |
-
));
|
264 |
-
|
265 |
-
// Make sure that we have WP Error
|
266 |
-
$this->assertEquals(
|
267 |
-
$response->get_error_message(),
|
268 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
269 |
-
);
|
270 |
-
|
271 |
-
$this->assertEquals(array(
|
272 |
-
'location' => get_page_link(AAM_UNITTEST_PAGE_ID),
|
273 |
-
'status' => 301
|
274 |
-
), $response->get_error_data());
|
275 |
-
}
|
276 |
-
|
277 |
-
/**
|
278 |
-
* Test that REDIRECTED to URL option is working as expected
|
279 |
-
*
|
280 |
-
* @return void
|
281 |
-
*
|
282 |
-
* @access public
|
283 |
-
* @version 6.0.0
|
284 |
-
*/
|
285 |
-
public function testRedirectURLOption()
|
286 |
-
{
|
287 |
-
$user = AAM::getUser();
|
288 |
-
$object = $user->getObject(
|
289 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
290 |
-
);
|
291 |
-
|
292 |
-
// Check if save returns positive result
|
293 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
294 |
-
'enabled' => true,
|
295 |
-
'type' => 'url',
|
296 |
-
'destination' => 'https://aamplugin.com',
|
297 |
-
'httpCode' => 307
|
298 |
-
))->save());
|
299 |
-
|
300 |
-
// Reset all internal cache
|
301 |
-
$this->_resetSubjects();
|
302 |
-
|
303 |
-
$service = AAM_Service_Content::getInstance();
|
304 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
305 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
306 |
-
));
|
307 |
-
|
308 |
-
// Make sure that we have WP Error
|
309 |
-
$this->assertEquals(
|
310 |
-
$response->get_error_message(),
|
311 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
312 |
-
);
|
313 |
-
|
314 |
-
$this->assertEquals(array(
|
315 |
-
'location' => 'https://aamplugin.com',
|
316 |
-
'status' => 307
|
317 |
-
), $response->get_error_data());
|
318 |
-
}
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Test that REDIRECTED to PHP Callback option is working as expected
|
322 |
-
*
|
323 |
-
* @return void
|
324 |
-
*
|
325 |
-
* @access public
|
326 |
-
* @version 6.0.0
|
327 |
-
*/
|
328 |
-
public function testRedirectCallbackOption()
|
329 |
-
{
|
330 |
-
$user = AAM::getUser();
|
331 |
-
$object = $user->getObject(
|
332 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
333 |
-
);
|
334 |
-
|
335 |
-
// Check if save returns positive result
|
336 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
337 |
-
'enabled' => true,
|
338 |
-
'type' => 'callback',
|
339 |
-
// WordPress core strips slashes, so we have to double slash all this
|
340 |
-
'destination' => 'AAM\\UnitTest\\Service\\Content\\Callback::redirectCallback',
|
341 |
-
'httpCode' => 310
|
342 |
-
))->save());
|
343 |
-
|
344 |
-
// Reset all internal cache
|
345 |
-
$this->_resetSubjects();
|
346 |
-
|
347 |
-
$service = AAM_Service_Content::getInstance();
|
348 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
349 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
350 |
-
));
|
351 |
-
|
352 |
-
// Make sure that we have WP Error
|
353 |
-
$this->assertEquals(
|
354 |
-
$response->get_error_message(),
|
355 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
356 |
-
);
|
357 |
-
|
358 |
-
$this->assertEquals(array(
|
359 |
-
'location' => Callback::REDIRECT_URL,
|
360 |
-
'status' => 310
|
361 |
-
), $response->get_error_data());
|
362 |
-
}
|
363 |
-
|
364 |
-
/**
|
365 |
-
* Test PASSWORD PROTECTED option
|
366 |
-
*
|
367 |
-
* @return void
|
368 |
-
*
|
369 |
-
* @access public
|
370 |
-
* @version 6.0.0
|
371 |
-
*/
|
372 |
-
public function testProtectedOption()
|
373 |
-
{
|
374 |
-
$user = AAM::getUser();
|
375 |
-
$object = $user->getObject(
|
376 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
377 |
-
);
|
378 |
-
|
379 |
-
// Check if save returns positive result
|
380 |
-
$this->assertTrue($object->updateOptionItem('protected', array(
|
381 |
-
'enabled' => true,
|
382 |
-
'password' => '123456'
|
383 |
-
))->save());
|
384 |
-
|
385 |
-
// Reset all internal cache
|
386 |
-
$this->_resetSubjects();
|
387 |
-
|
388 |
-
// Get post
|
389 |
-
$post = $user->getObject(
|
390 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
391 |
-
);
|
392 |
-
|
393 |
-
// Verify that password is required
|
394 |
-
$this->assertTrue(
|
395 |
-
apply_filters('post_password_required', false, get_post(AAM_UNITTEST_POST_ID))
|
396 |
-
);
|
397 |
-
|
398 |
-
// Verify that password is not required when explicitly provided
|
399 |
-
$this->assertTrue(
|
400 |
-
AAM_Service_Content::getInstance()->checkPostPassword($post, '123456')
|
401 |
-
);
|
402 |
-
|
403 |
-
// Test that password is required when incorrect password is provided
|
404 |
-
$this->assertEquals(
|
405 |
-
'WP_Error',
|
406 |
-
get_class(AAM_Service_Content::getInstance()->checkPostPassword($post, '654321'))
|
407 |
-
);
|
408 |
-
}
|
409 |
-
|
410 |
-
/**
|
411 |
-
* Test PASSWORD PROTECTED option with passed cookie
|
412 |
-
*
|
413 |
-
* @return void
|
414 |
-
*
|
415 |
-
* @access public
|
416 |
-
* @version 6.0.0
|
417 |
-
*/
|
418 |
-
public function testProtectedWithCookieOption()
|
419 |
-
{
|
420 |
-
$user = AAM::getUser();
|
421 |
-
$object = $user->getObject(
|
422 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
423 |
-
);
|
424 |
-
|
425 |
-
// Check if save returns positive result
|
426 |
-
$this->assertTrue($object->updateOptionItem('protected', array(
|
427 |
-
'enabled' => true,
|
428 |
-
'password' => '123456'
|
429 |
-
))->save());
|
430 |
-
|
431 |
-
// Reset all internal cache
|
432 |
-
$this->_resetSubjects();
|
433 |
-
|
434 |
-
// Get post
|
435 |
-
$post = $user->getObject(
|
436 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
437 |
-
);
|
438 |
-
|
439 |
-
// Verify that password is required
|
440 |
-
$this->assertTrue(
|
441 |
-
apply_filters('post_password_required', false, get_post(AAM_UNITTEST_POST_ID))
|
442 |
-
);
|
443 |
-
|
444 |
-
// Generate cookie
|
445 |
-
$hasher = AAM_Core_API::prepareHasher();
|
446 |
-
$_COOKIE['wp-postpass_' . COOKIEHASH] = $hasher->HashPassword('123456');
|
447 |
-
|
448 |
-
// Verify that password is not required when explicitly provided
|
449 |
-
$this->assertTrue(
|
450 |
-
AAM_Service_Content::getInstance()->checkPostPassword($post)
|
451 |
-
);
|
452 |
-
|
453 |
-
// Test that password is required when incorrect password is provided
|
454 |
-
$_COOKIE['wp-postpass_' . COOKIEHASH] = $hasher->HashPassword('654321');
|
455 |
-
$this->assertEquals(
|
456 |
-
'WP_Error',
|
457 |
-
get_class(AAM_Service_Content::getInstance()->checkPostPassword($post))
|
458 |
-
);
|
459 |
-
|
460 |
-
// Reset
|
461 |
-
unset($_COOKIE['wp-postpass_' . COOKIEHASH]);
|
462 |
-
}
|
463 |
-
|
464 |
-
/**
|
465 |
-
* Test CEASED option
|
466 |
-
*
|
467 |
-
* @return void
|
468 |
-
*
|
469 |
-
* @access public
|
470 |
-
* @version 6.0.0
|
471 |
-
*/
|
472 |
-
public function testCeasedOption()
|
473 |
-
{
|
474 |
-
// Hide the post
|
475 |
-
$user = AAM::getUser();
|
476 |
-
$object = $user->getObject(
|
477 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
478 |
-
);
|
479 |
-
|
480 |
-
// Check if save returns positive result
|
481 |
-
$this->assertTrue($object->updateOptionItem('ceased', array(
|
482 |
-
'enabled' => true,
|
483 |
-
'after' => '08/01/2019, 4:37 pm'
|
484 |
-
))->save());
|
485 |
-
|
486 |
-
// Reset all internal cache
|
487 |
-
$this->_resetSubjects();
|
488 |
-
|
489 |
-
// Get post
|
490 |
-
$post = $user->getObject(
|
491 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
492 |
-
);
|
493 |
-
|
494 |
-
// Verify that access to the post is expired
|
495 |
-
$error = AAM_Service_Content::getInstance()->checkPostExpiration($post);
|
496 |
-
|
497 |
-
$this->assertEquals('WP_Error', get_class($error));
|
498 |
-
$this->assertEquals(
|
499 |
-
'User is unauthorized to access this post. Access Expired.',
|
500 |
-
$error->get_error_message()
|
501 |
-
);
|
502 |
-
|
503 |
-
// Test that password is required when incorrect password is provided
|
504 |
-
$this->assertEquals(
|
505 |
-
'WP_Error',
|
506 |
-
get_class(AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post))
|
507 |
-
);
|
508 |
-
}
|
509 |
-
|
510 |
-
/**
|
511 |
-
* Test that user does not have the ability to edit a post
|
512 |
-
*
|
513 |
-
* @return void
|
514 |
-
*
|
515 |
-
* @access public
|
516 |
-
* @version 6.0.0
|
517 |
-
*/
|
518 |
-
public function testEditOption()
|
519 |
-
{
|
520 |
-
$user = AAM::getUser();
|
521 |
-
$object = $user->getObject(
|
522 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
523 |
-
);
|
524 |
-
|
525 |
-
// Verify that editing is allowed for a specific post
|
526 |
-
$this->assertTrue(current_user_can('edit_post', AAM_UNITTEST_POST_ID));
|
527 |
-
|
528 |
-
// Check if save returns positive result
|
529 |
-
$this->assertTrue($object->updateOptionItem('edit', true)->save());
|
530 |
-
|
531 |
-
// Reset all internal cache
|
532 |
-
$this->_resetSubjects();
|
533 |
-
|
534 |
-
// Verify that user is no longer allowed to edit a post
|
535 |
-
$this->assertFalse(current_user_can('edit_post', AAM_UNITTEST_POST_ID));
|
536 |
-
}
|
537 |
-
|
538 |
-
/**
|
539 |
-
* Test that user does not have the ability to delete a post
|
540 |
-
*
|
541 |
-
* @return void
|
542 |
-
*
|
543 |
-
* @access public
|
544 |
-
* @version 6.0.0
|
545 |
-
*/
|
546 |
-
public function testDeleteOption()
|
547 |
-
{
|
548 |
-
$user = AAM::getUser();
|
549 |
-
$object = $user->getObject(
|
550 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
551 |
-
);
|
552 |
-
|
553 |
-
// Verify that deletion is allowed for a specific post
|
554 |
-
$this->assertTrue(current_user_can('delete_post', AAM_UNITTEST_POST_ID));
|
555 |
-
|
556 |
-
// Check if save returns positive result
|
557 |
-
$this->assertTrue($object->updateOptionItem('delete', true)->save());
|
558 |
-
|
559 |
-
// Reset all internal cache
|
560 |
-
$this->_resetSubjects();
|
561 |
-
|
562 |
-
// Verify that user is no longer allowed to delete a post
|
563 |
-
$this->assertFalse(current_user_can('delete_post', AAM_UNITTEST_POST_ID));
|
564 |
-
}
|
565 |
-
|
566 |
-
/**
|
567 |
-
* Test that user does not have the ability to publish a post
|
568 |
-
*
|
569 |
-
* @return void
|
570 |
-
*
|
571 |
-
* @access public
|
572 |
-
* @version 6.0.0
|
573 |
-
*/
|
574 |
-
public function testPublishOption()
|
575 |
-
{
|
576 |
-
global $post;
|
577 |
-
|
578 |
-
$user = AAM::getUser();
|
579 |
-
$object = $user->getObject(
|
580 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
581 |
-
);
|
582 |
-
|
583 |
-
// Force global post
|
584 |
-
$post = get_post(AAM_UNITTEST_POST_ID);
|
585 |
-
|
586 |
-
// Verify that publishing is allowed for a specific post
|
587 |
-
$this->assertTrue(current_user_can('publish_post', AAM_UNITTEST_POST_ID));
|
588 |
-
|
589 |
-
// Check if save returns positive result
|
590 |
-
$this->assertTrue($object->updateOptionItem('publish', true)->save());
|
591 |
-
|
592 |
-
// Reset all internal cache
|
593 |
-
$this->_resetSubjects();
|
594 |
-
|
595 |
-
// Verify that user is no longer allowed to publish a post
|
596 |
-
$this->assertFalse(current_user_can('publish_post', AAM_UNITTEST_POST_ID));
|
597 |
-
|
598 |
-
// Reset to default the global state
|
599 |
-
unset($post);
|
600 |
-
}
|
601 |
-
|
602 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/SingleRoleInheritanceTest.php
DELETED
@@ -1,221 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Content;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Post,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM access settings inheritance mechanism for the Content (Posts & Terms)
|
20 |
-
* service
|
21 |
-
*
|
22 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
23 |
-
* @version 6.0.0
|
24 |
-
*/
|
25 |
-
class SingleRoleInheritanceTest extends TestCase
|
26 |
-
{
|
27 |
-
use ResetTrait,
|
28 |
-
AuthUserTrait;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Test to insure that access settings are stored property on the User level
|
32 |
-
*
|
33 |
-
* @return void
|
34 |
-
*
|
35 |
-
* @access public
|
36 |
-
* @version 6.0.0
|
37 |
-
*/
|
38 |
-
public function testSaveUserLevelOption()
|
39 |
-
{
|
40 |
-
$user = AAM::getUser();
|
41 |
-
$object = $user->getObject(
|
42 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
43 |
-
);
|
44 |
-
|
45 |
-
// Check if save returns positive result
|
46 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
47 |
-
|
48 |
-
// Read from the database saved values and assert that we have
|
49 |
-
// Array (
|
50 |
-
// hidden => true
|
51 |
-
// )
|
52 |
-
$option = $user->readOption(
|
53 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID . '|post'
|
54 |
-
);
|
55 |
-
|
56 |
-
$this->assertSame(array('hidden' => true), $option);
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Test that access settings are inherited from the parent role property
|
61 |
-
*
|
62 |
-
* This test is designed to verify that access settings are propagated property
|
63 |
-
* when there is only one role assigned to a user.
|
64 |
-
*
|
65 |
-
* @return void
|
66 |
-
*
|
67 |
-
* @access public
|
68 |
-
* @version 6.0.0
|
69 |
-
*/
|
70 |
-
public function testInheritanceFromSingleRole()
|
71 |
-
{
|
72 |
-
$user = AAM::getUser();
|
73 |
-
$parent = $user->getParent();
|
74 |
-
$object = $parent->getObject(
|
75 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
76 |
-
);
|
77 |
-
|
78 |
-
// Make sure that we have parent role defined
|
79 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($parent));
|
80 |
-
|
81 |
-
// Save access settings for the role and make sure they are saved property
|
82 |
-
// Check if save returns positive result
|
83 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
84 |
-
|
85 |
-
// Read from the database saved values and assert that we have
|
86 |
-
// Array (
|
87 |
-
// hidden => true
|
88 |
-
// )
|
89 |
-
$option = $parent->readOption(
|
90 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID . '|post'
|
91 |
-
);
|
92 |
-
$this->assertSame(array('hidden' => true), $option);
|
93 |
-
|
94 |
-
// Finally verify that access settings are propagated property to the User
|
95 |
-
// Level
|
96 |
-
$post = $user->getObject(
|
97 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
98 |
-
);
|
99 |
-
$this->assertSame(array('hidden' => true), $post->getOption());
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Test that access settings are propagated and merged properly
|
104 |
-
*
|
105 |
-
* The test is designed to verify that access settings are propagated properly
|
106 |
-
* from the parent role and merged well with explicitly defined access settings on
|
107 |
-
* the User level.
|
108 |
-
*
|
109 |
-
* The expected result is to have combined array of access settings from the parent
|
110 |
-
* role and specific user.
|
111 |
-
*
|
112 |
-
* @return void
|
113 |
-
*
|
114 |
-
* @access public
|
115 |
-
* @version 6.0.0
|
116 |
-
*/
|
117 |
-
public function testInheritanceMergeFromSingleRole()
|
118 |
-
{
|
119 |
-
$user = AAM::getUser();
|
120 |
-
$parent = $user->getParent();
|
121 |
-
$object = $parent->getObject(
|
122 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
123 |
-
);
|
124 |
-
|
125 |
-
// Save access settings for the role and make sure they are saved property
|
126 |
-
// Check if save returns positive result
|
127 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
128 |
-
|
129 |
-
// Save access setting for the user and make sure they are saved property
|
130 |
-
$post = $user->getObject(
|
131 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true
|
132 |
-
);
|
133 |
-
$this->assertTrue($post->updateOptionItem('comment', false)->save());
|
134 |
-
|
135 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
136 |
-
$this->_resetSubjects();
|
137 |
-
|
138 |
-
$post = $user->getObject(
|
139 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
140 |
-
);
|
141 |
-
$this->assertSame(
|
142 |
-
array('hidden' => true, 'comment' => false),
|
143 |
-
$post->getOption()
|
144 |
-
);
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Test that the full inheritance mechanism is working as expected
|
149 |
-
*
|
150 |
-
* Make sure that access settings are propagated and merged properly from the top
|
151 |
-
* (Default Level) to the bottom (User Level).
|
152 |
-
*
|
153 |
-
* @return void
|
154 |
-
*
|
155 |
-
* @access public
|
156 |
-
* @version 6.0.0
|
157 |
-
*/
|
158 |
-
public function testFullInheritanceChainSingeRole()
|
159 |
-
{
|
160 |
-
$user = AAM::getUser();
|
161 |
-
$role = $user->getParent();
|
162 |
-
$default = $role->getParent();
|
163 |
-
|
164 |
-
$userPost = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true);
|
165 |
-
$rolePost = $role->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true);
|
166 |
-
$defaultPost = $default->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true);
|
167 |
-
|
168 |
-
// Save access settings for all subjects
|
169 |
-
$this->assertTrue($userPost->updateOptionItem('hidden', true)->save());
|
170 |
-
$this->assertTrue($rolePost->updateOptionItem('comment', true)->save());
|
171 |
-
$this->assertTrue($defaultPost->updateOptionItem('restricted', true)->save());
|
172 |
-
|
173 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
174 |
-
$this->_resetSubjects();
|
175 |
-
|
176 |
-
// All settings has to be merged into one array
|
177 |
-
$post = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID);
|
178 |
-
$this->assertSame(
|
179 |
-
array(
|
180 |
-
'restricted' => true,
|
181 |
-
'comment' => true,
|
182 |
-
'hidden' => true
|
183 |
-
),
|
184 |
-
$post->getOption()
|
185 |
-
);
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Test that access settings overwrite works as expected
|
190 |
-
*
|
191 |
-
* The expected result is lower Access Level overwrite access settings from the
|
192 |
-
* higher Access Level.
|
193 |
-
*
|
194 |
-
* @return void
|
195 |
-
*
|
196 |
-
* @access public
|
197 |
-
* @version 6.0.0
|
198 |
-
*/
|
199 |
-
public function testInheritanceOverrideForSingleRole()
|
200 |
-
{
|
201 |
-
$user = AAM::getUser();
|
202 |
-
$parent = $user->getParent();
|
203 |
-
|
204 |
-
$object = $parent->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID);
|
205 |
-
|
206 |
-
// Save access settings for the role and make sure they are saved property
|
207 |
-
// Check if save returns positive result
|
208 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
209 |
-
|
210 |
-
// Save access setting for the user and make sure they are saved property
|
211 |
-
$post = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID, true);
|
212 |
-
$this->assertTrue($post->updateOptionItem('hidden', false)->save());
|
213 |
-
|
214 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
215 |
-
$this->_resetSubjects();
|
216 |
-
|
217 |
-
$post = $user->getObject(AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID);
|
218 |
-
$this->assertSame(array('hidden' => false), $post->getOption());
|
219 |
-
}
|
220 |
-
|
221 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Content/VisitorAccessControlTest.php
DELETED
@@ -1,432 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Content;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_API,
|
14 |
-
AAM_Service_Content,
|
15 |
-
AAM_Core_Object_Post,
|
16 |
-
PHPUnit\Framework\TestCase,
|
17 |
-
AAM\UnitTest\Libs\ResetTrait;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Test that content access settings are applied and used properly with WordPress core
|
21 |
-
* for the unauthorized user
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class VisitorAccessControlTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Test that visitor is not allowed to access the post when access settings
|
32 |
-
* are set so on the Visitor Level
|
33 |
-
*
|
34 |
-
* @return void
|
35 |
-
*
|
36 |
-
* @access public
|
37 |
-
* @version 6.0.0
|
38 |
-
*/
|
39 |
-
public function testRestrictedOption()
|
40 |
-
{
|
41 |
-
$user = AAM::getUser();
|
42 |
-
$object = $user->getObject(
|
43 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
44 |
-
);
|
45 |
-
|
46 |
-
// Check if save returns positive result
|
47 |
-
$this->assertTrue($object->updateOptionItem('restricted', true)->save());
|
48 |
-
|
49 |
-
// Reset all internal cache
|
50 |
-
$this->_resetSubjects();
|
51 |
-
|
52 |
-
$post = $user->getObject(
|
53 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
54 |
-
);
|
55 |
-
|
56 |
-
// Make sure that AAM API returns correct result
|
57 |
-
$this->assertTrue($post->is('restricted'));
|
58 |
-
|
59 |
-
// Check that current user is not allowed to read_post
|
60 |
-
$this->assertFalse(current_user_can('read_post', AAM_UNITTEST_POST_ID));
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Test that visitor does not have the ability to see hidden post
|
65 |
-
*
|
66 |
-
* @return void
|
67 |
-
*
|
68 |
-
* @access public
|
69 |
-
* @version 6.0.0
|
70 |
-
*/
|
71 |
-
public function testHiddenOption()
|
72 |
-
{
|
73 |
-
$posts = get_posts(array(
|
74 |
-
'post_type' => 'post',
|
75 |
-
'fields' => 'ids',
|
76 |
-
'suppress_filters' => false
|
77 |
-
));
|
78 |
-
|
79 |
-
// First, confirm that post is in the array of posts
|
80 |
-
$this->assertTrue(in_array(AAM_UNITTEST_POST_ID, $posts));
|
81 |
-
|
82 |
-
// Hide the post
|
83 |
-
$user = AAM::getUser();
|
84 |
-
$object = $user->getObject(
|
85 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
86 |
-
);
|
87 |
-
|
88 |
-
// Check if save returns positive result
|
89 |
-
$this->assertTrue($object->updateOptionItem('hidden', true)->save());
|
90 |
-
|
91 |
-
// Reset all internal cache
|
92 |
-
$this->_resetSubjects();
|
93 |
-
|
94 |
-
// Verify that post is no longer in the list of posts
|
95 |
-
$posts = get_posts(array(
|
96 |
-
'post_type' => 'post',
|
97 |
-
'fields' => 'ids',
|
98 |
-
'suppress_filters' => false
|
99 |
-
));
|
100 |
-
|
101 |
-
// First, confirm that post is in the array of posts
|
102 |
-
$this->assertFalse(in_array(AAM_UNITTEST_POST_ID, $posts));
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Test that content is limited with the Teaser message and enabled excerpt
|
107 |
-
* shortcode
|
108 |
-
*
|
109 |
-
* @return void
|
110 |
-
*
|
111 |
-
* @access public
|
112 |
-
* @version 6.0.0
|
113 |
-
*/
|
114 |
-
public function testTeaserMessageOption()
|
115 |
-
{
|
116 |
-
$user = AAM::getUser();
|
117 |
-
$object = $user->getObject(
|
118 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
119 |
-
);
|
120 |
-
|
121 |
-
// Check if save returns positive result
|
122 |
-
$this->assertTrue($object->updateOptionItem('teaser', array(
|
123 |
-
'enabled' => true,
|
124 |
-
'message' => 'Test teaser with [excerpt]'
|
125 |
-
))->save());
|
126 |
-
|
127 |
-
// Reset all internal cache
|
128 |
-
$this->_resetSubjects();
|
129 |
-
|
130 |
-
// Confirm that teaser message is returned instead of actual content
|
131 |
-
$GLOBALS['post'] = AAM_UNITTEST_POST_ID;
|
132 |
-
ob_start();
|
133 |
-
the_content();
|
134 |
-
$this->assertSame(
|
135 |
-
ob_get_contents(), 'Test teaser with ' . $object->post_excerpt
|
136 |
-
);
|
137 |
-
ob_end_clean();
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Test that visitor does not have the ability to comment on a post
|
142 |
-
*
|
143 |
-
* @return void
|
144 |
-
*
|
145 |
-
* @access public
|
146 |
-
* @version 6.0.0
|
147 |
-
*/
|
148 |
-
public function testCommentingOption()
|
149 |
-
{
|
150 |
-
$user = AAM::getUser();
|
151 |
-
$object = $user->getObject(
|
152 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
153 |
-
);
|
154 |
-
|
155 |
-
// Verify that commenting for this feature is set as open
|
156 |
-
$this->assertEquals($object->comment_status, 'open');
|
157 |
-
|
158 |
-
// Check if save returns positive result
|
159 |
-
$this->assertTrue($object->updateOptionItem('comment', true)->save());
|
160 |
-
|
161 |
-
// Reset all internal cache
|
162 |
-
$this->_resetSubjects();
|
163 |
-
|
164 |
-
// First, confirm that post is in the array of posts
|
165 |
-
$this->assertFalse(comments_open(AAM_UNITTEST_POST_ID));
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Test that REDIRECTED to Existing Page option is working as expected
|
170 |
-
*
|
171 |
-
* @return void
|
172 |
-
*
|
173 |
-
* @access public
|
174 |
-
* @version 6.0.0
|
175 |
-
*/
|
176 |
-
public function testRedirectPageOption()
|
177 |
-
{
|
178 |
-
$user = AAM::getUser();
|
179 |
-
$object = $user->getObject(
|
180 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
181 |
-
);
|
182 |
-
|
183 |
-
// Check if save returns positive result
|
184 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
185 |
-
'enabled' => true,
|
186 |
-
'type' => 'page',
|
187 |
-
'destination' => AAM_UNITTEST_PAGE_ID,
|
188 |
-
'httpCode' => 301
|
189 |
-
))->save());
|
190 |
-
|
191 |
-
// Reset all internal cache
|
192 |
-
$this->_resetSubjects();
|
193 |
-
|
194 |
-
$service = AAM_Service_Content::getInstance();
|
195 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
196 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
197 |
-
));
|
198 |
-
|
199 |
-
// Make sure that we have WP Error
|
200 |
-
$this->assertEquals(
|
201 |
-
$response->get_error_message(),
|
202 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
203 |
-
);
|
204 |
-
|
205 |
-
$this->assertEquals(array(
|
206 |
-
'location' => get_page_link(AAM_UNITTEST_PAGE_ID),
|
207 |
-
'status' => 301
|
208 |
-
), $response->get_error_data());
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Test that REDIRECTED to URL option is working as expected
|
213 |
-
*
|
214 |
-
* @return void
|
215 |
-
*
|
216 |
-
* @access public
|
217 |
-
* @version 6.0.0
|
218 |
-
*/
|
219 |
-
public function testRedirectURLOption()
|
220 |
-
{
|
221 |
-
$user = AAM::getUser();
|
222 |
-
$object = $user->getObject(
|
223 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
224 |
-
);
|
225 |
-
|
226 |
-
// Check if save returns positive result
|
227 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
228 |
-
'enabled' => true,
|
229 |
-
'type' => 'url',
|
230 |
-
'destination' => 'https://aamplugin.com',
|
231 |
-
'httpCode' => 307
|
232 |
-
))->save());
|
233 |
-
|
234 |
-
// Reset all internal cache
|
235 |
-
$this->_resetSubjects();
|
236 |
-
|
237 |
-
$service = AAM_Service_Content::getInstance();
|
238 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
239 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
240 |
-
));
|
241 |
-
|
242 |
-
// Make sure that we have WP Error
|
243 |
-
$this->assertEquals(
|
244 |
-
$response->get_error_message(),
|
245 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
246 |
-
);
|
247 |
-
|
248 |
-
$this->assertEquals(array(
|
249 |
-
'location' => 'https://aamplugin.com',
|
250 |
-
'status' => 307
|
251 |
-
), $response->get_error_data());
|
252 |
-
}
|
253 |
-
|
254 |
-
/**
|
255 |
-
* Test that REDIRECTED to PHP Callback option is working as expected
|
256 |
-
*
|
257 |
-
* @return void
|
258 |
-
*
|
259 |
-
* @access public
|
260 |
-
* @version 6.0.0
|
261 |
-
*/
|
262 |
-
public function testRedirectCallbackOption()
|
263 |
-
{
|
264 |
-
$user = AAM::getUser();
|
265 |
-
$object = $user->getObject(
|
266 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
267 |
-
);
|
268 |
-
|
269 |
-
// Check if save returns positive result
|
270 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
271 |
-
'enabled' => true,
|
272 |
-
'type' => 'callback',
|
273 |
-
// WordPress core strips slashes, so we have to double slash all this
|
274 |
-
'destination' => 'AAM\\UnitTest\\Service\\Content\\Callback::redirectCallback',
|
275 |
-
'httpCode' => 310
|
276 |
-
))->save());
|
277 |
-
|
278 |
-
// Reset all internal cache
|
279 |
-
$this->_resetSubjects();
|
280 |
-
|
281 |
-
$service = AAM_Service_Content::getInstance();
|
282 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
283 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
284 |
-
));
|
285 |
-
|
286 |
-
// Make sure that we have WP Error
|
287 |
-
$this->assertEquals(
|
288 |
-
$response->get_error_message(),
|
289 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
290 |
-
);
|
291 |
-
|
292 |
-
$this->assertEquals(array(
|
293 |
-
'location' => Callback::REDIRECT_URL,
|
294 |
-
'status' => 310
|
295 |
-
), $response->get_error_data());
|
296 |
-
}
|
297 |
-
|
298 |
-
/**
|
299 |
-
* Test that REDIRECTED to Login Page option is working as expected
|
300 |
-
*
|
301 |
-
* @return void
|
302 |
-
*
|
303 |
-
* @access public
|
304 |
-
* @version 6.0.0
|
305 |
-
*/
|
306 |
-
public function testRedirectLoginOption()
|
307 |
-
{
|
308 |
-
$user = AAM::getUser();
|
309 |
-
$object = $user->getObject(
|
310 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
311 |
-
);
|
312 |
-
|
313 |
-
// Check if save returns positive result
|
314 |
-
$this->assertTrue($object->updateOptionItem('redirected', array(
|
315 |
-
'enabled' => true,
|
316 |
-
'type' => 'login',
|
317 |
-
'httpCode' => 301
|
318 |
-
))->save());
|
319 |
-
|
320 |
-
// Reset all internal cache
|
321 |
-
$this->_resetSubjects();
|
322 |
-
|
323 |
-
$service = AAM_Service_Content::getInstance();
|
324 |
-
$response = $service->isAuthorizedToReadPost($user->getObject(
|
325 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
326 |
-
));
|
327 |
-
|
328 |
-
// Make sure that we have WP Error
|
329 |
-
$this->assertEquals(
|
330 |
-
$response->get_error_message(),
|
331 |
-
'Direct access is not allowed. Follow the provided redirect rule.'
|
332 |
-
);
|
333 |
-
|
334 |
-
$this->assertEquals(array(
|
335 |
-
'location' => wp_login_url() . '?reason=restricted',
|
336 |
-
'status' => 301
|
337 |
-
), $response->get_error_data());
|
338 |
-
}
|
339 |
-
|
340 |
-
/**
|
341 |
-
* Test PASSWORD PROTECTED option
|
342 |
-
*
|
343 |
-
* @return void
|
344 |
-
*
|
345 |
-
* @access public
|
346 |
-
* @version 6.0.0
|
347 |
-
*/
|
348 |
-
public function testProtectedOption()
|
349 |
-
{
|
350 |
-
$user = AAM::getUser();
|
351 |
-
$object = $user->getObject(
|
352 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
353 |
-
);
|
354 |
-
|
355 |
-
// Check if save returns positive result
|
356 |
-
$this->assertTrue($object->updateOptionItem('protected', array(
|
357 |
-
'enabled' => true,
|
358 |
-
'password' => '123456'
|
359 |
-
))->save());
|
360 |
-
|
361 |
-
// Reset all internal cache
|
362 |
-
$this->_resetSubjects();
|
363 |
-
|
364 |
-
// Get post
|
365 |
-
$post = $user->getObject(
|
366 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
367 |
-
);
|
368 |
-
|
369 |
-
// Verify that password is required
|
370 |
-
$this->assertTrue(
|
371 |
-
apply_filters('post_password_required', false, get_post(AAM_UNITTEST_POST_ID))
|
372 |
-
);
|
373 |
-
|
374 |
-
// Verify that password is not required when explicitly provided
|
375 |
-
$this->assertTrue(
|
376 |
-
AAM_Service_Content::getInstance()->checkPostPassword($post, '123456')
|
377 |
-
);
|
378 |
-
|
379 |
-
// Test that password is required when incorrect password is provided
|
380 |
-
$this->assertEquals(
|
381 |
-
'WP_Error',
|
382 |
-
get_class(AAM_Service_Content::getInstance()->checkPostPassword($post, '654321'))
|
383 |
-
);
|
384 |
-
}
|
385 |
-
|
386 |
-
/**
|
387 |
-
* Test CEASED option
|
388 |
-
*
|
389 |
-
* @return void
|
390 |
-
*
|
391 |
-
* @access public
|
392 |
-
* @version 6.0.0
|
393 |
-
*/
|
394 |
-
public function testCeasedOption()
|
395 |
-
{
|
396 |
-
// Hide the post
|
397 |
-
$user = AAM::getUser();
|
398 |
-
$object = $user->getObject(
|
399 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
400 |
-
);
|
401 |
-
|
402 |
-
// Check if save returns positive result
|
403 |
-
$this->assertTrue($object->updateOptionItem('ceased', array(
|
404 |
-
'enabled' => true,
|
405 |
-
'after' => '08/01/2019, 4:37 pm'
|
406 |
-
))->save());
|
407 |
-
|
408 |
-
// Reset all internal cache
|
409 |
-
$this->_resetSubjects();
|
410 |
-
|
411 |
-
// Get post
|
412 |
-
$post = $user->getObject(
|
413 |
-
AAM_Core_Object_Post::OBJECT_TYPE, AAM_UNITTEST_POST_ID
|
414 |
-
);
|
415 |
-
|
416 |
-
// Verify that access to the post is expired
|
417 |
-
$error = AAM_Service_Content::getInstance()->checkPostExpiration($post);
|
418 |
-
|
419 |
-
$this->assertEquals('WP_Error', get_class($error));
|
420 |
-
$this->assertEquals(
|
421 |
-
'User is unauthorized to access this post. Access Expired.',
|
422 |
-
$error->get_error_message()
|
423 |
-
);
|
424 |
-
|
425 |
-
// Test that password is required when incorrect password is provided
|
426 |
-
$this->assertEquals(
|
427 |
-
'WP_Error',
|
428 |
-
get_class(AAM_Service_Content::getInstance()->isAuthorizedToReadPost($post))
|
429 |
-
);
|
430 |
-
}
|
431 |
-
|
432 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Core/CoreServiceTest.php
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Core;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Menu,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM core service functionality
|
20 |
-
*
|
21 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class CoreServiceTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait,
|
27 |
-
AuthUserTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test that all AAM related labels are properly escaped to mitigate XSS
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testEscapeTranslation()
|
38 |
-
{
|
39 |
-
$escaped = __('<script>alert(1);</script>', AAM_KEY);
|
40 |
-
$this->assertEquals($escaped, '<script>alert(1);</script>');
|
41 |
-
}
|
42 |
-
|
43 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/DeniedRedirect/Callback.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\DeniedRedirect;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const OUTPUT = 'Redirect Callback Output';
|
8 |
-
|
9 |
-
public static function printOutput()
|
10 |
-
{
|
11 |
-
echo self::OUTPUT;
|
12 |
-
}
|
13 |
-
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/DeniedRedirect/DeniedRedirectTest.php
DELETED
@@ -1,189 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\DeniedRedirect;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Redirect,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait;
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Access Denied Redirect service
|
19 |
-
*
|
20 |
-
* @package AAM\UnitTest
|
21 |
-
* @version 6.0.0
|
22 |
-
*/
|
23 |
-
class DeniedRedirectTest extends TestCase
|
24 |
-
{
|
25 |
-
use ResetTrait;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Test default redirect which is "Access Denied" message
|
29 |
-
*
|
30 |
-
* @return void
|
31 |
-
*
|
32 |
-
* @access public
|
33 |
-
* @version 6.0.0
|
34 |
-
*/
|
35 |
-
public function testDefaultRedirect()
|
36 |
-
{
|
37 |
-
// Capture the WP Die message
|
38 |
-
ob_start();
|
39 |
-
wp_die('Restricted Access', 'aam_access_denied', array('exit' => false));
|
40 |
-
$content = ob_get_contents();
|
41 |
-
ob_end_clean();
|
42 |
-
|
43 |
-
$this->assertStringContainsString('Access Denied', $content);
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Test custom WP Die message content
|
48 |
-
*
|
49 |
-
* @return void
|
50 |
-
*
|
51 |
-
* @access public
|
52 |
-
* @version 6.0.0
|
53 |
-
*/
|
54 |
-
public function testCustomMessageRedirect()
|
55 |
-
{
|
56 |
-
// Define custom access denied message
|
57 |
-
$redirect = AAM::getUser()->getObject(AAM_Core_Object_Redirect::OBJECT_TYPE);
|
58 |
-
$redirect->updateOptionItem('frontend.redirect.type', 'message');
|
59 |
-
$redirect->updateOptionItem('frontend.redirect.message', 'Denied by test');
|
60 |
-
|
61 |
-
$this->assertTrue($redirect->save());
|
62 |
-
|
63 |
-
// Reset all internal cache
|
64 |
-
$this->_resetSubjects();
|
65 |
-
|
66 |
-
// Capture the WP Die message
|
67 |
-
ob_start();
|
68 |
-
wp_die('Test', 'aam_access_denied', array('exit' => false));
|
69 |
-
$content = ob_get_contents();
|
70 |
-
ob_end_clean();
|
71 |
-
|
72 |
-
$this->assertStringContainsString('Denied by test', $content);
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Test redirect to the existing page
|
77 |
-
*
|
78 |
-
* @return void
|
79 |
-
*
|
80 |
-
* @access public
|
81 |
-
* @version 6.0.0
|
82 |
-
*/
|
83 |
-
public function testExistingPageRedirect()
|
84 |
-
{
|
85 |
-
// Define custom access denied message
|
86 |
-
$redirect = AAM::getUser()->getObject(AAM_Core_Object_Redirect::OBJECT_TYPE);
|
87 |
-
$redirect->updateOptionItem('frontend.redirect.type', 'page');
|
88 |
-
$redirect->updateOptionItem('frontend.redirect.page', AAM_UNITTEST_PAGE_ID);
|
89 |
-
|
90 |
-
$this->assertTrue($redirect->save());
|
91 |
-
|
92 |
-
// Reset all internal cache
|
93 |
-
$this->_resetSubjects();
|
94 |
-
|
95 |
-
// Capture the WP Die message
|
96 |
-
ob_start();
|
97 |
-
wp_die('Access Denied', 'aam_access_denied', array('exit' => false));
|
98 |
-
ob_end_clean();
|
99 |
-
|
100 |
-
$this->assertContains('Location: ' . get_page_link(AAM_UNITTEST_PAGE_ID), xdebug_get_headers());
|
101 |
-
}
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Test redirect to specified URI
|
105 |
-
*
|
106 |
-
* @return void
|
107 |
-
*
|
108 |
-
* @access public
|
109 |
-
* @version 6.0.0
|
110 |
-
*/
|
111 |
-
public function testUrlRedirect()
|
112 |
-
{
|
113 |
-
// Define custom access denied message
|
114 |
-
$redirect = AAM::getUser()->getObject(AAM_Core_Object_Redirect::OBJECT_TYPE);
|
115 |
-
$redirect->updateOptionItem('frontend.redirect.type', 'url');
|
116 |
-
$redirect->updateOptionItem('frontend.redirect.url', '/hello-world');
|
117 |
-
|
118 |
-
$this->assertTrue($redirect->save());
|
119 |
-
|
120 |
-
// Reset all internal cache
|
121 |
-
$this->_resetSubjects();
|
122 |
-
|
123 |
-
// Capture the WP Die message
|
124 |
-
ob_start();
|
125 |
-
wp_die('Access Denied', 'aam_access_denied', array('exit' => false));
|
126 |
-
ob_end_clean();
|
127 |
-
|
128 |
-
$this->assertContains('Location: /hello-world', xdebug_get_headers());
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Test redirect to the login screen
|
133 |
-
*
|
134 |
-
* @return void
|
135 |
-
*
|
136 |
-
* @access public
|
137 |
-
* @version 6.0.0
|
138 |
-
*/
|
139 |
-
public function testLoginPageRedirect()
|
140 |
-
{
|
141 |
-
// Define custom access denied message
|
142 |
-
$redirect = AAM::getUser()->getObject(AAM_Core_Object_Redirect::OBJECT_TYPE);
|
143 |
-
$redirect->updateOptionItem('frontend.redirect.type', 'login');
|
144 |
-
|
145 |
-
$this->assertTrue($redirect->save());
|
146 |
-
|
147 |
-
// Reset all internal cache
|
148 |
-
$this->_resetSubjects();
|
149 |
-
|
150 |
-
// Capture the WP Die message
|
151 |
-
ob_start();
|
152 |
-
wp_die('Access Denied', 'aam_access_denied', array('exit' => false));
|
153 |
-
ob_end_clean();
|
154 |
-
|
155 |
-
$this->assertContains('Location: ' . add_query_arg(
|
156 |
-
array('reason' => 'restricted'), wp_login_url()
|
157 |
-
), xdebug_get_headers());
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Test redirect to the PHP callback function
|
162 |
-
*
|
163 |
-
* @return void
|
164 |
-
*
|
165 |
-
* @access public
|
166 |
-
* @version 6.0.0
|
167 |
-
*/
|
168 |
-
public function testCallbackRedirect()
|
169 |
-
{
|
170 |
-
// Define custom access denied message
|
171 |
-
$redirect = AAM::getUser()->getObject(AAM_Core_Object_Redirect::OBJECT_TYPE);
|
172 |
-
$redirect->updateOptionItem('frontend.redirect.type', 'callback');
|
173 |
-
$redirect->updateOptionItem('frontend.redirect.callback', 'AAM\\UnitTest\\Service\\DeniedRedirect\\Callback::printOutput');
|
174 |
-
|
175 |
-
$this->assertTrue($redirect->save());
|
176 |
-
|
177 |
-
// Reset all internal cache
|
178 |
-
$this->_resetSubjects();
|
179 |
-
|
180 |
-
// Capture the WP Die message
|
181 |
-
ob_start();
|
182 |
-
wp_die('Access Denied', 'aam_access_denied', array('exit' => false));
|
183 |
-
$content = ob_get_contents();
|
184 |
-
ob_end_clean();
|
185 |
-
|
186 |
-
$this->assertStringContainsString(Callback::OUTPUT, $content);
|
187 |
-
}
|
188 |
-
|
189 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Jwt/JwtTest.php
DELETED
@@ -1,360 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Jwt;
|
11 |
-
|
12 |
-
use DateTime,
|
13 |
-
AAM_Service_Jwt,
|
14 |
-
WP_REST_Request,
|
15 |
-
AAM_Core_Config,
|
16 |
-
AAM_Core_Jwt_Issuer,
|
17 |
-
PHPUnit\Framework\TestCase,
|
18 |
-
AAM\UnitTest\Libs\ResetTrait;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Jwt service tests
|
22 |
-
*
|
23 |
-
* @package AAM\UnitTest
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class JwtTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Assert that jwt token is generated for the authentication request
|
32 |
-
*
|
33 |
-
* @return void
|
34 |
-
*
|
35 |
-
* @access public
|
36 |
-
* @version 6.0.0
|
37 |
-
*/
|
38 |
-
public function testAuthResponseContainsJwt()
|
39 |
-
{
|
40 |
-
$server = rest_get_server();
|
41 |
-
|
42 |
-
// No need to generate Auth cookies
|
43 |
-
add_filter('send_auth_cookies', '__return_false');
|
44 |
-
|
45 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
46 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
47 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
48 |
-
$request->set_param('issueJWT', true);
|
49 |
-
|
50 |
-
$data = $server->dispatch($request)->get_data();
|
51 |
-
|
52 |
-
$this->assertArrayHasKey('jwt', $data);
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Validate that issued JWT token is valid when it is marked as none-revokable
|
57 |
-
*
|
58 |
-
* @return void
|
59 |
-
*
|
60 |
-
* @access public
|
61 |
-
* @version 6.0.0
|
62 |
-
*/
|
63 |
-
public function testValidateNotRevocableJwtToken()
|
64 |
-
{
|
65 |
-
$server = rest_get_server();
|
66 |
-
|
67 |
-
// Generate valid JWT token
|
68 |
-
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(array(
|
69 |
-
'userId' => AAM_UNITTEST_AUTH_USER_ID,
|
70 |
-
'revocable' => false,
|
71 |
-
'refreshable' => false
|
72 |
-
));
|
73 |
-
|
74 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
75 |
-
$this->assertObjectHasAttribute('claims', $jwt);
|
76 |
-
|
77 |
-
$request = new WP_REST_Request('POST', '/aam/v1/validate-jwt');
|
78 |
-
$request->set_param('jwt', $jwt->token);
|
79 |
-
|
80 |
-
$response = $server->dispatch($request);
|
81 |
-
|
82 |
-
$this->assertEquals(200, $response->get_status());
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Validate that issued JWT is not valid when it is marked as revokable and is
|
87 |
-
* not stored in the JWT store
|
88 |
-
*
|
89 |
-
* @access public
|
90 |
-
* @version 6.0.0
|
91 |
-
*/
|
92 |
-
public function testValidateRevocableJwtToken()
|
93 |
-
{
|
94 |
-
$server = rest_get_server();
|
95 |
-
|
96 |
-
// Generate valid JWT token
|
97 |
-
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(array(
|
98 |
-
'userId' => AAM_UNITTEST_AUTH_USER_ID,
|
99 |
-
'revocable' => true,
|
100 |
-
'refreshable' => false
|
101 |
-
));
|
102 |
-
|
103 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
104 |
-
$this->assertObjectHasAttribute('claims', $jwt);
|
105 |
-
|
106 |
-
$request = new WP_REST_Request('POST', '/aam/v1/validate-jwt');
|
107 |
-
$request->set_param('jwt', $jwt->token);
|
108 |
-
|
109 |
-
$response = $server->dispatch($request);
|
110 |
-
|
111 |
-
$this->assertEquals(400, $response->get_status());
|
112 |
-
$this->assertEquals('Token has been revoked', $response->get_data()->get_error_message());
|
113 |
-
}
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Validate that JWT token is invalid when it is expired
|
117 |
-
*
|
118 |
-
* @access public
|
119 |
-
* @version 6.0.0
|
120 |
-
*/
|
121 |
-
public function testValidateExpiredJwtToken()
|
122 |
-
{
|
123 |
-
$server = rest_get_server();
|
124 |
-
|
125 |
-
// Generate valid JWT token
|
126 |
-
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(array(
|
127 |
-
'userId' => AAM_UNITTEST_AUTH_USER_ID,
|
128 |
-
'revocable' => true,
|
129 |
-
'refreshable' => false
|
130 |
-
), DateTime::createFromFormat('m/d/Y', '01/01/2018'));
|
131 |
-
|
132 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
133 |
-
$this->assertObjectHasAttribute('claims', $jwt);
|
134 |
-
|
135 |
-
$request = new WP_REST_Request('POST', '/aam/v1/validate-jwt');
|
136 |
-
$request->set_param('jwt', $jwt->token);
|
137 |
-
|
138 |
-
$response = $server->dispatch($request);
|
139 |
-
|
140 |
-
$this->assertEquals(400, $response->get_status());
|
141 |
-
$this->assertEquals('Expired token', $response->get_data()->get_error_message());
|
142 |
-
}
|
143 |
-
|
144 |
-
/**
|
145 |
-
* Verify that user JWT token registry is populated correctly
|
146 |
-
*
|
147 |
-
* @return void
|
148 |
-
*
|
149 |
-
* @access public
|
150 |
-
* @version 6.0.0
|
151 |
-
*/
|
152 |
-
public function testTokenRegistryPopulated()
|
153 |
-
{
|
154 |
-
$service = AAM_Service_Jwt::getInstance();
|
155 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
156 |
-
|
157 |
-
// Assert that the registry is empty
|
158 |
-
$this->assertEquals(0, count($tokens));
|
159 |
-
|
160 |
-
// Issue new token and verify that registry increased by one
|
161 |
-
$res = $service->issueToken(AAM_UNITTEST_JOHN_ID);
|
162 |
-
|
163 |
-
// Reset cache
|
164 |
-
wp_cache_flush();
|
165 |
-
|
166 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
167 |
-
|
168 |
-
// Assert that the new token is there
|
169 |
-
$this->assertEquals(1, count($tokens));
|
170 |
-
$this->assertTrue(in_array($res->token, $tokens, true));
|
171 |
-
}
|
172 |
-
|
173 |
-
/**
|
174 |
-
* Verify that registry implement ring-buffer approach and does not allow to
|
175 |
-
* overload the DB
|
176 |
-
*
|
177 |
-
* @return void
|
178 |
-
*
|
179 |
-
* @access public
|
180 |
-
* @version 6.0.0
|
181 |
-
*/
|
182 |
-
public function testTokenRegistryOverflow()
|
183 |
-
{
|
184 |
-
AAM_Core_Config::set('authentication.jwt.registryLimit', 1);
|
185 |
-
|
186 |
-
// Reset cache
|
187 |
-
wp_cache_flush();
|
188 |
-
|
189 |
-
$service = AAM_Service_Jwt::getInstance();
|
190 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
191 |
-
|
192 |
-
// Assert that the registry is empty
|
193 |
-
$this->assertEquals(0, count($tokens));
|
194 |
-
|
195 |
-
// Issue new token and verify that registry increased by one
|
196 |
-
$res1 = $service->issueToken(AAM_UNITTEST_JOHN_ID);
|
197 |
-
|
198 |
-
// Reset cache
|
199 |
-
wp_cache_flush();
|
200 |
-
|
201 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
202 |
-
|
203 |
-
// Assert that token is in the registry
|
204 |
-
$this->assertEquals(1, count($tokens));
|
205 |
-
|
206 |
-
// Issue a new token and make sure that there is only one token in the
|
207 |
-
// registry
|
208 |
-
$res2 = $service->issueToken(AAM_UNITTEST_JOHN_ID);
|
209 |
-
|
210 |
-
// Reset cache
|
211 |
-
wp_cache_flush();
|
212 |
-
|
213 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
214 |
-
|
215 |
-
// Assert that token is in the registry
|
216 |
-
$this->assertEquals(1, count($tokens));
|
217 |
-
|
218 |
-
$this->assertFalse(in_array($res1->token, $tokens, true));
|
219 |
-
$this->assertTrue(in_array($res2->token, $tokens, true));
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Verify that token can be refreshed successfully
|
224 |
-
*
|
225 |
-
* @return void
|
226 |
-
*
|
227 |
-
* @access public
|
228 |
-
* @version 6.0.0
|
229 |
-
*/
|
230 |
-
public function testTokenRefreshValid()
|
231 |
-
{
|
232 |
-
$server = rest_get_server();
|
233 |
-
$service = AAM_Service_Jwt::getInstance();
|
234 |
-
|
235 |
-
// Issue a token that later we'll refresh
|
236 |
-
$jwt = $service->issueToken(AAM_UNITTEST_JOHN_ID, null, null, true);
|
237 |
-
|
238 |
-
// Verify that token was issued
|
239 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
240 |
-
|
241 |
-
// Refresh token
|
242 |
-
$request = new WP_REST_Request('POST', '/aam/v1/refresh-jwt');
|
243 |
-
$request->set_param('jwt', $jwt->token);
|
244 |
-
|
245 |
-
$response = $server->dispatch($request);
|
246 |
-
|
247 |
-
$this->assertEquals(200, $response->get_status());
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Verify that token can't be refreshed if it is simply invalid JWT token
|
252 |
-
*
|
253 |
-
* @return void
|
254 |
-
*
|
255 |
-
* @access public
|
256 |
-
* @version 6.0.0
|
257 |
-
*/
|
258 |
-
public function testTokenRefreshNotValid()
|
259 |
-
{
|
260 |
-
$server = rest_get_server();
|
261 |
-
|
262 |
-
// Refresh token
|
263 |
-
$request = new WP_REST_Request('POST', '/aam/v1/refresh-jwt');
|
264 |
-
$request->set_param('jwt', 'invalid-token');
|
265 |
-
|
266 |
-
$response = $server->dispatch($request);
|
267 |
-
|
268 |
-
$this->assertEquals(400, $response->get_status());
|
269 |
-
$this->assertStringContainsString('Invalid JWT token: Malformed UTF-8 characters', $response->get_data()->get_error_message());
|
270 |
-
}
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Verify that new token is not issued for already expired token
|
274 |
-
*
|
275 |
-
* @return void
|
276 |
-
*
|
277 |
-
* @access public
|
278 |
-
* @version 6.0.0
|
279 |
-
*/
|
280 |
-
public function testTokenRefreshExpired()
|
281 |
-
{
|
282 |
-
$server = rest_get_server();
|
283 |
-
|
284 |
-
// Generate valid JWT token
|
285 |
-
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(array(
|
286 |
-
'userId' => AAM_UNITTEST_AUTH_USER_ID,
|
287 |
-
'revocable' => true,
|
288 |
-
'refreshable' => true
|
289 |
-
), DateTime::createFromFormat('m/d/Y', '01/01/2018'));
|
290 |
-
|
291 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
292 |
-
$this->assertObjectHasAttribute('claims', $jwt);
|
293 |
-
|
294 |
-
$request = new WP_REST_Request('POST', '/aam/v1/refresh-jwt');
|
295 |
-
$request->set_param('jwt', $jwt->token);
|
296 |
-
|
297 |
-
$response = $server->dispatch($request);
|
298 |
-
|
299 |
-
$this->assertEquals(400, $response->get_status());
|
300 |
-
$this->assertEquals('Expired token', $response->get_data()->get_error_message());
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Verify that new token is not issued for none-refreshable token
|
305 |
-
*
|
306 |
-
* @return void
|
307 |
-
*
|
308 |
-
* @access public
|
309 |
-
* @version 6.0.0
|
310 |
-
*/
|
311 |
-
public function testTokenRefreshNotRefreshable()
|
312 |
-
{
|
313 |
-
$server = rest_get_server();
|
314 |
-
|
315 |
-
// Generate valid JWT token
|
316 |
-
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(array(
|
317 |
-
'userId' => AAM_UNITTEST_AUTH_USER_ID,
|
318 |
-
'revocable' => false,
|
319 |
-
'refreshable' => false
|
320 |
-
));
|
321 |
-
|
322 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
323 |
-
$this->assertObjectHasAttribute('claims', $jwt);
|
324 |
-
|
325 |
-
$request = new WP_REST_Request('POST', '/aam/v1/refresh-jwt');
|
326 |
-
$request->set_param('jwt', $jwt->token);
|
327 |
-
|
328 |
-
$response = $server->dispatch($request);
|
329 |
-
|
330 |
-
$this->assertEquals(400, $response->get_status());
|
331 |
-
$this->assertEquals('JWT token is not refreshable', $response->get_data()->get_error_message());
|
332 |
-
}
|
333 |
-
|
334 |
-
/**
|
335 |
-
* Verify that token is revoked properly
|
336 |
-
*
|
337 |
-
* @access public
|
338 |
-
* @version 6.0.0
|
339 |
-
*/
|
340 |
-
public function testTokenRevoked()
|
341 |
-
{
|
342 |
-
$service = AAM_Service_Jwt::getInstance();
|
343 |
-
|
344 |
-
// Issue a token that later we'll refresh
|
345 |
-
$jwt = $service->issueToken(AAM_UNITTEST_JOHN_ID, null, null, true);
|
346 |
-
|
347 |
-
// Verify that token was issued
|
348 |
-
$this->assertObjectHasAttribute('token', $jwt);
|
349 |
-
|
350 |
-
$this->assertTrue($service->revokeToken(AAM_UNITTEST_JOHN_ID, $jwt->token));
|
351 |
-
|
352 |
-
// Reset cache
|
353 |
-
wp_cache_flush();
|
354 |
-
|
355 |
-
$tokens = $service->getTokenRegistry(AAM_UNITTEST_JOHN_ID);
|
356 |
-
|
357 |
-
$this->assertFalse(in_array($jwt->token, $tokens, true));
|
358 |
-
}
|
359 |
-
|
360 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/LoginRedirect/Callback.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\LoginRedirect;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const REDIRECT_URL = 'https://aamplugin.com/redirect';
|
8 |
-
|
9 |
-
public static function redirectCallback()
|
10 |
-
{
|
11 |
-
return self::REDIRECT_URL;
|
12 |
-
}
|
13 |
-
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/LoginRedirect/LoginRedirectTest.php
DELETED
@@ -1,215 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\LoginRedirect;
|
11 |
-
|
12 |
-
use WP_REST_Request,
|
13 |
-
AAM_Core_Subject_User,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM_Core_Object_LoginRedirect;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Login Redirect feature
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class LoginRedirectTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Assert that correct URL login redirect is returns for RESTful auth call
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testRESTfulLoginURLRedirect()
|
37 |
-
{
|
38 |
-
$server = rest_get_server();
|
39 |
-
|
40 |
-
// No need to generate Auth cookies
|
41 |
-
add_filter('send_auth_cookies', '__return_false');
|
42 |
-
|
43 |
-
// Set login redirect
|
44 |
-
$subject = new AAM_Core_Subject_User(AAM_UNITTEST_JOHN_ID);
|
45 |
-
$object = $subject->getObject(AAM_Core_Object_LoginRedirect::OBJECT_TYPE, null, true);
|
46 |
-
$object->setOption(array(
|
47 |
-
'login.redirect.type' => 'url',
|
48 |
-
'login.redirect.url' => 'https://aamplugin.com'
|
49 |
-
));
|
50 |
-
$object->save();
|
51 |
-
|
52 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
53 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
54 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
55 |
-
|
56 |
-
$data = $server->dispatch($request)->get_data();
|
57 |
-
|
58 |
-
$this->assertEquals('WP_User', get_class($data['user']));
|
59 |
-
$this->assertEquals('https://aamplugin.com', $data['redirect']);
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Assert that correct Page login redirect is returns for RESTful auth call
|
64 |
-
*
|
65 |
-
* @return void
|
66 |
-
*
|
67 |
-
* @access public
|
68 |
-
* @version 6.0.0
|
69 |
-
*/
|
70 |
-
public function testRESTfulLoginPageRedirect()
|
71 |
-
{
|
72 |
-
$server = rest_get_server();
|
73 |
-
|
74 |
-
// No need to generate Auth cookies
|
75 |
-
add_filter('send_auth_cookies', '__return_false');
|
76 |
-
|
77 |
-
// Set login redirect
|
78 |
-
$subject = new AAM_Core_Subject_User(AAM_UNITTEST_JOHN_ID);
|
79 |
-
$object = $subject->getObject(AAM_Core_Object_LoginRedirect::OBJECT_TYPE, null, true);
|
80 |
-
$object->setOption(array(
|
81 |
-
'login.redirect.type' => 'page',
|
82 |
-
'login.redirect.page' => AAM_UNITTEST_PAGE_ID
|
83 |
-
));
|
84 |
-
$object->save();
|
85 |
-
|
86 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
87 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
88 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
89 |
-
|
90 |
-
$data = $server->dispatch($request)->get_data();
|
91 |
-
|
92 |
-
$this->assertEquals('WP_User', get_class($data['user']));
|
93 |
-
$this->assertEquals(get_page_link(AAM_UNITTEST_PAGE_ID), $data['redirect']);
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Assert that correct login redirect is returns for RESTful auth call for
|
98 |
-
* callback type of redirect
|
99 |
-
*
|
100 |
-
* @return void
|
101 |
-
*
|
102 |
-
* @access public
|
103 |
-
* @version 6.0.0
|
104 |
-
*/
|
105 |
-
public function testRESTfulLoginCallbackRedirect()
|
106 |
-
{
|
107 |
-
$server = rest_get_server();
|
108 |
-
|
109 |
-
// No need to generate Auth cookies
|
110 |
-
add_filter('send_auth_cookies', '__return_false');
|
111 |
-
|
112 |
-
// Set login redirect
|
113 |
-
$subject = new AAM_Core_Subject_User(AAM_UNITTEST_JOHN_ID);
|
114 |
-
$object = $subject->getObject(AAM_Core_Object_LoginRedirect::OBJECT_TYPE, null, true);
|
115 |
-
$object->setOption(array(
|
116 |
-
'login.redirect.type' => 'callback',
|
117 |
-
'login.redirect.callback' => 'AAM\\UnitTest\\Service\\LoginRedirect\\Callback::redirectCallback'
|
118 |
-
));
|
119 |
-
$object->save();
|
120 |
-
|
121 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
122 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
123 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
124 |
-
|
125 |
-
$data = $server->dispatch($request)->get_data();
|
126 |
-
|
127 |
-
$this->assertEquals('WP_User', get_class($data['user']));
|
128 |
-
$this->assertEquals(Callback::REDIRECT_URL, $data['redirect']);
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Assert that null login redirect is returns for RESTful auth call
|
133 |
-
*
|
134 |
-
* @return void
|
135 |
-
*
|
136 |
-
* @access public
|
137 |
-
* @version 6.0.0
|
138 |
-
*/
|
139 |
-
public function testRESTfulLoginDefaultRedirect()
|
140 |
-
{
|
141 |
-
$server = rest_get_server();
|
142 |
-
|
143 |
-
// No need to generate Auth cookies
|
144 |
-
add_filter('send_auth_cookies', '__return_false');
|
145 |
-
|
146 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
147 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
148 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
149 |
-
|
150 |
-
$data = $server->dispatch($request)->get_data();
|
151 |
-
|
152 |
-
$this->assertEquals('WP_User', get_class($data['user']));
|
153 |
-
$this->assertNull($data['redirect']);
|
154 |
-
}
|
155 |
-
|
156 |
-
/**
|
157 |
-
* Validate that `login_redirect` filter is triggered with AAM hook
|
158 |
-
*
|
159 |
-
* Make sure that user will be redirected to the existing page
|
160 |
-
*
|
161 |
-
* @return void
|
162 |
-
*
|
163 |
-
* @access public
|
164 |
-
* @version 6.0.0
|
165 |
-
*/
|
166 |
-
public function testLoginRedirectHookTriggerChanges()
|
167 |
-
{
|
168 |
-
// Set login redirect
|
169 |
-
$subject = new AAM_Core_Subject_User(AAM_UNITTEST_JOHN_ID);
|
170 |
-
$object = $subject->getObject(AAM_Core_Object_LoginRedirect::OBJECT_TYPE, null, true);
|
171 |
-
$object->setOption(array(
|
172 |
-
'login.redirect.type' => 'page',
|
173 |
-
'login.redirect.page' => AAM_UNITTEST_PAGE_ID
|
174 |
-
));
|
175 |
-
$object->save();
|
176 |
-
|
177 |
-
$redirect = apply_filters('login_redirect', admin_url(), admin_url(), $subject->getPrincipal());
|
178 |
-
|
179 |
-
$this->assertEquals(get_page_link(AAM_UNITTEST_PAGE_ID), $redirect);
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* Validate that `login_redirect` filter is triggered with AAM hook
|
184 |
-
*
|
185 |
-
* Make sure that user will be redirected to originally defined destination. By
|
186 |
-
* default AAM overwrites only destinations that are different than admin_url()
|
187 |
-
* return.
|
188 |
-
*
|
189 |
-
* @return void
|
190 |
-
*
|
191 |
-
* @access public
|
192 |
-
* @version 6.0.0
|
193 |
-
*/
|
194 |
-
public function testLoginRedirectHookTriggerPersistOriginalRedirect()
|
195 |
-
{
|
196 |
-
// Set login redirect
|
197 |
-
$subject = new AAM_Core_Subject_User(AAM_UNITTEST_JOHN_ID);
|
198 |
-
$object = $subject->getObject(AAM_Core_Object_LoginRedirect::OBJECT_TYPE, null, true);
|
199 |
-
$object->setOption(array(
|
200 |
-
'login.redirect.type' => 'url',
|
201 |
-
'login.redirect.url' => 'https://aamplugin.com'
|
202 |
-
));
|
203 |
-
$object->save();
|
204 |
-
|
205 |
-
$redirect = apply_filters(
|
206 |
-
'login_redirect',
|
207 |
-
get_page_link(AAM_UNITTEST_PAGE_ID),
|
208 |
-
get_page_link(AAM_UNITTEST_PAGE_ID),
|
209 |
-
$subject->getPrincipal()
|
210 |
-
);
|
211 |
-
|
212 |
-
$this->assertEquals(get_page_link(AAM_UNITTEST_PAGE_ID), $redirect);
|
213 |
-
}
|
214 |
-
|
215 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/LogoutRedirect/Callback.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\LogoutRedirect;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const REDIRECT_URL = 'https://aamplugin.com/redirect';
|
8 |
-
|
9 |
-
public static function redirectCallback()
|
10 |
-
{
|
11 |
-
header('Location: ' . self::REDIRECT_URL);
|
12 |
-
}
|
13 |
-
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/LogoutRedirect/LogoutRedirectTest.php
DELETED
@@ -1,115 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\LogoutRedirect;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
PHPUnit\Framework\TestCase,
|
14 |
-
AAM\UnitTest\Libs\ResetTrait,
|
15 |
-
AAM_Core_Object_LogoutRedirect,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Logout Redirect feature
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class LogoutRedirectTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait,
|
27 |
-
AuthUserTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test the default logout redirect
|
31 |
-
*
|
32 |
-
* AAM should not issue any redirect headers
|
33 |
-
*
|
34 |
-
* @return void
|
35 |
-
*
|
36 |
-
* @access public
|
37 |
-
* @version 6.0.0
|
38 |
-
*/
|
39 |
-
public function testDefaultLogoutRedirect()
|
40 |
-
{
|
41 |
-
// Reset any already sent "Location" headers. This way insure that no other
|
42 |
-
// redirect headers are sent
|
43 |
-
header('Location: empty');
|
44 |
-
do_action('wp_logout');
|
45 |
-
|
46 |
-
$this->assertContains('Location: empty', xdebug_get_headers());
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Test redirect to the existing page
|
51 |
-
*
|
52 |
-
* @return void
|
53 |
-
*
|
54 |
-
* @access public
|
55 |
-
* @version 6.0.0
|
56 |
-
*/
|
57 |
-
public function testExistingPageLogoutRedirect()
|
58 |
-
{
|
59 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_LogoutRedirect::OBJECT_TYPE, null, true);
|
60 |
-
$object->setOption(array(
|
61 |
-
'logout.redirect.type' => 'page',
|
62 |
-
'logout.redirect.page' => AAM_UNITTEST_PAGE_ID
|
63 |
-
));
|
64 |
-
$object->save();
|
65 |
-
|
66 |
-
do_action('wp_logout');
|
67 |
-
|
68 |
-
$this->assertContains('Location: ' . get_page_link(AAM_UNITTEST_PAGE_ID), xdebug_get_headers());
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Test redirect to the defined URL
|
73 |
-
*
|
74 |
-
* @return void
|
75 |
-
*
|
76 |
-
* @access public
|
77 |
-
* @version 6.0.0
|
78 |
-
*/
|
79 |
-
public function testUrlLogoutRedirect()
|
80 |
-
{
|
81 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_LogoutRedirect::OBJECT_TYPE, null, true);
|
82 |
-
$object->setOption(array(
|
83 |
-
'logout.redirect.type' => 'url',
|
84 |
-
'logout.redirect.url' => '/hello-world'
|
85 |
-
));
|
86 |
-
$object->save();
|
87 |
-
|
88 |
-
do_action('wp_logout');
|
89 |
-
|
90 |
-
$this->assertContains('Location: /hello-world', xdebug_get_headers());
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Test execution of the callback function as redirect
|
95 |
-
*
|
96 |
-
* @return void
|
97 |
-
*
|
98 |
-
* @access public
|
99 |
-
* @version 6.0.0
|
100 |
-
*/
|
101 |
-
public function testCallbackLogoutRedirect()
|
102 |
-
{
|
103 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_LogoutRedirect::OBJECT_TYPE, null, true);
|
104 |
-
$object->setOption(array(
|
105 |
-
'logout.redirect.type' => 'callback',
|
106 |
-
'logout.redirect.callback' => 'AAM\\UnitTest\\Service\\LogoutRedirect\\Callback::redirectCallback'
|
107 |
-
));
|
108 |
-
$object->save();
|
109 |
-
|
110 |
-
do_action('wp_logout');
|
111 |
-
|
112 |
-
$this->assertContains('Location: ' . Callback::REDIRECT_URL, xdebug_get_headers());
|
113 |
-
}
|
114 |
-
|
115 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Metabox/MultipleRoleInheritanceTest.php
DELETED
@@ -1,192 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Metabox;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM_Core_Object_Metabox,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthMultiRoleUserTrait,
|
18 |
-
AAM\UnitTest\Libs\MultiRoleOptionInterface;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test AAM access settings inheritance mechanism for multiple roles per user for
|
22 |
-
* the Metaboxes & Widgets service
|
23 |
-
*
|
24 |
-
* @package AAM\UnitTest
|
25 |
-
* @version 6.0.0
|
26 |
-
*/
|
27 |
-
class MultipleRoleInheritanceTest extends TestCase implements MultiRoleOptionInterface
|
28 |
-
{
|
29 |
-
use ResetTrait,
|
30 |
-
AuthMultiRoleUserTrait;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Test that access settings are inherited from multiple parent roles
|
34 |
-
*
|
35 |
-
* This test is designed to verify that access settings are propagated property
|
36 |
-
* when there access settings defined for multiple parent roles.
|
37 |
-
*
|
38 |
-
* A. Test that settings can be stored for the parent roles;
|
39 |
-
* B. Test that access settings are propagated property to the User level
|
40 |
-
*
|
41 |
-
* @return void
|
42 |
-
*
|
43 |
-
* @access public
|
44 |
-
* @version 6.0.0
|
45 |
-
*/
|
46 |
-
public function testInheritanceMergeFromMultipleRoles()
|
47 |
-
{
|
48 |
-
$user = AAM::getUser();
|
49 |
-
$role = $user->getParent();
|
50 |
-
|
51 |
-
// Make sure that we have parent roles defined properly
|
52 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
53 |
-
|
54 |
-
// Save access settings for the base role and iterate over each sibling and
|
55 |
-
// add additional settings
|
56 |
-
$this->assertTrue(
|
57 |
-
$role->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
58 |
-
'dashboard|dashboard_quick_press_0', true
|
59 |
-
)->save()
|
60 |
-
);
|
61 |
-
|
62 |
-
foreach($role->getSiblings() as $i => $sibling) {
|
63 |
-
// Save access settings for each role and make sure they are saved property
|
64 |
-
// Check if save returns positive result
|
65 |
-
$this->assertTrue(
|
66 |
-
$sibling->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
67 |
-
'dashboard|dashboard_quick_press_' . ($i + 1), ($i % 2 ? true : false)
|
68 |
-
)->save()
|
69 |
-
);
|
70 |
-
}
|
71 |
-
|
72 |
-
// Reset internal AAM cache
|
73 |
-
$this->_resetSubjects();
|
74 |
-
|
75 |
-
// Assert that we have both roles merged result is as following
|
76 |
-
// Array (
|
77 |
-
// dashboard|dashboard_quick_press_0 => true,
|
78 |
-
// dashboard|dashboard_quick_press_1 => false
|
79 |
-
// )
|
80 |
-
$option = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE)->getOption();
|
81 |
-
$this->assertSame(
|
82 |
-
array(
|
83 |
-
'dashboard|dashboard_quick_press_0' => true,
|
84 |
-
'dashboard|dashboard_quick_press_1' => false
|
85 |
-
),
|
86 |
-
$option
|
87 |
-
);
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Check that access to resource is denied when two or more roles have the same
|
92 |
-
* resource defined
|
93 |
-
*
|
94 |
-
* @return void
|
95 |
-
*
|
96 |
-
* @access public
|
97 |
-
* @version 6.0.0
|
98 |
-
*/
|
99 |
-
public function testInheritanceDenyPrecedenceFromMultipleRoles()
|
100 |
-
{
|
101 |
-
$user = AAM::getUser();
|
102 |
-
$role = $user->getParent();
|
103 |
-
|
104 |
-
// Make sure that we have parent roles defined properly
|
105 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
106 |
-
|
107 |
-
// Save access settings for the base role and iterate over each sibling and
|
108 |
-
// add additional settings
|
109 |
-
$this->assertTrue(
|
110 |
-
$role->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
111 |
-
'widgets|WP_Widget_Media_Video', true
|
112 |
-
)->save()
|
113 |
-
);
|
114 |
-
|
115 |
-
foreach($role->getSiblings() as $sibling) {
|
116 |
-
// Save access settings for each role and make sure they are saved property
|
117 |
-
// Check if save returns positive result
|
118 |
-
$this->assertTrue(
|
119 |
-
$sibling->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
120 |
-
'widgets|WP_Widget_Media_Video', false
|
121 |
-
)->save()
|
122 |
-
);
|
123 |
-
}
|
124 |
-
|
125 |
-
// Reset internal AAM cache
|
126 |
-
$this->_resetSubjects();
|
127 |
-
|
128 |
-
// Assert that we have both roles merged result is as following
|
129 |
-
// Array (
|
130 |
-
// widgets|WP_Widget_Media_Video => true
|
131 |
-
// )
|
132 |
-
$option = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE)->getOption();
|
133 |
-
$this->assertSame(
|
134 |
-
array('widgets|WP_Widget_Media_Video' => true), $option
|
135 |
-
);
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* Check that access is allowed to the resource when two or more roles have the
|
140 |
-
* same resource defined
|
141 |
-
*
|
142 |
-
* @return void
|
143 |
-
*
|
144 |
-
* @access public
|
145 |
-
* @version 6.0.0
|
146 |
-
*/
|
147 |
-
public function testInheritanceAllowPrecedenceFromMultipleRoles()
|
148 |
-
{
|
149 |
-
$user = AAM::getUser();
|
150 |
-
$role = $user->getParent();
|
151 |
-
|
152 |
-
// Make sure that we have parent roles defined properly
|
153 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
154 |
-
|
155 |
-
// Save access settings for the base role and iterate over each sibling and
|
156 |
-
// add additional settings
|
157 |
-
$this->assertTrue(
|
158 |
-
$role->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
159 |
-
'widgets|WP_Widget_Media_Video', true
|
160 |
-
)->save()
|
161 |
-
);
|
162 |
-
|
163 |
-
foreach($role->getSiblings() as $sibling) {
|
164 |
-
// Save access settings for each role and make sure they are saved property
|
165 |
-
// Check if save returns positive result
|
166 |
-
$this->assertTrue(
|
167 |
-
$sibling->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true)->updateOptionItem(
|
168 |
-
'widgets|WP_Widget_Media_Video', false
|
169 |
-
)->save()
|
170 |
-
);
|
171 |
-
}
|
172 |
-
|
173 |
-
// Override the default "deny" precedence
|
174 |
-
AAM_Core_Config::set(
|
175 |
-
sprintf('core.settings.%s.merge.preference', AAM_Core_Object_Metabox::OBJECT_TYPE),
|
176 |
-
'allow'
|
177 |
-
);
|
178 |
-
|
179 |
-
// Reset internal AAM cache
|
180 |
-
$this->_resetSubjects();
|
181 |
-
|
182 |
-
// Assert that we have both roles merged result is as following
|
183 |
-
// Array (
|
184 |
-
// widgets|WP_Widget_Media_Video => false
|
185 |
-
// )
|
186 |
-
$option = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE)->getOption();
|
187 |
-
$this->assertSame(
|
188 |
-
array('widgets|WP_Widget_Media_Video' => false), $option
|
189 |
-
);
|
190 |
-
}
|
191 |
-
|
192 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Metabox/SingleRoleInheritanceTest.php
DELETED
@@ -1,231 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Metabox;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Metabox,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM access settings inheritance mechanism for the Metaboxes & Widgets service
|
20 |
-
*
|
21 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class SingleRoleInheritanceTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait,
|
27 |
-
AuthUserTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test to insure that access settings are stored property on the User level
|
31 |
-
*
|
32 |
-
* A. Test that metabox is stored to the database with "true" flag and true
|
33 |
-
* is returned by AAM_Core_Subject_User::updateOption method;
|
34 |
-
* B. Test that information is actually stored property in the database and can
|
35 |
-
* be retrieved successfully.
|
36 |
-
*
|
37 |
-
* @return void
|
38 |
-
*
|
39 |
-
* @access public
|
40 |
-
* @see AAM_Core_Subject_User::updateOption
|
41 |
-
* @version 6.0.0
|
42 |
-
*/
|
43 |
-
public function testSaveMetaboxOption()
|
44 |
-
{
|
45 |
-
$user = AAM::getUser();
|
46 |
-
$object = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
47 |
-
|
48 |
-
// Check if save returns positive result
|
49 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
50 |
-
|
51 |
-
// Read from the database saved values and assert that we have
|
52 |
-
// Array (
|
53 |
-
// widgets|WP_Widget_Media_Video => true
|
54 |
-
// )
|
55 |
-
$option = $user->readOption(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
56 |
-
$this->assertSame(array('widgets|WP_Widget_Media_Video' => true), $option);
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Test that access settings are inherited from the parent role property
|
61 |
-
*
|
62 |
-
* This test is designed to verify that access settings are propagated property
|
63 |
-
* when there is only one role assigned to a user.
|
64 |
-
*
|
65 |
-
* A. Test that settings can be stored for the parent role;
|
66 |
-
* B. Test that access settings are propagated property to the User level
|
67 |
-
*
|
68 |
-
* @return void
|
69 |
-
*
|
70 |
-
* @access public
|
71 |
-
* @version 6.0.0
|
72 |
-
*/
|
73 |
-
public function testInheritanceFromSingleRole()
|
74 |
-
{
|
75 |
-
$user = AAM::getUser();
|
76 |
-
$parent = $user->getParent();
|
77 |
-
$object = $parent->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
78 |
-
|
79 |
-
// Make sure that we have parent role defined
|
80 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($parent));
|
81 |
-
|
82 |
-
// Save access settings for the role and make sure they are saved property
|
83 |
-
// Check if save returns positive result
|
84 |
-
$this->assertTrue($object->updateOptionItem('dashboard|dashboard_quick_press', true)->save());
|
85 |
-
|
86 |
-
// Read from the database saved values and assert that we have
|
87 |
-
// Array (
|
88 |
-
// dashboard|dashboard_quick_press => true
|
89 |
-
// )
|
90 |
-
$option = $parent->readOption(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
91 |
-
$this->assertSame(array('dashboard|dashboard_quick_press' => true), $option);
|
92 |
-
|
93 |
-
// Finally verify that access settings are propagated property to the User
|
94 |
-
// Level
|
95 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
96 |
-
$this->assertSame(
|
97 |
-
array('dashboard|dashboard_quick_press' => true), $metabox->getOption()
|
98 |
-
);
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Test that access settings are propagated and merged properly
|
103 |
-
*
|
104 |
-
* The test is designed to verify that access settings are propagated properly
|
105 |
-
* from the parent role and merged well with explicitly defined access settings on
|
106 |
-
* the User level.
|
107 |
-
*
|
108 |
-
* The expected result is to have combined array of access settings from the parent
|
109 |
-
* role and specific user.
|
110 |
-
*
|
111 |
-
* A. Test that access settings are stored for the parent role;
|
112 |
-
* B. Test that access settings are stored for the user;
|
113 |
-
* C. Test that access settings are propagated and merged properly;
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*
|
117 |
-
* @access public
|
118 |
-
* @version 6.0.0
|
119 |
-
*/
|
120 |
-
public function testInheritanceMergeFromSingleRole()
|
121 |
-
{
|
122 |
-
$user = AAM::getUser();
|
123 |
-
$parent = $user->getParent();
|
124 |
-
|
125 |
-
$object = $parent->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
126 |
-
|
127 |
-
// Save access settings for the role and make sure they are saved property
|
128 |
-
// Check if save returns positive result
|
129 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
130 |
-
|
131 |
-
// Save access setting for the user and make sure they are saved property
|
132 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
133 |
-
$this->assertTrue($metabox->updateOptionItem('dashboard|dashboard_quick_press', false)->save());
|
134 |
-
|
135 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
136 |
-
$this->_resetSubjects();
|
137 |
-
|
138 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
139 |
-
$this->assertSame(
|
140 |
-
array(
|
141 |
-
'widgets|WP_Widget_Media_Video' => true,
|
142 |
-
'dashboard|dashboard_quick_press' => false
|
143 |
-
),
|
144 |
-
$metabox->getOption()
|
145 |
-
);
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Test that the full inheritance mechanism is working as expected
|
150 |
-
*
|
151 |
-
* Make sure that access settings are propagated and merged properly from the top
|
152 |
-
* (Default Level)to the bottom (User Level).
|
153 |
-
*
|
154 |
-
* A. Assert that access settings are stored properly for each Access Level;
|
155 |
-
* B. Assert that access settings are merged properly and assigned to User Level;
|
156 |
-
*
|
157 |
-
* @return void
|
158 |
-
*
|
159 |
-
* @access public
|
160 |
-
* @version 6.0.0
|
161 |
-
*/
|
162 |
-
public function testFullInheritanceChainSingeRole()
|
163 |
-
{
|
164 |
-
$user = AAM::getUser();
|
165 |
-
$role = $user->getParent();
|
166 |
-
$default = $role->getParent();
|
167 |
-
|
168 |
-
$userMetabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
169 |
-
$roleMetabox = $role->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
170 |
-
$defaultMetabox = $default->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
171 |
-
|
172 |
-
// Save access settings for all subjects
|
173 |
-
$this->assertTrue($userMetabox->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
174 |
-
$this->assertTrue($roleMetabox->updateOptionItem('dashboard|dashboard_quick_press', true)->save());
|
175 |
-
$this->assertTrue($defaultMetabox->updateOptionItem('post|publish_post', true)->save());
|
176 |
-
|
177 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
178 |
-
$this->_resetSubjects();
|
179 |
-
|
180 |
-
// All settings has to be merged into one array
|
181 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
182 |
-
$this->assertSame(
|
183 |
-
array(
|
184 |
-
'post|publish_post' => true,
|
185 |
-
'dashboard|dashboard_quick_press' => true,
|
186 |
-
'widgets|WP_Widget_Media_Video' => true
|
187 |
-
),
|
188 |
-
$metabox->getOption()
|
189 |
-
);
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Test that access settings overwrite works as expected
|
194 |
-
*
|
195 |
-
* The expected result is lower Access Level overwrite access settings from the
|
196 |
-
* higher Access Level.
|
197 |
-
*
|
198 |
-
* A. Assert that access settings are stored properly for the parent role;
|
199 |
-
* B. Assert that access settings are stored properly for the specific user;
|
200 |
-
* C. Assert that access settings are overwritten properly on the User Level;
|
201 |
-
*
|
202 |
-
* @return void
|
203 |
-
*
|
204 |
-
* @access public
|
205 |
-
* @version 6.0.0
|
206 |
-
*/
|
207 |
-
public function testInheritanceOverrideForSingleRole()
|
208 |
-
{
|
209 |
-
$user = AAM::getUser();
|
210 |
-
$parent = $user->getParent();
|
211 |
-
|
212 |
-
$object = $parent->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
213 |
-
|
214 |
-
// Save access settings for the role and make sure they are saved property
|
215 |
-
// Check if save returns positive result
|
216 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
217 |
-
|
218 |
-
// Save access setting for the user and make sure they are saved property
|
219 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
220 |
-
$this->assertTrue($metabox->updateOptionItem('widgets|WP_Widget_Media_Video', false)->save());
|
221 |
-
|
222 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
223 |
-
$this->_resetSubjects();
|
224 |
-
|
225 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
226 |
-
$this->assertSame(
|
227 |
-
array('widgets|WP_Widget_Media_Video' => false), $metabox->getOption()
|
228 |
-
);
|
229 |
-
}
|
230 |
-
|
231 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Metabox/VisitorInheritanceTest.php
DELETED
@@ -1,187 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Metabox;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Metabox,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM access settings inheritance mechanism for the Metaboxes & Widgets service
|
20 |
-
* for the visitor subject
|
21 |
-
*
|
22 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
23 |
-
* @version 6.0.0
|
24 |
-
*/
|
25 |
-
class VisitorInheritanceTest extends TestCase
|
26 |
-
{
|
27 |
-
use ResetTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test to insure that access settings are stored property on the Visitor level
|
31 |
-
*
|
32 |
-
* A. Test that metabox is stored to the database with "true" flag and true
|
33 |
-
* is returned by AAM_Core_Subject_Visitor::updateOption method;
|
34 |
-
* B. Test that information is actually stored property in the database and can
|
35 |
-
* be retrieved successfully.
|
36 |
-
*
|
37 |
-
* @return void
|
38 |
-
*
|
39 |
-
* @access public
|
40 |
-
* @see AAM_Core_Subject_Visitor::updateOption
|
41 |
-
* @version 6.0.0
|
42 |
-
*/
|
43 |
-
public function testSaveMetaboxOption()
|
44 |
-
{
|
45 |
-
$user = AAM::getUser();
|
46 |
-
$object = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
47 |
-
|
48 |
-
// Make sure that we actually are dealing with Visitor subject
|
49 |
-
$this->assertEquals('AAM_Core_Subject_Visitor', get_class($user));
|
50 |
-
|
51 |
-
// Check if save returns positive result
|
52 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
53 |
-
|
54 |
-
// Read from the database saved values and assert that we have
|
55 |
-
// Array (
|
56 |
-
// widgets|WP_Widget_Media_Video => true
|
57 |
-
// )
|
58 |
-
$option = $user->readOption(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
59 |
-
$this->assertSame(array('widgets|WP_Widget_Media_Video' => true), $option);
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Test that access settings are inherited from the parent default subject
|
64 |
-
*
|
65 |
-
* This test is designed to verify that access settings are propagated property
|
66 |
-
* from the default settings
|
67 |
-
*
|
68 |
-
* A. Test that settings can be stored for the default subject
|
69 |
-
* B. Test that access settings are propagated property to the Visitor level
|
70 |
-
*
|
71 |
-
* @return void
|
72 |
-
*
|
73 |
-
* @access public
|
74 |
-
* @version 6.0.0
|
75 |
-
*/
|
76 |
-
public function testInheritanceFromDefault()
|
77 |
-
{
|
78 |
-
$user = AAM::getUser();
|
79 |
-
$parent = $user->getParent();
|
80 |
-
$object = $parent->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
81 |
-
|
82 |
-
// Make sure that we work with Default subject
|
83 |
-
$this->assertEquals('AAM_Core_Subject_Default', get_class($parent));
|
84 |
-
|
85 |
-
// Save access settings for the Default and make sure they are saved property
|
86 |
-
// Check if save returns positive result
|
87 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
88 |
-
|
89 |
-
// Read from the database saved values and assert that we have
|
90 |
-
// Array (
|
91 |
-
// widgets|WP_Widget_Media_Video => true
|
92 |
-
// )
|
93 |
-
$option = $parent->readOption(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
94 |
-
$this->assertSame(array('widgets|WP_Widget_Media_Video' => true), $option);
|
95 |
-
|
96 |
-
// Finally verify that access settings are propagated property to the Visitor
|
97 |
-
// Level
|
98 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
99 |
-
$this->assertSame(
|
100 |
-
array('widgets|WP_Widget_Media_Video' => true), $metabox->getOption()
|
101 |
-
);
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Test that access settings are propagated and merged properly
|
106 |
-
*
|
107 |
-
* The test is designed to verify that access settings are propagated properly
|
108 |
-
* from the Default and merged well with explicitly defined access settings on
|
109 |
-
* the Visitor level.
|
110 |
-
*
|
111 |
-
* A. Test that access settings are stored for the Default subject;
|
112 |
-
* B. Test that access settings are stored for the Visitor;
|
113 |
-
* C. Test that access settings are propagated and merged properly;
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*
|
117 |
-
* @access public
|
118 |
-
* @version 6.0.0
|
119 |
-
*/
|
120 |
-
public function testInheritanceMergeFromDefault()
|
121 |
-
{
|
122 |
-
$visitor = AAM::getUser();
|
123 |
-
$default = $visitor->getParent();
|
124 |
-
|
125 |
-
$object = $default->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
126 |
-
|
127 |
-
// Save access settings for the Default and make sure they are saved property
|
128 |
-
// Check if save returns positive result
|
129 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
130 |
-
|
131 |
-
// Save access setting for the Visitor and make sure they are saved property
|
132 |
-
$metabox = $visitor->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
133 |
-
$this->assertTrue($metabox->updateOptionItem('widgets|WP_Widget_Media_Image', false)->save());
|
134 |
-
|
135 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
136 |
-
$this->_resetSubjects();
|
137 |
-
|
138 |
-
$metabox = $visitor->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
139 |
-
$this->assertSame(
|
140 |
-
array(
|
141 |
-
'widgets|WP_Widget_Media_Video' => true,
|
142 |
-
'widgets|WP_Widget_Media_Image' => false
|
143 |
-
),
|
144 |
-
$metabox->getOption()
|
145 |
-
);
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* Test that access settings overwrite works as expected
|
150 |
-
*
|
151 |
-
* The expected result is lower Access Level overwrite access settings from the
|
152 |
-
* higher Access Level.
|
153 |
-
*
|
154 |
-
* A. Assert that access settings are stored properly for the parent subject;
|
155 |
-
* B. Assert that access settings are stored properly for the Visitor;
|
156 |
-
* C. Assert that access settings are overwritten properly on the Visitor Level;
|
157 |
-
*
|
158 |
-
* @return void
|
159 |
-
*
|
160 |
-
* @access public
|
161 |
-
* @version 6.0.0
|
162 |
-
*/
|
163 |
-
public function testInheritanceOverride()
|
164 |
-
{
|
165 |
-
$user = AAM::getUser();
|
166 |
-
$parent = $user->getParent();
|
167 |
-
|
168 |
-
$object = $parent->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
169 |
-
|
170 |
-
// Save access settings for the Default and make sure they are saved property
|
171 |
-
// Check if save returns positive result
|
172 |
-
$this->assertTrue($object->updateOptionItem('widgets|WP_Widget_Media_Video', true)->save());
|
173 |
-
|
174 |
-
// Save access setting for the Visitor and make sure they are saved property
|
175 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE, null, true);
|
176 |
-
$this->assertTrue($metabox->updateOptionItem('widgets|WP_Widget_Media_Video', false)->save());
|
177 |
-
|
178 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
179 |
-
$this->_resetSubjects();
|
180 |
-
|
181 |
-
$metabox = $user->getObject(AAM_Core_Object_Metabox::OBJECT_TYPE);
|
182 |
-
$this->assertSame(
|
183 |
-
array('widgets|WP_Widget_Media_Video' => false), $metabox->getOption()
|
184 |
-
);
|
185 |
-
}
|
186 |
-
|
187 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/NotFoundRedirect/Callback.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\NotFoundRedirect;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const REDIRECT_URL = 'https://aamplugin.com/redirect';
|
8 |
-
|
9 |
-
public static function redirectCallback()
|
10 |
-
{
|
11 |
-
header('Location: ' . self::REDIRECT_URL);
|
12 |
-
}
|
13 |
-
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/NotFoundRedirect/NotFoundRedirectTest.php
DELETED
@@ -1,141 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\NotFoundRedirect;
|
11 |
-
|
12 |
-
use AAM_Core_Config,
|
13 |
-
PHPUnit\Framework\TestCase,
|
14 |
-
AAM_Service_NotFoundRedirect,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait;
|
16 |
-
|
17 |
-
/**
|
18 |
-
* 404 Redirect service
|
19 |
-
*
|
20 |
-
* @package AAM\UnitTest
|
21 |
-
* @version 6.0.0
|
22 |
-
*/
|
23 |
-
class NotFoundRedirectTest extends TestCase
|
24 |
-
{
|
25 |
-
use ResetTrait;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Test the default 404 redirect
|
29 |
-
*
|
30 |
-
* AAM should not issue any redirect headers
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testDefault404Redirect()
|
38 |
-
{
|
39 |
-
global $wp_query;
|
40 |
-
|
41 |
-
// Force 404 path
|
42 |
-
$wp_query->is_404 = true;
|
43 |
-
$service = AAM_Service_NotFoundRedirect::getInstance();
|
44 |
-
|
45 |
-
// Reset any already sent "Location" headers. This way insure that no other
|
46 |
-
// redirect headers are sent
|
47 |
-
header('Location: empty');
|
48 |
-
|
49 |
-
$service->wp();
|
50 |
-
|
51 |
-
$this->assertContains('Location: empty', xdebug_get_headers());
|
52 |
-
|
53 |
-
// Reset to default
|
54 |
-
$wp_query->is_404 = null;
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Test redirect to the existing page
|
59 |
-
*
|
60 |
-
* @return void
|
61 |
-
*
|
62 |
-
* @access public
|
63 |
-
* @version 6.0.0
|
64 |
-
*/
|
65 |
-
public function testExistingPageLogoutRedirect()
|
66 |
-
{
|
67 |
-
global $wp_query;
|
68 |
-
|
69 |
-
// Set 404 config
|
70 |
-
AAM_Core_Config::set('frontend.404redirect.type', 'page');
|
71 |
-
AAM_Core_Config::set('frontend.404redirect.page', AAM_UNITTEST_PAGE_ID);
|
72 |
-
|
73 |
-
// Force 404 path
|
74 |
-
$wp_query->is_404 = true;
|
75 |
-
$service = AAM_Service_NotFoundRedirect::getInstance();
|
76 |
-
|
77 |
-
$service->wp();
|
78 |
-
|
79 |
-
$this->assertContains('Location: ' . get_page_link(AAM_UNITTEST_PAGE_ID), xdebug_get_headers());
|
80 |
-
|
81 |
-
// Reset to default
|
82 |
-
$wp_query->is_404 = null;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Test redirect to the defined URL
|
87 |
-
*
|
88 |
-
* @return void
|
89 |
-
*
|
90 |
-
* @access public
|
91 |
-
* @version 6.0.0
|
92 |
-
*/
|
93 |
-
public function testUrlLogoutRedirect()
|
94 |
-
{
|
95 |
-
global $wp_query;
|
96 |
-
|
97 |
-
// Set 404 config
|
98 |
-
AAM_Core_Config::set('frontend.404redirect.type', 'url');
|
99 |
-
AAM_Core_Config::set('frontend.404redirect.url', '/hello-world');
|
100 |
-
|
101 |
-
// Force 404 path
|
102 |
-
$wp_query->is_404 = true;
|
103 |
-
$service = AAM_Service_NotFoundRedirect::getInstance();
|
104 |
-
|
105 |
-
$service->wp();
|
106 |
-
|
107 |
-
$this->assertContains('Location: /hello-world', xdebug_get_headers());
|
108 |
-
|
109 |
-
// Reset to default
|
110 |
-
$wp_query->is_404 = null;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Test execution of the callback function as redirect
|
115 |
-
*
|
116 |
-
* @return void
|
117 |
-
*
|
118 |
-
* @access public
|
119 |
-
* @version 6.0.0
|
120 |
-
*/
|
121 |
-
public function testCallbackLogoutRedirect()
|
122 |
-
{
|
123 |
-
global $wp_query;
|
124 |
-
|
125 |
-
// Set 404 config
|
126 |
-
AAM_Core_Config::set('frontend.404redirect.type', 'callback');
|
127 |
-
AAM_Core_Config::set('frontend.404redirect.callback', 'AAM\\UnitTest\\Service\\NotFoundRedirect\\Callback::redirectCallback');
|
128 |
-
|
129 |
-
// Force 404 path
|
130 |
-
$wp_query->is_404 = true;
|
131 |
-
$service = AAM_Service_NotFoundRedirect::getInstance();
|
132 |
-
|
133 |
-
$service->wp();
|
134 |
-
|
135 |
-
$this->assertContains('Location: ' . Callback::REDIRECT_URL, xdebug_get_headers());
|
136 |
-
|
137 |
-
// Reset to default
|
138 |
-
$wp_query->is_404 = null;
|
139 |
-
}
|
140 |
-
|
141 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Route/RouteTest.php
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Route;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
WP_REST_Request,
|
14 |
-
AAM_Core_Config,
|
15 |
-
AAM_Service_Route,
|
16 |
-
AAM_Core_Object_Route,
|
17 |
-
PHPUnit\Framework\TestCase,
|
18 |
-
AAM\UnitTest\Libs\ResetTrait;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* API Routes service tests
|
22 |
-
*
|
23 |
-
* @package AAM\UnitTest
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class RouteTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait;
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Test that XML-PRC is disabled
|
32 |
-
*
|
33 |
-
* @return void
|
34 |
-
*
|
35 |
-
* @access public
|
36 |
-
* @version 6.0.0
|
37 |
-
*/
|
38 |
-
public function testDisabledXMLRPC()
|
39 |
-
{
|
40 |
-
AAM_Core_Config::set('core.settings.xmlrpc', false);
|
41 |
-
|
42 |
-
$this->assertFalse(apply_filters('xmlrpc_enabled', true));
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Test that RESTful API is disabled
|
47 |
-
*
|
48 |
-
* @return void
|
49 |
-
*
|
50 |
-
* @access public
|
51 |
-
* @version 6.0.0
|
52 |
-
*/
|
53 |
-
public function testDisabledRESTfulAPI()
|
54 |
-
{
|
55 |
-
AAM_Core_Config::set('core.settings.restful', false);
|
56 |
-
|
57 |
-
$error = apply_filters('rest_authentication_errors', null);
|
58 |
-
|
59 |
-
$this->assertEquals('WP_Error', get_class($error));
|
60 |
-
$this->assertEquals('RESTful API is disabled', $error->get_error_message());
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Assert that jwt token is generated for the authentication request
|
65 |
-
*
|
66 |
-
* @return void
|
67 |
-
*
|
68 |
-
* @access public
|
69 |
-
* @version 6.0.0
|
70 |
-
*/
|
71 |
-
public function testRestrictedRESTfulEndpoint()
|
72 |
-
{
|
73 |
-
global $wp;
|
74 |
-
|
75 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Route::OBJECT_TYPE);
|
76 |
-
|
77 |
-
// Restrict AAM authentication endpoint
|
78 |
-
$this->assertTrue(
|
79 |
-
$object->updateOptionItem('restful|/aam/v2/authenticate|post', true)->save()
|
80 |
-
);
|
81 |
-
|
82 |
-
// Register all the necessary hooks
|
83 |
-
|
84 |
-
$wp->query_vars['rest_route'] = true;
|
85 |
-
AAM_Service_Route::getInstance()->registerRouteControllers();
|
86 |
-
|
87 |
-
$server = rest_get_server();
|
88 |
-
|
89 |
-
$request = new WP_REST_Request('POST', '/aam/v2/authenticate');
|
90 |
-
$request->set_param('username', AAM_UNITTEST_USERNAME);
|
91 |
-
$request->set_param('password', AAM_UNITTEST_PASSWORD);
|
92 |
-
|
93 |
-
$error = $server->dispatch($request);
|
94 |
-
|
95 |
-
$this->assertEquals('WP_Error', get_class($error));
|
96 |
-
$this->assertEquals('Access Denied', $error->get_error_message());
|
97 |
-
}
|
98 |
-
|
99 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/SecureLogin/SecureLoginTest.php
DELETED
@@ -1,151 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\SecureLogin;
|
11 |
-
|
12 |
-
use AAM_Core_API,
|
13 |
-
AAM_Core_Config,
|
14 |
-
WP_Session_Tokens,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Secure login features
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class SecureLoginTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Test that "One Session Per User" works as expected
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testOneSessionPerUser()
|
37 |
-
{
|
38 |
-
// Enable "One Session Per User" feature
|
39 |
-
AAM_Core_Config::set('service.secureLogin.feature.singleSession', true);
|
40 |
-
|
41 |
-
// No need to generate Auth cookies
|
42 |
-
add_filter('send_auth_cookies', '__return_false');
|
43 |
-
|
44 |
-
// Define valid credentials
|
45 |
-
$creds = array(
|
46 |
-
'user_login' => AAM_UNITTEST_USERNAME,
|
47 |
-
'user_password' => AAM_UNITTEST_PASSWORD
|
48 |
-
);
|
49 |
-
|
50 |
-
// Sign-in user first time
|
51 |
-
$user = wp_signon($creds);
|
52 |
-
$this->assertEquals('WP_User', get_class($user));
|
53 |
-
|
54 |
-
// Now try to authenticate user again
|
55 |
-
$user = wp_signon($creds);
|
56 |
-
$this->assertEquals('WP_User', get_class($user));
|
57 |
-
|
58 |
-
// Finally verify that there is only one session persisted
|
59 |
-
$sessions = WP_Session_Tokens::get_instance($user->ID);
|
60 |
-
$this->assertCount(1, $sessions->get_all());
|
61 |
-
|
62 |
-
// Reset all sessions
|
63 |
-
$sessions->destroy_all();
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Test the "Brute Force Lockout" feature
|
68 |
-
*
|
69 |
-
* Authentication process has to return WP_Error if number of allowed attempts
|
70 |
-
* exceeded its limit
|
71 |
-
*
|
72 |
-
* @return void
|
73 |
-
*
|
74 |
-
* @access public
|
75 |
-
* @version 6.0.0
|
76 |
-
*/
|
77 |
-
public function testBruteForceLockout()
|
78 |
-
{
|
79 |
-
// Enable "Brute Force Lockout" feature
|
80 |
-
AAM_Core_Config::set('service.secureLogin.feature.bruteForceLockout', true);
|
81 |
-
|
82 |
-
// Force dummy user IP
|
83 |
-
$ip = '127.0.0.1';
|
84 |
-
$_SERVER['REMOTE_ADDR'] = $ip;
|
85 |
-
|
86 |
-
// Force to max out the number of attempts
|
87 |
-
set_transient('aam_failed_login_attempts_' . $ip, 50, time() + 10);
|
88 |
-
|
89 |
-
// No need to generate Auth cookies
|
90 |
-
add_filter('send_auth_cookies', '__return_false');
|
91 |
-
|
92 |
-
// Define valid credentials
|
93 |
-
$creds = array(
|
94 |
-
'user_login' => AAM_UNITTEST_USERNAME,
|
95 |
-
'user_password' => AAM_UNITTEST_PASSWORD
|
96 |
-
);
|
97 |
-
|
98 |
-
// Sign-in user first time
|
99 |
-
$user = wp_signon($creds);
|
100 |
-
|
101 |
-
$this->assertEquals('WP_Error', get_class($user));
|
102 |
-
$this->assertEquals('Exceeded maximum number for authentication attempts. Try again later.', $user->get_error_message());
|
103 |
-
|
104 |
-
// Also make sure that attempts counter was increased
|
105 |
-
$this->assertEquals(51, get_transient('aam_failed_login_attempts_' . $ip));
|
106 |
-
|
107 |
-
// Reset original state
|
108 |
-
delete_transient('aam_failed_login_attempts_' . $ip);
|
109 |
-
unset($_SERVER['REMOTE_ADDR']);
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Test that it fails to authenticate locked user
|
114 |
-
*
|
115 |
-
* @return void
|
116 |
-
*
|
117 |
-
* @access public
|
118 |
-
* @version 6.0.0
|
119 |
-
*/
|
120 |
-
public function testUserLockedStatus()
|
121 |
-
{
|
122 |
-
global $wpdb;
|
123 |
-
|
124 |
-
$result = $wpdb->update(
|
125 |
-
$wpdb->users, array('user_status' => 1), array('ID' => AAM_UNITTEST_JOHN_ID)
|
126 |
-
);
|
127 |
-
|
128 |
-
// Make sure that row is updated
|
129 |
-
$this->assertEquals(1, $result);
|
130 |
-
|
131 |
-
// No need to generate Auth cookies
|
132 |
-
add_filter('send_auth_cookies', '__return_false');
|
133 |
-
|
134 |
-
// Define valid credentials
|
135 |
-
$creds = array(
|
136 |
-
'user_login' => AAM_UNITTEST_USERNAME,
|
137 |
-
'user_password' => AAM_UNITTEST_PASSWORD
|
138 |
-
);
|
139 |
-
|
140 |
-
// Sign-in user first time
|
141 |
-
$user = wp_signon($creds);
|
142 |
-
$this->assertEquals('WP_Error', get_class($user));
|
143 |
-
$this->assertEquals('<strong>ERROR</strong>: User is locked. Contact website administrator.', $user->get_error_message());
|
144 |
-
|
145 |
-
// Restore user status
|
146 |
-
$result = $wpdb->update(
|
147 |
-
$wpdb->users, array('user_status' => 0), array('ID' => AAM_UNITTEST_JOHN_ID)
|
148 |
-
);
|
149 |
-
}
|
150 |
-
|
151 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Toolbar/MultipleRoleInheritanceTest.php
DELETED
@@ -1,179 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Toolbar;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Config,
|
14 |
-
AAM_Core_Object_Toolbar,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait,
|
17 |
-
AAM\UnitTest\Libs\AuthMultiRoleUserTrait,
|
18 |
-
AAM\UnitTest\Libs\MultiRoleOptionInterface;
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Test AAM access settings inheritance mechanism for multiple roles per user for
|
22 |
-
* the Admin Toolbar service
|
23 |
-
*
|
24 |
-
* Admin Toolbar is available only for authenticated users so no Visitors are tested
|
25 |
-
*
|
26 |
-
* @package AAM\UnitTest
|
27 |
-
* @version 6.0.0
|
28 |
-
*/
|
29 |
-
class MultipleRoleInheritanceTest extends TestCase implements MultiRoleOptionInterface
|
30 |
-
{
|
31 |
-
use ResetTrait,
|
32 |
-
AuthMultiRoleUserTrait;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Test that access settings are inherited from multiple parent roles
|
36 |
-
*
|
37 |
-
* This test is designed to verify that access settings are propagated property
|
38 |
-
* when there access settings defined for multiple parent roles.
|
39 |
-
*
|
40 |
-
* @return void
|
41 |
-
*
|
42 |
-
* @access public
|
43 |
-
* @version 6.0.0
|
44 |
-
*/
|
45 |
-
public function testInheritanceMergeFromMultipleRoles()
|
46 |
-
{
|
47 |
-
$user = AAM::getUser();
|
48 |
-
$role = $user->getParent();
|
49 |
-
|
50 |
-
// Make sure that we have parent roles defined properly
|
51 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
52 |
-
|
53 |
-
// Save access settings for the base role and iterate over each sibling and
|
54 |
-
// add additional settings
|
55 |
-
$object = $role->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
56 |
-
$this->assertTrue($object->updateOptionItem('new-page', true)->save());
|
57 |
-
|
58 |
-
foreach($role->getSiblings() as $i => $sibling) {
|
59 |
-
// Save access settings for each role and make sure they are saved property
|
60 |
-
// Check if save returns positive result
|
61 |
-
$this->assertTrue(
|
62 |
-
$sibling->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true)->updateOptionItem(
|
63 |
-
'new-page-' . ($i + 1), ($i % 2 ? true : false)
|
64 |
-
)->save()
|
65 |
-
);
|
66 |
-
}
|
67 |
-
|
68 |
-
// Reset internal AAM cache
|
69 |
-
$this->_resetSubjects();
|
70 |
-
|
71 |
-
// Assert that we have both roles merged result is as following
|
72 |
-
// Array (
|
73 |
-
// new-page => true,
|
74 |
-
// new-page-1 => false
|
75 |
-
// )
|
76 |
-
$option = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE)->getOption();
|
77 |
-
$this->assertSame(
|
78 |
-
array('new-page' => true, 'new-page-1' => false), $option
|
79 |
-
);
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Test that access settings are merged with default "deny" precedence correctly
|
84 |
-
*
|
85 |
-
* @return void
|
86 |
-
*
|
87 |
-
* @access public
|
88 |
-
* @version 6.0.0
|
89 |
-
*/
|
90 |
-
public function testInheritanceDenyPrecedenceFromMultipleRoles()
|
91 |
-
{
|
92 |
-
$user = AAM::getUser();
|
93 |
-
$role = $user->getParent();
|
94 |
-
|
95 |
-
// Make sure that we have parent roles defined properly
|
96 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
97 |
-
|
98 |
-
// Save access settings for the base role and iterate over each sibling and
|
99 |
-
// add additional settings
|
100 |
-
$this->assertTrue(
|
101 |
-
$role->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true)->updateOptionItem(
|
102 |
-
'new-page', true
|
103 |
-
)->save()
|
104 |
-
);
|
105 |
-
|
106 |
-
foreach($role->getSiblings() as $sibling) {
|
107 |
-
// Save access settings for each role and make sure they are saved property
|
108 |
-
// Check if save returns positive result
|
109 |
-
$this->assertTrue(
|
110 |
-
$sibling->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true)->updateOptionItem(
|
111 |
-
'new-page', false
|
112 |
-
)->save()
|
113 |
-
);
|
114 |
-
}
|
115 |
-
|
116 |
-
// Reset internal AAM cache
|
117 |
-
$this->_resetSubjects();
|
118 |
-
|
119 |
-
// Assert that we have both roles merged result is as following
|
120 |
-
// Array (
|
121 |
-
// new-page => true
|
122 |
-
// )
|
123 |
-
$option = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE)->getOption();
|
124 |
-
$this->assertSame(
|
125 |
-
array('new-page' => true), $option
|
126 |
-
);
|
127 |
-
}
|
128 |
-
|
129 |
-
/**
|
130 |
-
* Test that access settings are merged correctly with "allowed" precedence
|
131 |
-
* correctly
|
132 |
-
*
|
133 |
-
* @return void
|
134 |
-
* @version 6.0.0
|
135 |
-
*/
|
136 |
-
public function testInheritanceAllowPrecedenceFromMultipleRoles()
|
137 |
-
{
|
138 |
-
$user = AAM::getUser();
|
139 |
-
$role = $user->getParent();
|
140 |
-
|
141 |
-
// Make sure that we have parent roles defined properly
|
142 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($role));
|
143 |
-
|
144 |
-
// Save access settings for the base role and iterate over each sibling and
|
145 |
-
// add additional settings
|
146 |
-
$this->assertTrue(
|
147 |
-
$role->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true)->updateOptionItem(
|
148 |
-
'new-page', true
|
149 |
-
)->save()
|
150 |
-
);
|
151 |
-
|
152 |
-
foreach($role->getSiblings() as $sibling) {
|
153 |
-
// Save access settings for each role and make sure they are saved property
|
154 |
-
// Check if save returns positive result
|
155 |
-
$this->assertTrue(
|
156 |
-
$sibling->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true)->updateOptionItem(
|
157 |
-
'new-page', false
|
158 |
-
)->save()
|
159 |
-
);
|
160 |
-
}
|
161 |
-
|
162 |
-
// Override the default "deny" precedence
|
163 |
-
AAM_Core_Config::set(
|
164 |
-
sprintf('core.settings.%s.merge.preference', AAM_Core_Object_Toolbar::OBJECT_TYPE),
|
165 |
-
'allow'
|
166 |
-
);
|
167 |
-
|
168 |
-
// Reset internal AAM cache
|
169 |
-
$this->_resetSubjects();
|
170 |
-
|
171 |
-
// Assert that we have both roles merged result is as following
|
172 |
-
// Array (
|
173 |
-
// new-page => false
|
174 |
-
// )
|
175 |
-
$option = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE)->getOption();
|
176 |
-
$this->assertSame(array('new-page' => false), $option);
|
177 |
-
}
|
178 |
-
|
179 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Toolbar/SingleRoleInheritanceTest.php
DELETED
@@ -1,225 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Toolbar;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Core_Object_Toolbar,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test AAM access settings inheritance mechanism for the Toolbar service
|
20 |
-
*
|
21 |
-
* Toolbar is available only for authenticated users so no Visitors are tested
|
22 |
-
*
|
23 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
24 |
-
* @version 6.0.0
|
25 |
-
*/
|
26 |
-
class SingleRoleInheritanceTest extends TestCase
|
27 |
-
{
|
28 |
-
use ResetTrait,
|
29 |
-
AuthUserTrait;
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Test to insure that access settings are stored property on the User level
|
33 |
-
*
|
34 |
-
* @return void
|
35 |
-
*
|
36 |
-
* @access public
|
37 |
-
* @see AAM_Core_Subject_User::updateOption
|
38 |
-
* @version 6.0.0
|
39 |
-
*/
|
40 |
-
public function testSaveToolbarOption()
|
41 |
-
{
|
42 |
-
$user = AAM::getUser();
|
43 |
-
$object = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
44 |
-
|
45 |
-
// Check if save returns positive result
|
46 |
-
$this->assertTrue($object->updateOptionItem('new-page', true)->save());
|
47 |
-
|
48 |
-
// Read from the database saved values and assert that we have
|
49 |
-
// Array (
|
50 |
-
// index.php => true
|
51 |
-
// )
|
52 |
-
$option = $user->readOption(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
53 |
-
$this->assertSame(array('new-page' => true), $option);
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Test that access settings are inherited from the parent role property
|
58 |
-
*
|
59 |
-
* This test is designed to verify that access settings are propagated property
|
60 |
-
* when there is only one role assigned to a user.
|
61 |
-
*
|
62 |
-
* @return void
|
63 |
-
*
|
64 |
-
* @access public
|
65 |
-
* @version 6.0.0
|
66 |
-
*/
|
67 |
-
public function testInheritanceFromSingleRole()
|
68 |
-
{
|
69 |
-
$user = AAM::getUser();
|
70 |
-
$parent = $user->getParent();
|
71 |
-
$object = $parent->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
72 |
-
|
73 |
-
// Make sure that we have parent role defined
|
74 |
-
$this->assertEquals('AAM_Core_Subject_Role', get_class($parent));
|
75 |
-
|
76 |
-
// Save access settings for the role and make sure they are saved property
|
77 |
-
// Check if save returns positive result
|
78 |
-
$this->assertTrue($object->updateOptionItem('new-page', true)->save());
|
79 |
-
|
80 |
-
// Read from the database saved values and assert that we have
|
81 |
-
// Array (
|
82 |
-
// index.php => true
|
83 |
-
// )
|
84 |
-
$option = $parent->readOption(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
85 |
-
$this->assertSame(array('new-page' => true), $option);
|
86 |
-
|
87 |
-
// Finally verify that access settings are propagated property to the User
|
88 |
-
// Level
|
89 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
90 |
-
$this->assertSame(array('new-page' => true), $menu->getOption());
|
91 |
-
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
* Test that access settings are propagated and merged properly
|
95 |
-
*
|
96 |
-
* The test is designed to verify that access settings are propagated properly
|
97 |
-
* from the parent role and merged well with explicitly defined access settings on
|
98 |
-
* the User level.
|
99 |
-
*
|
100 |
-
* The expected result is to have combined array of access settings from the parent
|
101 |
-
* role and specific user.
|
102 |
-
*
|
103 |
-
* @return void
|
104 |
-
*
|
105 |
-
* @access public
|
106 |
-
* @version 6.0.0
|
107 |
-
*/
|
108 |
-
public function testInheritanceMergeFromSingleRole()
|
109 |
-
{
|
110 |
-
$user = AAM::getUser();
|
111 |
-
$parent = $user->getParent();
|
112 |
-
|
113 |
-
$object = $parent->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
114 |
-
|
115 |
-
// Save access settings for the role and make sure they are saved property
|
116 |
-
// Check if save returns positive result
|
117 |
-
$this->assertTrue($object->updateOptionItem('new-page', true)->save());
|
118 |
-
|
119 |
-
// Save access setting for the user and make sure they are saved property
|
120 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
121 |
-
$this->assertTrue($menu->updateOptionItem('new-post', false)->save());
|
122 |
-
|
123 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
124 |
-
$this->_resetSubjects();
|
125 |
-
|
126 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
127 |
-
$this->assertSame(
|
128 |
-
array('new-page' => true, 'new-post' => false),
|
129 |
-
$menu->getOption()
|
130 |
-
);
|
131 |
-
}
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Test that the full inheritance mechanism is working as expected
|
135 |
-
*
|
136 |
-
* Make sure that access settings are propagated and merged properly from the top
|
137 |
-
* (Default Level) to the bottom (User Level).
|
138 |
-
*
|
139 |
-
* @return void
|
140 |
-
*
|
141 |
-
* @access public
|
142 |
-
* @version 6.0.0
|
143 |
-
*/
|
144 |
-
public function testFullInheritanceChainSingeRole()
|
145 |
-
{
|
146 |
-
$user = AAM::getUser();
|
147 |
-
$role = $user->getParent();
|
148 |
-
$default = $role->getParent();
|
149 |
-
|
150 |
-
$userMenu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
151 |
-
$roleMenu = $role->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
152 |
-
$defaultMenu = $default->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
153 |
-
|
154 |
-
// Save access settings for all subjects
|
155 |
-
$this->assertTrue($userMenu->updateOptionItem('new-post', true)->save());
|
156 |
-
$this->assertTrue($roleMenu->updateOptionItem('new-page', true)->save());
|
157 |
-
$this->assertTrue($defaultMenu->updateOptionItem('new-media', true)->save());
|
158 |
-
|
159 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
160 |
-
$this->_resetSubjects();
|
161 |
-
|
162 |
-
// All settings has to be merged into one array
|
163 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
164 |
-
$this->assertSame(
|
165 |
-
array(
|
166 |
-
'new-media' => true,
|
167 |
-
'new-page' => true,
|
168 |
-
'new-post' => true
|
169 |
-
),
|
170 |
-
$menu->getOption()
|
171 |
-
);
|
172 |
-
}
|
173 |
-
|
174 |
-
/**
|
175 |
-
* Test that access settings overwrite works as expected
|
176 |
-
*
|
177 |
-
* The expected result is lower Access Level overwrite access settings from the
|
178 |
-
* higher Access Level.
|
179 |
-
*
|
180 |
-
* @return void
|
181 |
-
*
|
182 |
-
* @access public
|
183 |
-
* @version 6.0.0
|
184 |
-
*/
|
185 |
-
public function testInheritanceOverrideForSingleRole()
|
186 |
-
{
|
187 |
-
$user = AAM::getUser();
|
188 |
-
$parent = $user->getParent();
|
189 |
-
|
190 |
-
$object = $parent->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
191 |
-
|
192 |
-
// Save access settings for the role and make sure they are saved property
|
193 |
-
// Check if save returns positive result
|
194 |
-
$this->assertTrue($object->updateOptionItem('new-post', true)->save());
|
195 |
-
|
196 |
-
// Save access setting for the user and make sure they are saved property
|
197 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE, null, true);
|
198 |
-
$this->assertTrue($menu->updateOptionItem('new-post', false)->save());
|
199 |
-
|
200 |
-
// Reset cache and try to kick-in the inheritance mechanism
|
201 |
-
$this->_resetSubjects();
|
202 |
-
|
203 |
-
$menu = $user->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
204 |
-
$this->assertSame(array('new-post' => false), $menu->getOption());
|
205 |
-
}
|
206 |
-
|
207 |
-
public function testToolbarRendering()
|
208 |
-
{
|
209 |
-
$_SERVER['HTTP_HOST'] = 'aamplugin.com';
|
210 |
-
$_SERVER['REQUEST_URI'] = '/wp-admin';
|
211 |
-
|
212 |
-
// Restrict access to the Log Out menu and make sure it is not rendered
|
213 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Toolbar::OBJECT_TYPE);
|
214 |
-
$this->assertTrue($object->updateOptionItem('logout', true)->save());
|
215 |
-
|
216 |
-
ob_start();
|
217 |
-
_wp_admin_bar_init();
|
218 |
-
wp_admin_bar_render();
|
219 |
-
$content = ob_get_contents();
|
220 |
-
ob_end_clean();
|
221 |
-
|
222 |
-
$this->assertEquals(false, strpos($content, "id='wp-admin-bar-logout'"));
|
223 |
-
}
|
224 |
-
|
225 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Uri/Callback.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace AAM\UnitTest\Service\Uri;
|
4 |
-
|
5 |
-
class Callback
|
6 |
-
{
|
7 |
-
const REDIRECT_URL = 'https://aamplugin.com/redirect';
|
8 |
-
|
9 |
-
public static function redirectCallback()
|
10 |
-
{
|
11 |
-
header('Location: ' . self::REDIRECT_URL);
|
12 |
-
}
|
13 |
-
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/Uri/UriTest.php
DELETED
@@ -1,177 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\Uri;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
AAM_Service_Uri,
|
14 |
-
AAM_Core_Object_Uri,
|
15 |
-
PHPUnit\Framework\TestCase,
|
16 |
-
AAM\UnitTest\Libs\ResetTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* URI Access service
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class UriTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Test default "Access Denied" message
|
30 |
-
*
|
31 |
-
* @return void
|
32 |
-
*
|
33 |
-
* @access public
|
34 |
-
* @version 6.0.0
|
35 |
-
*/
|
36 |
-
public function testAccessDeniedMessage()
|
37 |
-
{
|
38 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
39 |
-
$result = $object->updateOptionItem('/hello-world', array(
|
40 |
-
'type' => 'default',
|
41 |
-
'action' => null
|
42 |
-
))->save();
|
43 |
-
|
44 |
-
$this->assertTrue($result);
|
45 |
-
|
46 |
-
// Override the default handlers so we can suppress die exit
|
47 |
-
add_filter('wp_die_handler', function() {
|
48 |
-
return function($message, $title) {
|
49 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
50 |
-
};
|
51 |
-
}, PHP_INT_MAX);
|
52 |
-
$_SERVER['REQUEST_URI'] = '/hello-world';
|
53 |
-
|
54 |
-
ob_start();
|
55 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
56 |
-
$content = ob_get_contents();
|
57 |
-
ob_end_clean();
|
58 |
-
|
59 |
-
$this->assertStringContainsString('Access Denied', $content);
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Test custom wp_die message
|
64 |
-
*
|
65 |
-
* @return void
|
66 |
-
*
|
67 |
-
* @access public
|
68 |
-
* @version 6.0.0
|
69 |
-
*/
|
70 |
-
public function testCustomMessage()
|
71 |
-
{
|
72 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
73 |
-
$result = $object->updateOptionItem('/hello-world', array(
|
74 |
-
'type' => 'message',
|
75 |
-
'action' => 'This is not allowed'
|
76 |
-
))->save();
|
77 |
-
|
78 |
-
$this->assertTrue($result);
|
79 |
-
|
80 |
-
// Override the default handlers so we can suppress die exit
|
81 |
-
add_filter('wp_die_handler', function() {
|
82 |
-
return function($message, $title) {
|
83 |
-
_default_wp_die_handler($message, $title, array('exit' => false));
|
84 |
-
};
|
85 |
-
}, PHP_INT_MAX);
|
86 |
-
$_SERVER['REQUEST_URI'] = '/hello-world';
|
87 |
-
|
88 |
-
ob_start();
|
89 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
90 |
-
$content = ob_get_contents();
|
91 |
-
ob_end_clean();
|
92 |
-
|
93 |
-
$this->assertStringContainsString('This is not allowed', $content);
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Test redirect to the custom page
|
98 |
-
*
|
99 |
-
* @return void
|
100 |
-
*
|
101 |
-
* @access public
|
102 |
-
* @version 6.0.0
|
103 |
-
*/
|
104 |
-
public function testRedirectToExistingPage()
|
105 |
-
{
|
106 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
107 |
-
$result = $object->updateOptionItem('/hello-world', array(
|
108 |
-
'type' => 'page',
|
109 |
-
'action' => AAM_UNITTEST_PAGE_ID
|
110 |
-
))->save();
|
111 |
-
|
112 |
-
$this->assertTrue($result);
|
113 |
-
|
114 |
-
$_SERVER['REQUEST_URI'] = '/hello-world';
|
115 |
-
|
116 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
117 |
-
|
118 |
-
$this->assertContains(
|
119 |
-
'Location: ' . get_page_link(AAM_UNITTEST_PAGE_ID), xdebug_get_headers()
|
120 |
-
);
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Test redirect to the local URL
|
125 |
-
*
|
126 |
-
* @return void
|
127 |
-
*
|
128 |
-
* @access public
|
129 |
-
* @version 6.0.0
|
130 |
-
*/
|
131 |
-
public function testRedirectToUrl()
|
132 |
-
{
|
133 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
134 |
-
$result = $object->updateOptionItem('/hello-world', array(
|
135 |
-
'type' => 'url',
|
136 |
-
'action' => '/another-page'
|
137 |
-
))->save();
|
138 |
-
|
139 |
-
$this->assertTrue($result);
|
140 |
-
|
141 |
-
$_SERVER['REQUEST_URI'] = '/hello-world';
|
142 |
-
|
143 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
144 |
-
|
145 |
-
$this->assertContains(
|
146 |
-
'Location: /another-page', xdebug_get_headers()
|
147 |
-
);
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Test trigger of the callback function
|
152 |
-
*
|
153 |
-
* @return void
|
154 |
-
*
|
155 |
-
* @access public
|
156 |
-
* @version 6.0.0
|
157 |
-
*/
|
158 |
-
public function testTriggerCallback()
|
159 |
-
{
|
160 |
-
$object = AAM::getUser()->getObject(AAM_Core_Object_Uri::OBJECT_TYPE);
|
161 |
-
$result = $object->updateOptionItem('/hello-world', array(
|
162 |
-
'type' => 'callback',
|
163 |
-
'action' => 'AAM\\UnitTest\\Service\\Uri\\Callback::redirectCallback'
|
164 |
-
))->save();
|
165 |
-
|
166 |
-
$this->assertTrue($result);
|
167 |
-
|
168 |
-
$_SERVER['REQUEST_URI'] = '/hello-world';
|
169 |
-
|
170 |
-
AAM_Service_Uri::getInstance()->authorizeUri();
|
171 |
-
|
172 |
-
$this->assertContains(
|
173 |
-
'Location: ' . Callback::REDIRECT_URL, xdebug_get_headers()
|
174 |
-
);
|
175 |
-
}
|
176 |
-
|
177 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/Service/UserLevelFilter/UserLevelFilterTest.php
DELETED
@@ -1,151 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
namespace AAM\UnitTest\Service\AdminMenu;
|
11 |
-
|
12 |
-
use AAM,
|
13 |
-
WP_User_Query,
|
14 |
-
PHPUnit\Framework\TestCase,
|
15 |
-
AAM\UnitTest\Libs\ResetTrait,
|
16 |
-
AAM\UnitTest\Libs\AuthManagerUserTrait;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Test User Level Filter service
|
20 |
-
*
|
21 |
-
* @package AAM\UnitTest
|
22 |
-
* @version 6.0.0
|
23 |
-
*/
|
24 |
-
class UserLevelFilterTest extends TestCase
|
25 |
-
{
|
26 |
-
use ResetTrait,
|
27 |
-
AuthManagerUserTrait;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Test that only allowed roles are returned
|
31 |
-
*
|
32 |
-
* @return void
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
* @version 6.0.0
|
36 |
-
*/
|
37 |
-
public function testEditableRoles()
|
38 |
-
{
|
39 |
-
require_once ABSPATH . '/wp-admin/includes/user.php';
|
40 |
-
|
41 |
-
$roles = get_editable_roles();
|
42 |
-
|
43 |
-
$this->assertFalse(array_key_exists('administrator', $roles));
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Test that restricted roles are added to the "excluded" list of roles during
|
48 |
-
* search
|
49 |
-
*
|
50 |
-
* @return void
|
51 |
-
*
|
52 |
-
* @access public
|
53 |
-
* @version 6.0.0
|
54 |
-
*/
|
55 |
-
public function testPrepareUserQuery()
|
56 |
-
{
|
57 |
-
$query = new WP_User_Query(array(
|
58 |
-
'search' => 'a'
|
59 |
-
));
|
60 |
-
|
61 |
-
$this->assertEquals(array('administrator'), $query->query_vars['role__not_in']);
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Test that top User List table view does not have restricted roles listed
|
66 |
-
*
|
67 |
-
* @return void
|
68 |
-
*
|
69 |
-
* @access public
|
70 |
-
* @version 6.0.0
|
71 |
-
*/
|
72 |
-
public function testListTableViews()
|
73 |
-
{
|
74 |
-
if (!isset($GLOBALS['hook_suffix'])) {
|
75 |
-
$GLOBALS['hook_suffix'] = 'users';
|
76 |
-
}
|
77 |
-
|
78 |
-
require_once ABSPATH . 'wp-admin/includes/admin.php';
|
79 |
-
|
80 |
-
$table = _get_list_table( 'WP_Users_List_Table' , array('screen' => 'users'));
|
81 |
-
|
82 |
-
ob_start();
|
83 |
-
$table->views();
|
84 |
-
$content = ob_get_contents();
|
85 |
-
ob_end_clean();
|
86 |
-
|
87 |
-
$this->assertFalse(strpos($content, "class='administrator'"));
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Test that subadmin is allowed to manage users with lower user level
|
92 |
-
*
|
93 |
-
* @return void
|
94 |
-
*
|
95 |
-
* @access public
|
96 |
-
* @version 6.0.0
|
97 |
-
*/
|
98 |
-
public function testAllowedUserEdit()
|
99 |
-
{
|
100 |
-
$this->assertTrue(current_user_can('edit_user', AAM_UNITTEST_JOHN_ID));
|
101 |
-
}
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Test that subadmin is not allowed to manage users with higher user level
|
105 |
-
*
|
106 |
-
* @return void
|
107 |
-
*
|
108 |
-
* @access public
|
109 |
-
* @version 6.0.0
|
110 |
-
*/
|
111 |
-
public function testNotAllowedUserEdit()
|
112 |
-
{
|
113 |
-
$this->assertFalse(current_user_can('edit_user', AAM_UNITTEST_AUTH_USER_ID));
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Test that subadmin is allowed to manage users with the same user level
|
118 |
-
*
|
119 |
-
* @return void
|
120 |
-
*
|
121 |
-
* @access public
|
122 |
-
* @version 6.0.0
|
123 |
-
*/
|
124 |
-
public function testAllowedSameLevelUserEdit()
|
125 |
-
{
|
126 |
-
$this->assertTrue(
|
127 |
-
current_user_can('edit_user', AAM_UNITTEST_AUTH_SUBADMIN2_USER_ID)
|
128 |
-
);
|
129 |
-
}
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Test that subadmin is not allowed to manage users with the same user level
|
133 |
-
*
|
134 |
-
* @return void
|
135 |
-
*
|
136 |
-
* @access public
|
137 |
-
* @version 6.0.0
|
138 |
-
*/
|
139 |
-
public function testNotAllowedSameLevelUserEdit()
|
140 |
-
{
|
141 |
-
// Fake the un assigned `manage_same_user_level`
|
142 |
-
//wp_get_current_user()->caps['manage_same_user_level'] = false;
|
143 |
-
$user = AAM::getUser()->getPrincipal();
|
144 |
-
$user->caps['manage_same_user_level'] = false;
|
145 |
-
|
146 |
-
$this->assertFalse(
|
147 |
-
current_user_can('edit_user', AAM_UNITTEST_AUTH_SUBADMIN2_USER_ID)
|
148 |
-
);
|
149 |
-
}
|
150 |
-
|
151 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/bootstrap.php
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Make sure that path to the PHPUnit is included in the PHP.ini include_path as well
|
5 |
-
* as PHPUnit is installed on your machine
|
6 |
-
*/
|
7 |
-
|
8 |
-
// Autoloader for the PHPUnit Framework
|
9 |
-
spl_autoload_register(function ($classname) {
|
10 |
-
$filepath = null;
|
11 |
-
|
12 |
-
if (strpos($classname, 'PHPUnit') === 0) {
|
13 |
-
$filepath = __DIR__ . '\\' . $classname . '.php';
|
14 |
-
} elseif (strpos($classname, 'AAM\UnitTest') === 0) {
|
15 |
-
$filepath = __DIR__ . str_replace(array('AAM\UnitTest', '\\'), array('', '/'), $classname) . '.php';
|
16 |
-
}
|
17 |
-
|
18 |
-
if ($filepath && file_exists($filepath)) {
|
19 |
-
require $filepath;
|
20 |
-
}
|
21 |
-
});
|
22 |
-
|
23 |
-
// Load the WordPress library.
|
24 |
-
require_once dirname(__DIR__) . '/../../../wp-load.php';
|
25 |
-
|
26 |
-
// Very important to allow to test headers
|
27 |
-
ob_start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|