Skip to content

Commit

Permalink
added unit tests and support for next, prev, first and last
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingmedia committed Oct 14, 2016
1 parent 795c202 commit 5cd9cc6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/View/Helper/HtmlHelper.php
Expand Up @@ -238,7 +238,11 @@ public function meta($type, $content = null, array $options = [])
'description' => ['name' => 'description', 'content' => $content],
'robots' => ['name' => 'robots', 'content' => $content],
'viewport' => ['name' => 'viewport', 'content' => $content],
'canonical' => ['rel' => 'canonical', 'link' => $content]
'canonical' => ['rel' => 'canonical', 'link' => $content],
'next' => ['rel' => 'next', 'link' => $content],
'prev' => ['rel' => 'prev', 'link' => $content],
'first' => ['rel' => 'first', 'link' => $content],
'last' => ['rel' => 'last', 'link' => $content]
];

if ($type === 'icon' && $content === null) {
Expand Down
50 changes: 41 additions & 9 deletions tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -43,11 +43,18 @@ class HtmlHelperTest extends TestCase
public $cDataEnd = 'preg:/[^\]]*\]\]\>[\s\r\n]*/';

/**
* html property
* Helper to be tested
*
* @var object
* @var \Cake\View\Helper\HtmlHelper
*/
public $Html = null;
public $Html;

/**
* Mocked view
*
* @var \Cake\View\View|\PHPUnit_Framework_MockObject_MockObject
*/
public $View;

/**
* setUp method
Expand Down Expand Up @@ -489,7 +496,6 @@ public function testImageTagWithTheme()
*/
public function testThemeAssetsInMainWebrootPath()
{
$webRoot = Configure::read('App.wwwRoot');
Configure::write('App.wwwRoot', TEST_APP . 'webroot/');

$this->Html->Url->theme = 'TestTheme';
Expand All @@ -515,13 +521,10 @@ public function testThemeAssetsInMainWebrootPath()
public function testStyle()
{
$result = $this->Html->style(['display' => 'none', 'margin' => '10px']);
$expected = 'display:none; margin:10px;';
$this->assertRegExp('/^display\s*:\s*none\s*;\s*margin\s*:\s*10px\s*;?$/', $expected);
$this->assertEquals('display:none; margin:10px;', $result);

$result = $this->Html->style(['display' => 'none', 'margin' => '10px'], false);
$lines = explode("\n", $result);
$this->assertRegExp('/^\s*display\s*:\s*none\s*;\s*$/', $lines[0]);
$this->assertRegExp('/^\s*margin\s*:\s*10px\s*;?$/', $lines[1]);
$this->assertEquals("display:none;\nmargin:10px;", $result);
}

/**
Expand Down Expand Up @@ -1636,6 +1639,35 @@ public function testMeta()
$this->assertHtml($expected, $result);
}

/**
* @return array
*/
public function dataMetaLinksProvider()
{
return [
['canonical', ['controller' => 'posts', 'action' => 'show'], '/posts/show'],
['first', ['controller' => 'posts', 'action' => 'index'], '/posts'],
['last', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 10]], '/posts?page=10'],
['prev', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 4]], '/posts?page=4'],
['next', ['controller' => 'posts', 'action' => 'index', '?' => ['page' => 6]], '/posts?page=6']
];
}

/**
* test canonical and pagination meta links
*
* @param string $type
* @param array $url
* @param string $expected_url
* @dataProvider dataMetaLinksProvider
*/
public function testMetaLinks($type, array $url, $expected_url)
{
$result = $this->Html->meta($type, $url);
$expected = ['link' => ['href' => $expected_url, 'rel' => $type]];
$this->assertHtml($expected, $result);
}

/**
* Test generating favicon's with meta()
*
Expand Down

0 comments on commit 5cd9cc6

Please sign in to comment.