File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,4 +26,16 @@ public function testUseTag() {
2626 ));
2727 }
2828
29+ public function testImage () {
30+ $ result = $ this ->Html ->image ('' , array ('data-src ' => 'holder.js/24x24 ' ));
31+ $ this ->assertTags ($ result , array (
32+ 'img ' => array ('src ' => '/ ' , 'data-src ' => 'holder.js/24x24 ' , 'alt ' => '' )
33+ ));
34+
35+ $ result = $ this ->Html ->image ('some.jpg ' , array ('data-src ' => 'holder.js/24x24 ' ));
36+ $ this ->assertTags ($ result , array (
37+ 'img ' => array ('src ' => '/img/some.jpg ' , 'alt ' => '' )
38+ ));
39+ }
40+
2941}
Original file line number Diff line number Diff line change @@ -26,4 +26,43 @@ public function useTag($tag) {
2626 return $ html ;
2727 }
2828
29+ /**
30+ * Creates a formatted IMG element.
31+ *
32+ * This method will set an empty alt attribute if one is not supplied.
33+ *
34+ * ### Usage:
35+ *
36+ * Create a regular image:
37+ *
38+ * `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP'));`
39+ *
40+ * Create an image link:
41+ *
42+ * `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
43+ *
44+ * ### Options:
45+ *
46+ * - `url` If provided an image link will be generated and the link will point at
47+ * `$options['url']`.
48+ * - `fullBase` If true the src attribute will get a full address for the image file.
49+ * - `plugin` False value will prevent parsing path as a plugin
50+ * - `data-src` For holder.js options. If `$path` is not empty, then unset `$options['data-src']`.
51+ *
52+ * @param string $path Path to the image file, relative to the app/webroot/img/ directory.
53+ * @param array $options Array of HTML attributes. See above for special options.
54+ * @return string completed img tag
55+ * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
56+ */
57+ public function image ($ path , $ options = array ()) {
58+ if (empty ($ path )) {
59+ $ path = '/ ' ;
60+ } else {
61+ if (isset ($ options ['data-src ' ])) {
62+ unset($ options ['data-src ' ]);
63+ }
64+ }
65+ return parent ::image ($ path , $ options );
66+ }
67+
2968}
You can’t perform that action at this time.
0 commit comments