Files
kupshop/bundles/KupShop/AdminBundle/Tests/BlocksHistoryTest.php
2025-08-02 16:30:27 +02:00

131 lines
3.9 KiB
PHP

<?php
namespace KupShop\AdminBundle\Tests;
use KupShop\AdminBundle\Util\BlocksHistory;
use KupShop\ContentBundle\Util\Block;
class BlocksHistoryTest extends \DatabaseTestCase
{
/** @var BlocksHistory */
protected $blocksHistory;
/** @var Block */
protected $block;
protected function setUp(): void
{
parent::setUp();
$this->blocksHistory = $this->get(BlocksHistory::class);
$this->block = $this->get(Block::class);
}
public function testSetBlocksHistoryName()
{
$blockHistory = $this->blocksHistory->getBlocksHistory(1, BlocksHistory::TYPE_BY_ID);
$this->blocksHistory->setBlocksHistoryName('Verze 1.0.1', 1);
$blockHistoryUpdated = $this->blocksHistory->getBlocksHistory(1, BlocksHistory::TYPE_BY_ID);
$this->assertEquals(null, $blockHistory['name']);
$this->assertEquals('Verze 1.0.1', $blockHistoryUpdated['name']);
}
public function testDeleteBlocksHistory()
{
$blockHistory = $this->blocksHistory->getBlocksHistory(1, BlocksHistory::TYPE_BY_ID);
$this->blocksHistory->deleteBlocksHistory(1);
$blockHistoryDeleted = $this->blocksHistory->getBlocksHistory(1, BlocksHistory::TYPE_BY_ID);
$this->assertNotEmpty($blockHistory);
$this->assertEmpty($blockHistoryDeleted);
}
public function testSaveBlocksHistory()
{
$updatedBlocks = [
2 => [
'id' => 2,
'name' => 'Test',
'identifier' => '',
'content' => 'Test content UPDATED',
],
3 => [
'id' => 3,
'name' => 'Test SUB',
'identifier' => '',
'content' => 'Test SUB content',
],
4 => [
'id' => 4,
'name' => 'Test 2',
'identifier' => '',
'content' => 'Test 2 content',
],
];
$blocks = $this->block->getBlocks(1);
$this->blocksHistory->saveBlocksHistory($updatedBlocks);
$history = $this->blocksHistory->getBlocksHistory(1);
$this->assertEquals(1, count($history));
$this->assertEquals($blocks, reset($history)['blocks']);
}
public function testGetLastActualHistory()
{
$updatedBlocks = [
6 => [
'id' => 6,
'name' => 'Test History EDIT',
'identifier' => '',
'content' => 'Test history EDIT',
],
];
$lastActualHistoryFalse = $this->blocksHistory->getLastFreshHistory(5);
$this->blocksHistory->saveBlocksHistory($updatedBlocks);
$lastActualHistory = $this->blocksHistory->getLastFreshHistory(5);
$this->assertFalse($lastActualHistoryFalse);
$this->assertNotFalse($lastActualHistory);
}
public function testRevertBlocksHistoryFailure()
{
$this->assertFalse($this->blocksHistory->revertBlocksHistory(100));
}
public function testRevertBlocksHistory()
{
$history = $this->blocksHistory->getBlocksHistory(2, BlocksHistory::TYPE_BY_ID);
$this->blocksHistory->revertBlocksHistory(2);
$blocks = $this->block->getBlocks(5);
$this->assertEquals($history['blocks'], $blocks);
}
/**
* @dataProvider isBlockUpdatedProvider
*/
public function testIsBlockUpdated($block, $condition)
{
$this->assertEquals($condition, $this->blocksHistory->isBlockUpdated($block));
}
public function isBlockUpdatedProvider()
{
return [
[['id' => 2, 'name' => 'Test', 'content' => 'Test content EDITED'], true],
[['id' => 2, 'name' => 'Test', 'content' => 'Test content'], false],
];
}
protected function getDataSet()
{
sqlQuery('DELETE FROM articles');
return $this->getJsonDataSetFromFile();
}
}