PageRenderTime 40ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 14ms app.codeStats 1ms

/Croogo/Test/Case/View/Helper/CroogoHtmlHelperTest.php

https://github.com/kareypowell/croogo
PHP | 183 lines | 158 code | 19 blank | 6 comment | 0 complexity | 05b7852e9593679a91331d225dc39429 MD5 | raw file
  1<?php
  2
  3App::uses('CroogoHelper', 'Croogo.View/Helper');
  4App::uses('CroogoHtmlHelper', 'Croogo.View/Helper');
  5App::uses('Controller', 'Controller');
  6App::uses('CroogoTestCase', 'Croogo.TestSuite');
  7App::uses('View', 'View');
  8App::uses('HtmlHelper', 'View/Helper');
  9
 10class CroogoHtmlHelperTest extends CroogoTestCase {
 11
 12	public $fixtures = array(
 13		'plugin.taxonomy.type',
 14	);
 15
 16	public function setUp() {
 17		$controller = null;
 18		$this->View = new View($controller);
 19		$this->CroogoHtml = new CroogoHtmlHelper($this->View);
 20	}
 21
 22	public function tearDown() {
 23		unset($this->View);
 24		unset($this->CroogoHtml);
 25	}
 26
 27	public function testIcon() {
 28		$result = $this->CroogoHtml->icon('remove');
 29		$this->assertContains('<i class="icon-remove"></i>', $result);
 30	}
 31
 32	public function testStatusOk() {
 33		$result = $this->CroogoHtml->status(1);
 34		$this->assertContains('<i class="icon-ok green"></i>', $result);
 35	}
 36
 37	public function testStatusOkWithUrl() {
 38		$result = $this->CroogoHtml->status(1, array(
 39			'admin' => true,
 40			'plugin' => 'nodes',
 41			'controller' => 'nodes',
 42			'action' => 'toggle',
 43		));
 44		$expected = array(
 45			'a' => array(
 46				'href',
 47				'data-url' => '/admin/nodes/nodes/toggle',
 48				'class' => 'icon-ok green ajax-toggle',
 49			),
 50			'/a',
 51		);
 52		$this->assertTags($result, $expected);
 53	}
 54
 55	public function testStatusRemove() {
 56		$result = $this->CroogoHtml->status(0);
 57		$this->assertContains('<i class="icon-remove red"></i>', $result);
 58	}
 59
 60	public function testStatusRemoveWithUrl() {
 61		$result = $this->CroogoHtml->status(0, array(
 62			'admin' => true,
 63			'plugin' => 'nodes',
 64			'controller' => 'nodes',
 65			'action' => 'delete',
 66		));
 67		$expected = array(
 68			'a' => array(
 69				'href',
 70				'data-url' => '/admin/nodes/nodes/delete',
 71				'class' => 'icon-remove red ajax-toggle',
 72			),
 73			'/a',
 74		);
 75		$this->assertTags($result, $expected);
 76	}
 77
 78	public function testLink() {
 79		$result = $this->CroogoHtml->link('', '/remove', array('icon' => 'remove', 'button' => 'danger'));
 80		$this->assertContains('class="btn btn-danger"', $result);
 81		$this->assertContains('<i class="icon-remove icon-large"></i>', $result);
 82	}
 83
 84/**
 85 * testLinkWithSmallIcon
 86 */
 87	public function testLinkWithSmallIcon() {
 88		$result = $this->CroogoHtml->link('', '/remove', array(
 89			'icon' => 'remove',
 90			'iconSize' => 'small',
 91			'button' => 'danger'
 92		));
 93		$this->assertContains('class="btn btn-danger"', $result);
 94		$this->assertContains('<i class="icon-remove"></i>', $result);
 95	}
 96
 97/**
 98 * testLinkWithInlineIcon
 99 */
100	public function testLinkWithInlineIcon() {
101		$result = $this->CroogoHtml->link('', '/remove', array(
102			'icon' => 'remove',
103			'iconSize' => 'small',
104			'iconInline' => true,
105			'button' => 'danger'
106		));
107		$expected = array(
108			'a' => array(
109				'href',
110				'class' => 'btn btn-danger icon-remove',
111			),
112		);
113		$this->assertTags($result, $expected);
114
115		$result = $this->CroogoHtml->link('', '/remove', array(
116			'icon' => 'remove',
117			'iconInline' => true,
118			'button' => 'danger'
119		));
120		$expected = array(
121			'a' => array(
122				'href',
123				'class' => 'btn btn-danger icon-large icon-remove',
124			),
125		);
126		$this->assertTags($result, $expected);
127	}
128
129	public function testLinkDefaultButton() {
130		$result = $this->CroogoHtml->link('Remove', '/remove', array('button' => 'default'));
131		$this->assertContains('<a href="/remove" class="btn">Remove</a>', $result);
132	}
133
134	public function testLinkOptionsIsNull() {
135		$result = $this->CroogoHtml->link('Remove', '/remove', null);
136	}
137
138	public function testLinkTooltip() {
139		$result = $this->CroogoHtml->link('', '/remove', array('tooltip' => 'remove it'));
140		$expected = array(
141			'a' => array(
142				'href',
143				'rel' => 'tooltip',
144				'data-placement',
145				'data-trigger',
146				'data-title' => 'remove it',
147			),
148			'/a',
149		);
150		$this->assertTags($result, $expected);
151	}
152
153	public function testLinkButtonTooltipWithArrayOptions() {
154		$result = $this->CroogoHtml->link('', '/remove', array(
155			'button' => array('success'),
156			'tooltip' => array(
157				'data-title' => 'remove it',
158				'data-placement' => 'left',
159				'data-trigger' => 'focus',
160			),
161		));
162		$expected = array(
163			'a' => array(
164				'href',
165				'class' => 'btn btn-success',
166				'rel' => 'tooltip',
167				'data-placement' => 'left',
168				'data-trigger' => 'focus',
169				'data-title' => 'remove it',
170			),
171			'/a',
172		);
173		$this->assertTags($result, $expected);
174	}
175
176	public function testAddPathAndGetCrumbList() {
177		$this->CroogoHtml->addPath('/yes/we/can', '/');
178		$result = $this->CroogoHtml->getCrumbList();
179		$this->assertContains('<a href="/yes/">yes</a>', $result);
180		$this->assertContains('<a href="/yes/we/">we</a>', $result);
181		$this->assertContains('<a href="/yes/we/can/">can</a>', $result);
182	}
183}