mirror of
https://github.com/KevinMidboe/rohnenedre.git
synced 2025-12-07 20:09:02 +00:00
Initial commit. State 04.2021.
This commit is contained in:
27
wp-content/plugins/wpclef/tests/bootstrap.php
Normal file
27
wp-content/plugins/wpclef/tests/bootstrap.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Bootstrap the plugin unit testing environment.
|
||||
*
|
||||
* Edit 'active_plugins' setting below to point to your main plugin file.
|
||||
*
|
||||
* @package wordpress-plugin-tests
|
||||
*/
|
||||
|
||||
// Activates this plugin in WordPress so it can be tested.
|
||||
$GLOBALS['wp_tests_options'] = array(
|
||||
'active_plugins' => array( 'wpclef/wpclef.php' ),
|
||||
);
|
||||
|
||||
define('BASE_TEST_DIR', dirname(dirname(__FILE__)));
|
||||
define('CLEF_TESTING', true);
|
||||
|
||||
// If the develop repo location is defined (as WP_DEVELOP_DIR), use that
|
||||
// location. Otherwise, we'll just assume that this plugin is installed in a
|
||||
// WordPress develop SVN checkout.
|
||||
|
||||
if( false !== getenv( 'WP_TESTS_DIR' ) ) {
|
||||
require getenv( 'WP_TESTS_DIR' ) . '/tests/phpunit/includes/bootstrap.php';
|
||||
} else {
|
||||
require '../../../../tests/phpunit/includes/bootstrap.php';
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests to test that that testing framework is testing tests. Meta, huh?
|
||||
*
|
||||
* @package wordpress-plugins-tests
|
||||
*/
|
||||
require_once BASE_TEST_DIR . '/includes/class.clef-setup.php';
|
||||
require_once BASE_TEST_DIR . '/includes/class.clef-utils.php';
|
||||
require_once BASE_TEST_DIR . '/includes/class.clef-internal-settings.php';
|
||||
|
||||
class WP_Test_InternalSettings_Passwords_Disabled_For_User extends WP_UnitTestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->settings = ClefInternalSettings::start();
|
||||
$this->settings->set('clef_settings_app_id', 'test_app_id');
|
||||
$this->settings->set('clef_settings_app_secret', 'test_app_secret');
|
||||
$this->user = get_user_by('id', $this->factory->user->create());
|
||||
}
|
||||
|
||||
function test_no_passwords_disabled() {
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
function test_all_passwords_disabled() {
|
||||
$this->settings->set('clef_password_settings_force', true);
|
||||
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
function test_passwords_disabled_for_clef_users() {
|
||||
$this->settings->set('clef_password_settings_disable_passwords', true);
|
||||
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
update_user_meta($this->user->ID, 'clef_id', '1234567890');
|
||||
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
function test_passwords_disabled_for_role() {
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', '');
|
||||
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('subscriber');
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Contributor');
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('contributor');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Author');
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('author');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Editor');
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('editor');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Administrator');
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('administrator');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Super Administrator');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
function test_passwords_disabled_for_custom_role() {
|
||||
$custom_role = add_role(
|
||||
'customrole4u',
|
||||
'Test Custom Role',
|
||||
array(
|
||||
'read' => true, // true allows this capability
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => false, // Use false to explicitly deny
|
||||
)
|
||||
);
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_passwords_custom_role_customrole4u', 1);
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->add_role('customrole4u');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
|
||||
$this->user->remove_role('customrole4u');
|
||||
$this->assertFalse($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that if passwords are disabled for both a regular role (and up)
|
||||
* and a custom role, no conflict occurs that could return the
|
||||
* wrong result.
|
||||
*
|
||||
*/
|
||||
function test_passwords_disabled_for_custom_role_and_regular_role() {
|
||||
$custom_role = add_role(
|
||||
'customrole4u',
|
||||
'Test Custom Role',
|
||||
array(
|
||||
'read' => true, // true allows this capability
|
||||
'edit_posts' => true,
|
||||
'delete_posts' => false, // Use false to explicitly deny
|
||||
)
|
||||
);
|
||||
|
||||
$this->settings->set('clef_password_settings_disable_passwords_custom_role_customrole4u', 1);
|
||||
$this->settings->set('clef_password_settings_disable_certain_passwords', 'Subscriber');
|
||||
|
||||
$this->user->add_role('customrole4u');
|
||||
$this->assertTrue($this->settings->passwords_are_disabled_for_user($this->user));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests to test that that testing framework is testing tests. Meta, huh?
|
||||
*
|
||||
* @package wordpress-plugins-tests
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../bootstrap.php';
|
||||
require_once BASE_TEST_DIR . '/clef-require.php';
|
||||
Clef::start();
|
||||
require_once BASE_TEST_DIR . '/includes/class.clef-session.php';
|
||||
require_once BASE_TEST_DIR . '/includes/class.clef-login.php';
|
||||
|
||||
class WP_Test_Login_Disable_Passwords extends WP_UnitTestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->settings = ClefInternalSettings::start();
|
||||
$this->settings->set('clef_settings_app_id', 'test_app_id');
|
||||
$this->settings->set('clef_settings_app_secret', 'test_app_secret');
|
||||
$this->user = get_user_by('id', $this->factory->user->create());
|
||||
|
||||
|
||||
$this->login = ClefLogin::start($this->settings);
|
||||
|
||||
|
||||
$this->settings->set('clef_password_settings_force', true);
|
||||
global $_POST;
|
||||
$_POST['pwd'] = 'password';
|
||||
}
|
||||
|
||||
function test_valid_override() {
|
||||
global $_POST;
|
||||
|
||||
$override = 'test';
|
||||
$this->settings->set('clef_override_settings_key', $override);
|
||||
$_POST = array( 'override' => $override );
|
||||
|
||||
$this->assertEquals($this->user, $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
function test_invalid_override() {
|
||||
global $_POST;
|
||||
|
||||
$override = 'test';
|
||||
$this->settings->set('clef_override_settings_key', $override);
|
||||
$_POST = array( 'override' => 'bad');
|
||||
|
||||
$this->assertInstanceOf('WP_Error', $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
function test_disabled() {
|
||||
$this->assertInstanceOf('WP_Error', $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
function test_empty_post() {
|
||||
global $_POST;
|
||||
$_POST = array();
|
||||
|
||||
$this->assertInstanceOf('WP_Error', $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
function test_xml_disabled() {
|
||||
define('XMLRPC_REQUEST', true);
|
||||
|
||||
$this->assertInstanceOf('WP_Error', $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
function test_xml_enabled() {
|
||||
define('XMLRPC_REQUEST', true);
|
||||
$this->settings->set('clef_password_settings_xml_allowed', true);
|
||||
|
||||
$this->assertEquals($this->user, $this->login->disable_passwords($this->user));
|
||||
}
|
||||
|
||||
}
|
||||
22
wp-content/plugins/wpclef/tests/setup/fakesendmail.sh
Normal file
22
wp-content/plugins/wpclef/tests/setup/fakesendmail.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
#Fake sendmail script, adapted from:
|
||||
#https://github.com/mrded/MNPP/blob/ee64fb2a88efc70ba523b78e9ce61f9f1ed3b4a9/init/fake-sendmail.sh
|
||||
|
||||
#Create a temp folder to put messages in
|
||||
numPath="${TMPDIR-/tmp/}fakemail"
|
||||
umask 037
|
||||
mkdir -p $numPath
|
||||
|
||||
if [ ! -f $numPath/num ]; then
|
||||
echo "0" > $numPath/num
|
||||
fi
|
||||
num=`cat $numPath/num`
|
||||
num=$(($num + 1))
|
||||
echo $num > $numPath/num
|
||||
|
||||
name="$numPath/message_$num.eml"
|
||||
while read line
|
||||
do
|
||||
echo $line >> $name
|
||||
done
|
||||
exit 0
|
||||
43
wp-content/plugins/wpclef/tests/test_clef_tests.php
Normal file
43
wp-content/plugins/wpclef/tests/test_clef_tests.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests to test that that testing framework is testing tests. Meta, huh?
|
||||
*
|
||||
* @package wordpress-plugins-tests
|
||||
*/
|
||||
class WP_Test_Clef_Tests extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Run a simple test to ensure that the tests are running
|
||||
*/
|
||||
function test_tests() {
|
||||
|
||||
$this->assertTrue( true );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If these tests are being run on Travis CI, verify that the version of
|
||||
* WordPress installed is the version that we requested.
|
||||
*/
|
||||
function test_wp_version() {
|
||||
|
||||
// if ( !getenv( 'TRAVIS_PHP_VERSION' ) )
|
||||
// $this->markTestSkipped( 'Test skipped since Travis CI was not detected.' );
|
||||
|
||||
// //grab the requested version
|
||||
// $requested_version = getenv( 'WP_VERSION' );
|
||||
|
||||
// // trunk is always "master" in github terms, but WordPress has a specific way of describing it
|
||||
// // grab the exact version number to verify that we're on trunk
|
||||
// if ( $requested_version == 'master' ) {
|
||||
// $file = file_get_contents( 'http://core.svn.wordpress.org/trunk/wp-includes/version.php' );
|
||||
// preg_match( '#\$wp_version = \'([^\']+)\';#', $file, $matches );
|
||||
// $requested_version = $matches[1];
|
||||
// }
|
||||
|
||||
// $this->assertEquals( get_bloginfo( 'version' ), $requested_version );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user