Skip to content

Commit

Permalink
Control: isControlInvalid() checks children of classes not implementi…
Browse files Browse the repository at this point in the history
…ng IRenderable [Closes nette/nette#93]
  • Loading branch information
JanTvrdik authored and dg committed Dec 15, 2011
1 parent 5e629ec commit 1a6a159
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Application/UI/Control.php
Expand Up @@ -184,12 +184,21 @@ public function isControlInvalid($snippet = NULL)
return TRUE;

} else {
foreach ($this->getComponents() as $component) {
if ($component instanceof IRenderable && $component->isControlInvalid()) {
// $this->invalidSnippets['__child'] = TRUE; // as cache
return TRUE;
$queue = array($this);
do {
foreach (array_shift($queue)->getComponents() as $component) {
if ($component instanceof IRenderable) {
if ($component->isControlInvalid()) {
// $this->invalidSnippets['__child'] = TRUE; // as cache
return TRUE;
}

} elseif ($component instanceof Nette\ComponentModel\IContainer) {
$queue[] = $component;
}
}
}
} while ($queue);

return FALSE;
}

Expand Down
43 changes: 43 additions & 0 deletions tests/Application/Control.isControlInvalid.phpt
@@ -0,0 +1,43 @@
<?php

/**
* Test: Nette\Application\UI\Control::isControlInvalid()
*
* @author Jan Tvrdík
* @package Nette\Application\UI
* @subpackage UnitTests
*/

use Nette\Application\UI;



require __DIR__ . '/../bootstrap.php';



class TestControl extends UI\Control
{

}



$control = new TestControl();
$child = new TestControl();
$control->addComponent($child, 'foo');

Assert::false($control->isControlInvalid());
$child->invalidateControl();
Assert::true($control->isControlInvalid());


$control = new TestControl();
$child = new Nette\ComponentModel\Container();
$grandChild = new TestControl();
$control->addComponent($child, 'foo');
$child->addComponent($grandChild, 'bar');

Assert::false($control->isControlInvalid());
$grandChild->invalidateControl();
Assert::true($control->isControlInvalid());

0 comments on commit 1a6a159

Please sign in to comment.