Skip to content

Commit

Permalink
added allowops test
Browse files Browse the repository at this point in the history
  • Loading branch information
weaondara committed Dec 25, 2015
1 parent ea1da2f commit 015ee65
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import net.alpenblock.bungeeperms.ChatColor;
import net.alpenblock.bungeeperms.Color;
import net.alpenblock.bungeeperms.testsuite.bukkit.tests.AllowOpsTest;
import net.alpenblock.bungeeperms.testsuite.bukkit.tests.SuperPermsIterate;
import net.alpenblock.bungeeperms.testsuite.bukkit.tests.SuperPermsList;
import net.alpenblock.bungeeperms.testsuite.bukkit.tests.SuperPermsTest;
Expand All @@ -32,6 +33,7 @@ public void onLoad()
{
instance = this;

tests.add(new AllowOpsTest());
tests.add(new PrefixSuffixTest());
tests.add(new RecalculatePermissionsTest());
tests.add(new SuperPermsIterate());
Expand Down
@@ -0,0 +1,54 @@
package net.alpenblock.bungeeperms.testsuite.bukkit.tests;

import net.alpenblock.bungeeperms.BungeePerms;
import net.alpenblock.bungeeperms.Statics;
import net.alpenblock.bungeeperms.platform.bukkit.BukkitConfig;
import net.alpenblock.bungeeperms.testsuite.bukkit.BukkitTest;
import net.alpenblock.bungeeperms.testsuite.bukkit.BukkitTestSuite;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class AllowOpsTest extends BukkitTest
{

@Override
public boolean test(CommandSender sender)
{
Player p = Bukkit.getPlayer(BukkitTestSuite.getTestplayer());
if (p == null)
{
throw new RuntimeException("test player " + BukkitTestSuite.getTestplayer() + " not found");
}

boolean wasop = p.isOp();
p.setOp(true);

boolean wasallowops = ((BukkitConfig) BungeePerms.getInstance().getConfig()).isAllowops();

Statics.setField(BukkitConfig.class, BungeePerms.getInstance().getConfig(), false, "allowops");
assertFalse(sender, ((BukkitConfig) BungeePerms.getInstance().getConfig()).isAllowops());
p.recalculatePermissions();
assertFalse(sender, p.hasPermission("root.node3.perm5"));

Statics.setField(BukkitConfig.class, BungeePerms.getInstance().getConfig(), true, "allowops");
assertTrue(sender, ((BukkitConfig) BungeePerms.getInstance().getConfig()).isAllowops());
p.recalculatePermissions();
assertTrue(sender, p.hasPermission("root.node3.perm5"));

//restore allowops
Statics.setField(BukkitConfig.class, BungeePerms.getInstance().getConfig(), wasallowops, "allowops");

//restore op
p.setOp(wasop);

return result();
}

@Override
public String getName()
{
return "AllowOpsTest";
}

}

0 comments on commit 015ee65

Please sign in to comment.