Skip to content

Commit

Permalink
Add tests for Batch Extension.
Browse files Browse the repository at this point in the history
Fix bug in Batch Extension.
  • Loading branch information
reinink committed Nov 18, 2013
1 parent dfcf763 commit a562d7b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/League/Plates/Extension/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function runUri($var1 = null, $var2 = null, $var3 = null, $var4 = null)
if ($this->parts[$var1] === $var2) {
return $var3;
} else {
return $var3;
return $var4;
}
}

Expand Down
71 changes: 71 additions & 0 deletions tests/League/Plates/Extension/URITest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace League\Plates\Extension;

class URITest extends \PHPUnit_Framework_TestCase
{
private $extension;

public function setUp()
{
$this->extension = new URI('/green/red/blue');
}

public function testCanCreateExtension()
{
$this->assertInstanceOf('League\Plates\Extension\URI', $this->extension);
}

public function testGetFunctionsReturnsAnArray()
{
$this->assertInternalType('array', $this->extension->getFunctions());
}

public function testGetFunctionsReturnsAtLeastOneRecord()
{
$this->assertTrue(count($this->extension->getFunctions()) > 0);
}

public function testGetUrl()
{
$this->assertTrue($this->extension->runUri() === '/green/red/blue');
}

public function testGetSpecifiedSegment()
{
$this->assertTrue($this->extension->runUri(1) === 'green');
$this->assertTrue($this->extension->runUri(2) === 'red');
$this->assertTrue($this->extension->runUri(3) === 'blue');
}

public function testSegmentMatch()
{
$this->assertTrue($this->extension->runUri(1, 'green'));
$this->assertFalse($this->extension->runUri(1, 'red'));
}

public function testSegmentMatchSuccessResponse()
{
$this->assertTrue($this->extension->runUri(1, 'green', 'success') === 'success');
}

public function testSegmentMatchFailureResponse()
{
$this->assertTrue($this->extension->runUri(1, 'red', 'success', 'fail') === 'fail');
}

public function testRegexMatch()
{
$this->assertTrue($this->extension->runUri('/[a-z]+/red/blue'));
}

public function testRegexMatchSuccessResponse()
{
$this->assertTrue($this->extension->runUri('/[a-z]+/red/blue', 'success') === 'success');
}

public function testRegexMatchFailureResponse()
{
$this->assertTrue($this->extension->runUri('/[0-9]+/red/blue', 'success', 'fail') === 'fail');
}
}

0 comments on commit a562d7b

Please sign in to comment.