Skip to content

Commit

Permalink
Fix deprecated request property use in HtmlHelper tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 9, 2017
1 parent 51abd06 commit 7c178f6
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions tests/TestCase/View/Helper/HtmlHelperTest.php
Expand Up @@ -117,7 +117,7 @@ public function testLink()
{
Router::connect('/:controller/:action/*');

$this->Html->request->webroot = '';
$this->Html->request = $this->Html->request->withAttribute('webroot', '');

$result = $this->Html->link('/home');
$expected = ['a' => ['href' => '/home'], 'preg:/\/home/', '/a'];
Expand Down Expand Up @@ -330,8 +330,6 @@ public function testImageTag()
Router::connect('/:controller', ['action' => 'index']);
Router::connect('/:controller/:action/*');

$this->Html->request->webroot = '';

$result = $this->Html->image('test.gif');
$expected = ['img' => ['src' => 'img/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);
Expand Down Expand Up @@ -430,14 +428,13 @@ public function testImageWithFullBase()
$expected = ['img' => ['src' => $here . 'img/sub/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);

$request = $this->Html->request;
$request->webroot = '/myproject/';
$request->base = '/myproject';
Router::pushRequest($request);
$this->Html->Url->request = $this->Html->request
->withAttribute('webroot', '/myproject/')
->withAttribute('base', '/myproject');

$result = $this->Html->image('sub/test.gif', ['fullBase' => true]);
$here = $this->Html->Url->build('/', true);
$expected = ['img' => ['src' => $here . 'img/sub/test.gif', 'alt' => '']];
$expected = ['img' => ['src' => $here . 'myproject/img/sub/test.gif', 'alt' => '']];
$this->assertHtml($expected, $result);
}

Expand All @@ -450,7 +447,7 @@ public function testImageWithTimestampping()
{
Configure::write('Asset.timestamp', 'force');

$this->Html->request->webroot = '/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/');
$result = $this->Html->image('cake.icon.png');
$expected = ['img' => ['src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '']];
$this->assertHtml($expected, $result);
Expand All @@ -462,7 +459,7 @@ public function testImageWithTimestampping()
$expected = ['img' => ['src' => 'preg:/\/img\/cake\.icon\.png\?\d+/', 'alt' => '']];
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/longer/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/longer/');
$result = $this->Html->image('cake.icon.png');
$expected = [
'img' => ['src' => 'preg:/\/testing\/longer\/img\/cake\.icon\.png\?[0-9]+/', 'alt' => '']
Expand All @@ -485,25 +482,26 @@ public function testImageTagWithTheme()
Configure::write('Asset.timestamp', true);
Configure::write('debug', true);

$this->Html->Url->request->webroot = '/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/');
$this->Html->Url->theme = 'TestTheme';
$result = $this->Html->image('__cake_test_image.gif');
$expected = [
'img' => [
'src' => 'preg:/\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
]];
$this->assertHtml($expected, $result);
]
];
$this->assertHtml($expected, $result);

$this->Html->Url->request->webroot = '/testing/';
$result = $this->Html->image('__cake_test_image.gif');
$expected = [
'img' => [
'src' => 'preg:/\/testing\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
]];
$this->assertHtml($expected, $result);
$File->delete();
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/');
$result = $this->Html->image('__cake_test_image.gif');
$expected = [
'img' => [
'src' => 'preg:/\/testing\/test_theme\/img\/__cake_test_image\.gif\?\d+/',
'alt' => ''
]];
$this->assertHtml($expected, $result);
$File->delete();
}

/**
Expand Down Expand Up @@ -735,12 +733,12 @@ public function testCssTimestamping()
$expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/';
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/');
$result = $this->Html->css('cake.generic', ['once' => false]);
$expected['link']['href'] = 'preg:/\/testing\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/longer/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/longer/');
$result = $this->Html->css('cake.generic', ['once' => false]);
$expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?[0-9]+/';
$this->assertHtml($expected, $result);
Expand Down Expand Up @@ -778,12 +776,12 @@ public function testPluginCssTimestamping()
$expected['link']['href'] = 'preg:/.*test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/');
$result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
$expected['link']['href'] = 'preg:/\/testing\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/longer/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/longer/');
$result = $this->Html->css('TestPlugin.test_plugin_asset', ['once' => false]);
$expected['link']['href'] = 'preg:/\/testing\/longer\/test_plugin\/css\/test_plugin_asset\.css\?[0-9]+/';
$this->assertHtml($expected, $result);
Expand Down Expand Up @@ -1093,7 +1091,7 @@ public function testScriptInTheme()
$testfile = WWW_ROOT . '/test_theme/js/__test_js.js';
$File = new File($testfile, true);

$this->Html->Url->request->webroot = '/';
$this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/');
$this->Html->Url->theme = 'TestTheme';
$result = $this->Html->script('__test_js.js');
$expected = [
Expand Down Expand Up @@ -1766,7 +1764,7 @@ public function testMetaIcon()
];
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/';
$this->Html->request = $this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/');
$result = $this->Html->meta('icon');
$expected = [
'link' => ['href' => '/testing/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'icon'],
Expand Down Expand Up @@ -1798,7 +1796,7 @@ public function testMetaIconWithTheme()
];
$this->assertHtml($expected, $result);

$this->Html->request->webroot = '/testing/';
$this->Html->request = $this->Html->Url->request = $this->Html->request->withAttribute('webroot', '/testing/');
$result = $this->Html->meta('icon');
$expected = [
'link' => ['href' => '/testing/test_theme/favicon.ico', 'type' => 'image/x-icon', 'rel' => 'icon'],
Expand Down

0 comments on commit 7c178f6

Please sign in to comment.