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

Language PHP Lines 184
MD5 Hash 05b7852e9593679a91331d225dc39429
Repository https://github.com/kareypowell/croogo.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php

App::uses('CroogoHelper', 'Croogo.View/Helper');
App::uses('CroogoHtmlHelper', 'Croogo.View/Helper');
App::uses('Controller', 'Controller');
App::uses('CroogoTestCase', 'Croogo.TestSuite');
App::uses('View', 'View');
App::uses('HtmlHelper', 'View/Helper');

class CroogoHtmlHelperTest extends CroogoTestCase {

	public $fixtures = array(
		'plugin.taxonomy.type',
	);

	public function setUp() {
		$controller = null;
		$this->View = new View($controller);
		$this->CroogoHtml = new CroogoHtmlHelper($this->View);
	}

	public function tearDown() {
		unset($this->View);
		unset($this->CroogoHtml);
	}

	public function testIcon() {
		$result = $this->CroogoHtml->icon('remove');
		$this->assertContains('<i class="icon-remove"></i>', $result);
	}

	public function testStatusOk() {
		$result = $this->CroogoHtml->status(1);
		$this->assertContains('<i class="icon-ok green"></i>', $result);
	}

	public function testStatusOkWithUrl() {
		$result = $this->CroogoHtml->status(1, array(
			'admin' => true,
			'plugin' => 'nodes',
			'controller' => 'nodes',
			'action' => 'toggle',
		));
		$expected = array(
			'a' => array(
				'href',
				'data-url' => '/admin/nodes/nodes/toggle',
				'class' => 'icon-ok green ajax-toggle',
			),
			'/a',
		);
		$this->assertTags($result, $expected);
	}

	public function testStatusRemove() {
		$result = $this->CroogoHtml->status(0);
		$this->assertContains('<i class="icon-remove red"></i>', $result);
	}

	public function testStatusRemoveWithUrl() {
		$result = $this->CroogoHtml->status(0, array(
			'admin' => true,
			'plugin' => 'nodes',
			'controller' => 'nodes',
			'action' => 'delete',
		));
		$expected = array(
			'a' => array(
				'href',
				'data-url' => '/admin/nodes/nodes/delete',
				'class' => 'icon-remove red ajax-toggle',
			),
			'/a',
		);
		$this->assertTags($result, $expected);
	}

	public function testLink() {
		$result = $this->CroogoHtml->link('', '/remove', array('icon' => 'remove', 'button' => 'danger'));
		$this->assertContains('class="btn btn-danger"', $result);
		$this->assertContains('<i class="icon-remove icon-large"></i>', $result);
	}

/**
 * testLinkWithSmallIcon
 */
	public function testLinkWithSmallIcon() {
		$result = $this->CroogoHtml->link('', '/remove', array(
			'icon' => 'remove',
			'iconSize' => 'small',
			'button' => 'danger'
		));
		$this->assertContains('class="btn btn-danger"', $result);
		$this->assertContains('<i class="icon-remove"></i>', $result);
	}

/**
 * testLinkWithInlineIcon
 */
	public function testLinkWithInlineIcon() {
		$result = $this->CroogoHtml->link('', '/remove', array(
			'icon' => 'remove',
			'iconSize' => 'small',
			'iconInline' => true,
			'button' => 'danger'
		));
		$expected = array(
			'a' => array(
				'href',
				'class' => 'btn btn-danger icon-remove',
			),
		);
		$this->assertTags($result, $expected);

		$result = $this->CroogoHtml->link('', '/remove', array(
			'icon' => 'remove',
			'iconInline' => true,
			'button' => 'danger'
		));
		$expected = array(
			'a' => array(
				'href',
				'class' => 'btn btn-danger icon-large icon-remove',
			),
		);
		$this->assertTags($result, $expected);
	}

	public function testLinkDefaultButton() {
		$result = $this->CroogoHtml->link('Remove', '/remove', array('button' => 'default'));
		$this->assertContains('<a href="/remove" class="btn">Remove</a>', $result);
	}

	public function testLinkOptionsIsNull() {
		$result = $this->CroogoHtml->link('Remove', '/remove', null);
	}

	public function testLinkTooltip() {
		$result = $this->CroogoHtml->link('', '/remove', array('tooltip' => 'remove it'));
		$expected = array(
			'a' => array(
				'href',
				'rel' => 'tooltip',
				'data-placement',
				'data-trigger',
				'data-title' => 'remove it',
			),
			'/a',
		);
		$this->assertTags($result, $expected);
	}

	public function testLinkButtonTooltipWithArrayOptions() {
		$result = $this->CroogoHtml->link('', '/remove', array(
			'button' => array('success'),
			'tooltip' => array(
				'data-title' => 'remove it',
				'data-placement' => 'left',
				'data-trigger' => 'focus',
			),
		));
		$expected = array(
			'a' => array(
				'href',
				'class' => 'btn btn-success',
				'rel' => 'tooltip',
				'data-placement' => 'left',
				'data-trigger' => 'focus',
				'data-title' => 'remove it',
			),
			'/a',
		);
		$this->assertTags($result, $expected);
	}

	public function testAddPathAndGetCrumbList() {
		$this->CroogoHtml->addPath('/yes/we/can', '/');
		$result = $this->CroogoHtml->getCrumbList();
		$this->assertContains('<a href="/yes/">yes</a>', $result);
		$this->assertContains('<a href="/yes/we/">we</a>', $result);
		$this->assertContains('<a href="/yes/we/can/">can</a>', $result);
	}
}
Back to Top