Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TLVTree to not have a View attribute #74

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/views/helpers/Tiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
$title . $badges,
'toplevelview/show/tree',
array(
'name' => $node->getRoot()->getView()->getName(),
'name' => $node->getRoot()->getViewName(),
'id' => $node->getFullId()
),
array(
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
$url = Url::fromPath(
'toplevelview/show/tree',
array(
'name' => $node->getRoot()->getView()->getName(),
'name' => $node->getRoot()->getViewName(),
'id' => $node->getFullId()
)
);
Expand Down
3 changes: 2 additions & 1 deletion library/Toplevelview/Model/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function getTree(): TLVTree
if ($this->tree === null) {
$this->ensureParsed();
$this->tree = $tree = TLVTree::fromArray($this->raw);
$tree->setView($this);
$tree->setViewName($this->getName());
$tree->setViewChecksum($this->getTextChecksum());
}
return $this->tree;
}
Expand Down
43 changes: 21 additions & 22 deletions library/Toplevelview/Tree/TLVTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ class TLVTree extends TLVTreeNode

protected $cacheLifetime = 60;

/**
* @var View
*/
protected $view;
protected $viewName;

protected $viewChecksum;

/**
* Return a child by its ID
Expand Down Expand Up @@ -70,22 +69,25 @@ public function getById($id)
return $currentNode;
}

/**
* @return View
*/
public function getView()
public function getViewName(): string
{
return $this->view;
return $this->viewName;
}

/**
* @param View $view
*
* @return $this
*/
public function setView(View $view)
public function setViewName(string $name)
{
$this->viewName = $name;
return $this;
}

public function getViewChecksum(): string
{
return $this->viewChecksum;
}

public function setViewChecksum(string $checksum)
{
$this->view = $view;
$this->viewChecksum = $checksum;
return $this;
}

Expand All @@ -111,12 +113,9 @@ public function registerObject($type, $name, $class)

protected function getCacheName()
{
$view = $this->getView();
return sprintf(
'%s-%s.json',
$view->getName(),
$view->getTextChecksum()
);
$n = $this->getViewName();
$c = $this->getViewChecksum();
return sprintf('%s-%s.json', $n, $c);
}

protected function loadCache()
Expand Down
12 changes: 12 additions & 0 deletions test/php/library/Toplevelview/ViewConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Icinga\Module\Toplevelview\ViewConfig;

use Icinga\Exception\NotReadableError;
use Icinga\Exception\NotFoundError;
use PHPUnit\Framework\TestCase;

final class ViewConfigTest extends TestCase
Expand All @@ -31,4 +32,15 @@ public function testViewConfigWithNoError()
$this->assertSame(null, $clone->getName());
$this->assertFalse($clone->hasBeenLoaded());
}

public function testViewConfigWithTree()
{
$this->expectException(NotFoundError::class);

$c = new ViewConfig('test/testdata');
$view = $c->loadByName('example');

$t = $view->getTree();
$t->getById('0-1-2');
}
}