move initial capabilities from init hook to activation hook
This commit is contained in:
parent
b0f7c3b1ad
commit
66481113d4
|
@ -4,7 +4,7 @@ namespace Tainacan;
|
||||||
use Tainacan\Repositories\Repository;
|
use Tainacan\Repositories\Repository;
|
||||||
|
|
||||||
class Capabilities {
|
class Capabilities {
|
||||||
protected $defaults = [
|
public $defaults = [
|
||||||
"tainacan-collection"=> [
|
"tainacan-collection"=> [
|
||||||
"administrator"=> [
|
"administrator"=> [
|
||||||
"delete_posts",
|
"delete_posts",
|
||||||
|
@ -275,7 +275,6 @@ class Capabilities {
|
||||||
* Register hooks
|
* Register hooks
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
add_action('init', array(&$this, 'init'), 11);
|
|
||||||
add_action('tainacan-insert-tainacan-collection', array(&$this, 'new_collection'));
|
add_action('tainacan-insert-tainacan-collection', array(&$this, 'new_collection'));
|
||||||
|
|
||||||
add_action('tainacan-add-collection-moderators', array(&$this, 'add_moderators'), 10, 2);
|
add_action('tainacan-add-collection-moderators', array(&$this, 'add_moderators'), 10, 2);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Tainacan\Capabilities;
|
|
||||||
|
|
||||||
const ENTITIES_DIR = __DIR__ . '/entities/';
|
const ENTITIES_DIR = __DIR__ . '/entities/';
|
||||||
const FIELD_TYPES_DIR = __DIR__ . '/field-types/';
|
const FIELD_TYPES_DIR = __DIR__ . '/field-types/';
|
||||||
const FILTER_TYPES_DIR = __DIR__ . '/filter-types/';
|
const FILTER_TYPES_DIR = __DIR__ . '/filter-types/';
|
||||||
|
@ -109,6 +107,4 @@ $Tainacan_Terms = new \Tainacan\Repositories\Terms();
|
||||||
global $Tainacan_Logs;
|
global $Tainacan_Logs;
|
||||||
$Tainacan_Logs = new \Tainacan\Repositories\Logs();
|
$Tainacan_Logs = new \Tainacan\Repositories\Logs();
|
||||||
|
|
||||||
new Capabilities();
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -25,6 +25,10 @@ function tnc_enable_dev_wp_interface() {
|
||||||
//return defined('TNC_ENABLE_DEV_WP_INTERFACE') && true === TNC_ENABLE_DEV_WP_INTERFACE ? true : false;
|
//return defined('TNC_ENABLE_DEV_WP_INTERFACE') && true === TNC_ENABLE_DEV_WP_INTERFACE ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global $Tainacan_Capabilities;
|
||||||
|
$Tainacan_Capabilities = new \Tainacan\Capabilities();
|
||||||
|
register_activation_hook( __FILE__, array( $Tainacan_Capabilities, 'init' ) );
|
||||||
|
|
||||||
// TODO move it somewhere else?
|
// TODO move it somewhere else?
|
||||||
require_once('admin/class-tainacan-admin.php');
|
require_once('admin/class-tainacan-admin.php');
|
||||||
global $Tainacan_Admin;
|
global $Tainacan_Admin;
|
||||||
|
|
|
@ -22,6 +22,9 @@ require_once $_tests_dir . '/includes/functions.php';
|
||||||
*/
|
*/
|
||||||
function _manually_load_plugin() {
|
function _manually_load_plugin() {
|
||||||
require dirname( dirname( __FILE__ ) ) . '/src/tainacan.php';
|
require dirname( dirname( __FILE__ ) ) . '/src/tainacan.php';
|
||||||
|
add_action('plugins_loaded', function() {
|
||||||
|
do_action('activate_' . substr(dirname( dirname( __FILE__ ) ), 1) . '/src/tainacan.php');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tainacan\Tests;
|
||||||
|
use Tainacan\Repositories\Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DefaultCapabilities
|
||||||
|
*
|
||||||
|
* @package Test_Tainacan
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sample test case.
|
||||||
|
*/
|
||||||
|
class DefaultCapabilities extends TAINACAN_UnitTestCase {
|
||||||
|
|
||||||
|
|
||||||
|
function test_capabilities_present() {
|
||||||
|
|
||||||
|
global $Tainacan_Capabilities;
|
||||||
|
$c = new \Tainacan\Entities\Collection();
|
||||||
|
$caps = $c->get_capabilities();
|
||||||
|
|
||||||
|
|
||||||
|
$defaults_caps = $Tainacan_Capabilities->defaults;
|
||||||
|
|
||||||
|
foreach ($defaults_caps as $post_type => $wp_append_roles) {
|
||||||
|
if($post_type == 'tainacan-items') continue;
|
||||||
|
$entity = Repository::get_entity_by_post_type($post_type);
|
||||||
|
$entity_cap = $entity->get_capabilities();
|
||||||
|
|
||||||
|
foreach ($wp_append_roles as $role_name => $caps) {
|
||||||
|
$role = get_role($role_name);
|
||||||
|
|
||||||
|
$new_user = $this->factory()->user->create(array( 'role' => $role_name ));
|
||||||
|
wp_set_current_user($new_user);
|
||||||
|
|
||||||
|
foreach ($caps as $cap) {
|
||||||
|
$this->assertTrue(current_user_can($entity_cap->$cap));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue