croogo /Taxonomy/Test/Case/Controller/TermsControllerTest.php

Language PHP Lines 232
MD5 Hash 95e0ed93156f1ad7e9ae0fdc877e20f3
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
App::uses('TermsController', 'Taxonomy.Controller');
App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');

class TermsControllerTest extends CroogoControllerTestCase {

	public $fixtures = array(
		'plugin.users.aco',
		'plugin.users.aro',
		'plugin.users.aros_aco',
		'plugin.blocks.block',
		'plugin.comments.comment',
		'plugin.contacts.contact',
		'plugin.translate.i18n',
		'plugin.settings.language',
		'plugin.menus.link',
		'plugin.menus.menu',
		'plugin.contacts.message',
		'plugin.nodes.node',
		'plugin.meta.meta',
		'plugin.taxonomy.model_taxonomy',
		'plugin.blocks.region',
		'plugin.users.role',
		'plugin.settings.setting',
		'plugin.taxonomy.taxonomy',
		'plugin.taxonomy.term',
		'plugin.taxonomy.type',
		'plugin.taxonomy.types_vocabulary',
		'plugin.users.user',
		'plugin.taxonomy.vocabulary',
	);

/**
 * setUp
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		App::build(array(
			'View' => array(CakePlugin::path('Taxonomy') . 'View' . DS)
		), App::APPEND);
		$this->TermsController = $this->generate('Taxonomy.Terms', array(
			'methods' => array(
				'redirect',
			),
			'components' => array(
				'Auth' => array('user'),
				'Session',
				'Menus.Menus',
			),
		));
		$this->TermsController->Auth
			->staticExpects($this->any())
			->method('user')
			->will($this->returnCallback(array($this, 'authUserCallback')));
	}

/**
 * tearDown
 *
 * @return void
 */
	public function tearDown() {
		parent::tearDown();
		unset($this->TermsController);
	}

/**
 * testAdminIndex
 *
 * @return void
 */
	public function testAdminIndex() {
		$this->testAction('/admin/taxonomy/terms/index/1');
		$this->assertNotEmpty($this->vars['terms']);
		$expected = array(
			'1' => 'Uncategorized',
			'2' => 'Announcements',
		);
		$termsTree = Hash::combine($this->vars['terms'], '{n}.Term.id', '{n}.Term.title');
		$this->assertEquals($expected, $termsTree);
	}

/**
 * testAdminAdd
 *
 * @return void
 */
	public function testAdminAdd() {
		$this->expectFlashAndRedirect('Term saved successfuly.');
		$this->testAction('admin/taxonomy/terms/add/1', array(
			'data' => array(
				'Taxonomy' => array(
					'parent_id' => null,
				),
				'Term' => array(
					'title' => 'New Category',
					'slug' => 'new-category',
					'description' => 'category description here',
				),
			),
		));
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
		$termsTreeSlugs = array_keys($termsTree);
		$expected = array(
			'uncategorized',
			'announcements',
			'new-category',
		);
		$this->assertEqual($termsTreeSlugs, $expected);
	}

/**
 * testAdminAddWithParent
 *
 * @return void
 */
	public function testAdminAddWithParent() {
		$this->expectFlashAndRedirect('Term saved successfuly.');
		$this->testAction('admin/taxonomy/terms/add/1', array(
			'data' => array(
				'Taxonomy' => array(
					'parent_id' => 1, // Uncategorized
				),
				'Term' => array(
					'title' => 'New Category',
					'slug' => 'new-category',
					'description' => 'category description here',
				),
			),
		));
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
		$termsTreeTitles = array_values($termsTree);
		$expected = array(
			'Uncategorized',
			'_New Category',
			'Announcements',
		);
		$this->assertEqual($termsTreeTitles, $expected);
	}

/**
 * testAdminEdit
 *
 * @return void
 */
	public function testAdminEdit() {
		$this->expectFlashAndRedirect('Term saved successfuly.');
		// ID of Uncategorized and Categories
		$this->testAction('/admin/taxonomy/terms/edit/1/1', array(
			'data' => array(
				'Taxonomy' => array(
					'id' => 1,
					'parent_id' => null,
				),
				'Term' => array(
					'id' => 1,
					'title' => 'New Category',
					'slug' => 'new-category',
					'description' => 'category description here',
				),
			),
		));
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
		$expected = array(
			'new-category' => 'New Category',
			'announcements' => 'Announcements',
		);
		$this->assertEquals($expected, $termsTree);
	}

/**
 * testAdminDelete
 *
 * @return void
 */
	public function testAdminDelete() {
		$ModelTaxonomy = ClassRegistry::init('Taxonomy.ModelTaxonomy');
		$options = array('conditions' => array(
			'taxonomy_id' => 1,
		));
		$count = $ModelTaxonomy->find('count', $options);
		$this->assertEquals(1, $count);

		$this->expectFlashAndRedirect('Term deleted');
		$this->testAction('admin/taxonomy/terms/delete/1/1'); // ID of Uncategorized and Categories
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');

		$count = $ModelTaxonomy->find('count', $options);
		$this->assertEquals(0, $count);

		$expected = array(
			'announcements' => 'Announcements',
		);
		$this->assertEqual($termsTree, $expected);
	}

/**
 * testAdminMoveup
 *
 * @return void
 */
	public function testAdminMoveup() {
		$this->expectFlashAndRedirect('Moved up successfully');
		$this->testAction('admin/taxonomy/terms/moveup/2/1'); // ID of Announcements and Categories
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
		$expected = array(
			'announcements' => 'Announcements',
			'uncategorized' => 'Uncategorized',
		);
		$this->assertEqual($termsTree, $expected);
	}

/**
 * testAdminMovedown
 *
 * @return void
 */
	public function testAdminMovedown() {
		$this->expectFlashAndRedirect('Moved down successfully');
		$this->testAction('admin/taxonomy/terms/movedown/1/1'); // ID of Uncategorized and Categories
		$termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
		$expected = array(
			'announcements' => 'Announcements',
			'uncategorized' => 'Uncategorized',
		);
		$this->assertEqual($termsTree, $expected);
	}

}
Back to Top