-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
532d9ab
commit ca6d06b
Showing
4 changed files
with
183 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Class file for the Accessibility Checker plugin. | ||
* | ||
* @package Accessibility_Checker | ||
*/ | ||
|
||
namespace EDECU\Inc; | ||
|
||
/** | ||
* Class Plugin | ||
* | ||
* Main plugin functionality class. | ||
*/ | ||
class Plugin { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
// Intentionally left blank. | ||
} | ||
|
||
/** | ||
* Initialize the plugin. | ||
* | ||
* Registers activation and deactivation hooks, and adds action to load text domain. | ||
*/ | ||
public function init() { | ||
register_activation_hook( __FILE__, array( $this, 'activate' ) ); | ||
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); | ||
add_action( 'init', array( $this, 'load_textdomain' ) ); | ||
} | ||
|
||
/** | ||
* Handles tasks to perform upon plugin activation. | ||
* | ||
* Adds the 'upload_files' capability to the 'contributor' role. | ||
*/ | ||
public function activate() { | ||
$contributor = get_role( 'contributor' ); | ||
if ( null !== $contributor ) { | ||
$contributor->add_cap( 'upload_files' ); | ||
} | ||
} | ||
|
||
/** | ||
* Handles tasks to perform upon plugin deactivation. | ||
* | ||
* Removes the 'upload_files' capability from the 'contributor' role. | ||
*/ | ||
public function deactivate() { | ||
$contributor = get_role( 'contributor' ); | ||
if ( null !== $contributor ) { | ||
$contributor->remove_cap( 'upload_files' ); | ||
} | ||
} | ||
|
||
/** | ||
* Load the plugin text domain for translation. | ||
*/ | ||
public function load_textdomain() { | ||
load_plugin_textdomain( 'enable-contributor-uploads', false, basename( __DIR__ ) . '/languages' ); | ||
} | ||
|
||
/** | ||
* Handles tasks to perform upon plugin uninstallation. | ||
* | ||
* Removes the 'upload_files' capability from the 'contributor' role. | ||
* Note: This method should be called statically and is intended for registration with register_uninstall_hook. | ||
*/ | ||
public static function uninstall() { | ||
$contributor = get_role( 'contributor' ); | ||
if ( null !== $contributor ) { | ||
$contributor->remove_cap( 'upload_files' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Class EDECU_Plugin_Test | ||
* | ||
* @package Enable_Contributor_Uploads | ||
*/ | ||
|
||
use EDECU\Inc\Plugin; | ||
|
||
/** | ||
* Plugin test case. | ||
*/ | ||
class EDECU_Plugin_Test extends WP_UnitTestCase { | ||
|
||
/** | ||
* Plugin instance. | ||
* | ||
* @var Plugin | ||
*/ | ||
private $plugin; | ||
|
||
/** | ||
* Test setup. | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
$this->plugin = new Plugin(); | ||
} | ||
|
||
/** | ||
* Test teardown. | ||
*/ | ||
public function tearDown() { | ||
parent::tearDown(); | ||
unset( $this->plugin ); | ||
} | ||
|
||
/** | ||
* Test initialization of the plugin. | ||
*/ | ||
public function test_init() { | ||
// Simulate the plugin initialization. | ||
$this->plugin->init(); | ||
|
||
// Assert that the textdomain is loaded. | ||
$this->assertTrue( is_textdomain_loaded( 'enable-contributor-uploads' ), 'Text domain should be loaded' ); | ||
} | ||
|
||
/** | ||
* Test plugin activation. | ||
*/ | ||
public function test_activate() { | ||
// Activate the plugin. | ||
$this->plugin->activate(); | ||
|
||
// Retrieve the 'contributor' role. | ||
$contributor = get_role( 'contributor' ); | ||
|
||
// Assert that 'upload_files' capability is added to 'contributor' role. | ||
$this->assertTrue( $contributor->has_cap( 'upload_files' ), 'Contributor role should have the upload_files capability after activation' ); | ||
} | ||
|
||
/** | ||
* Test plugin deactivation. | ||
*/ | ||
public function test_deactivate() { | ||
// First, activate the plugin to ensure 'contributor' has the 'upload_files' capability. | ||
$this->plugin->activate(); | ||
|
||
// Then, deactivate the plugin. | ||
$this->plugin->deactivate(); | ||
|
||
// Retrieve the 'contributor' role again. | ||
$contributor = get_role( 'contributor' ); | ||
|
||
// Assert that 'upload_files' capability is removed from 'contributor' role. | ||
$this->assertFalse( $contributor->has_cap( 'upload_files' ), 'Contributor role should not have the upload_files capability after deactivation' ); | ||
} | ||
|
||
/** | ||
* Test plugin uninstallation. | ||
*/ | ||
public function test_uninstall() { | ||
// Simulate plugin uninstallation. | ||
Plugin::uninstall(); | ||
|
||
// Retrieve the 'contributor' role. | ||
$contributor = get_role( 'contributor' ); | ||
|
||
// Assert that 'upload_files' capability is removed from 'contributor' role. | ||
$this->assertFalse( $contributor->has_cap( 'upload_files' ), 'Contributor role should not have the upload_files capability after uninstallation' ); | ||
} | ||
} |