Skip to content

Commit

Permalink
Patch for issue #7561
Browse files Browse the repository at this point in the history
Add reset method and tests
  • Loading branch information
jeffblack360 committed Dec 8, 2015
1 parent 492cb4b commit 2714e14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/View/View.php
Expand Up @@ -737,6 +737,19 @@ public function assign($name, $value)
$this->Blocks->set($name, $value);
}

/**
* Reset the content for a block. This will overwrite any
* existing content.
*
* @param string $name Name of the block
* @return void
* @see ViewBlock::set()
*/
public function reset($name)
{
$this->assign($name, '');
}

/**
* Fetch the content for a block. If a block is
* empty or undefined '' will be returned.
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -1488,6 +1488,22 @@ public function testBlockReset()
$this->assertSame('', $result);
}

/**
* Test resetting a block's content with reset.
*
* @return void
*/
public function testBlockResetFunc()
{
$this->View->assign('test', 'Block content');
$result = $this->View->fetch('test', 'This should not be returned');
$this->assertSame('Block content', $result);

$this->View->reset('test');
$result = $this->View->fetch('test', 'This should not be returned');
$this->assertSame('', $result);
}

/**
* Test checking a block's existance.
*
Expand Down

0 comments on commit 2714e14

Please sign in to comment.