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

Method isControlInvalid does not "see" through ComponentContainer #93

Merged
merged 1 commit into from Dec 21, 2011
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions Nette/Application/UI/Control.php
Expand Up @@ -183,12 +183,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/Nette/Application.UI/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());