Item: Remove "ench" tag when all enchantments are removed from an item (#4184)

fixes #4144
This commit is contained in:
TheNewHEROBRINEX
2021-04-18 21:56:07 +02:00
committed by GitHub
parent 6f80b8979d
commit 8d1a1628de
3 changed files with 23 additions and 1 deletions

View File

@ -25,12 +25,15 @@ namespace pocketmine\item;
use PHPUnit\Framework\TestCase;
use pocketmine\block\BlockFactory;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
class ItemTest extends TestCase{
public function setUp() : void{
BlockFactory::init();
ItemFactory::init();
Enchantment::init();
}
/**
@ -61,6 +64,16 @@ class ItemTest extends TestCase{
}
}
/**
* Tests that when all enchantments are removed from an item, the "ench" tag is removed as well
*/
public function testEnchantmentRemoval() : void{
$item = ItemFactory::get(Item::DIAMOND_SWORD);
$item->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::SHARPNESS)));
$item->removeEnchantment(Enchantment::SHARPNESS);
self::assertNull($item->getNamedTag()->getTag(Item::TAG_ENCH));
}
/**
* @return mixed[][]
* @phpstan-return list<array{string,int,int}>