Skip to content
Permalink
Browse files

added unit tests and support for next, prev, first and last

  • Loading branch information...
thinkingmedia
thinkingmedia committed Oct 14, 2016
1 parent 795c202 commit 5cd9cc68eb85ae914d91cb50a882797882d24d53
Showing with 46 additions and 10 deletions.
  1. +5 −1 src/View/Helper/HtmlHelper.php
  2. +41 −9 tests/TestCase/View/Helper/HtmlHelperTest.php
@@ -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) {
@@ -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
@@ -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';
@@ -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);
}
/**
@@ -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()
*

0 comments on commit 5cd9cc6

Please sign in to comment.
You can’t perform that action at this time.