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

Language PHP Lines 181
MD5 Hash 2e06c118593b14bc124fb1f5ee73477b
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
<?php
App::uses('VocabulariesController', 'Taxonomy.Controller');
App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');

/**
 * VocabulariesController Test
 */
class VocabulariesControllerTest extends CroogoControllerTestCase {

/**
 * fixtures
 */
	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->VocabulariesController = $this->generate('Taxonomy.Vocabularies', array(
			'methods' => array(
				'redirect',
			),
			'components' => array(
				'Auth' => array('user'),
				'Session',
			),
		));
		$this->VocabulariesController->Auth
			->staticExpects($this->any())
			->method('user')
			->will($this->returnCallback(array($this, 'authUserCallback')));
	}

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

/**
 * testAdminIndex
 *
 * @return void
 */
	public function testAdminIndex() {
		$this->testAction('/admin/taxonomy/vocabularies/index');
		$this->assertNotEmpty($this->vars['vocabularies']);
	}

/**
 * testAdminAdd
 *
 * @return void
 */
	public function testAdminAdd() {
		$this->expectFlashAndRedirect('The Vocabulary has been saved');
		$this->testAction('admin/taxonomy/vocabularies/add', array(
			'data' => array(
				'Vocabulary' => array(
					'title' => 'New Vocabulary',
					'alias' => 'new_vocabulary',
				),
			),
		));
		$newVocabulary = $this->VocabulariesController->Vocabulary->findByAlias('new_vocabulary');
		$this->assertEqual($newVocabulary['Vocabulary']['title'], 'New Vocabulary');
	}

/**
 * testAdminEdit
 *
 * @return void
 */
	public function testAdminEdit() {
		$this->expectFlashAndRedirect('The Vocabulary has been saved');
		$this->testAction('/admin/taxonomy/vocabularies/edit/1', array(
			'data' => array(
				'Vocabulary' => array(
					'id' => 1, // categories
					'title' => 'Categories [modified]',
				),
			),
		));
		$categories = $this->VocabulariesController->Vocabulary->findByAlias('categories');
		$this->assertEquals('Categories [modified]', $categories['Vocabulary']['title']);
	}

/**
 * testAdminDelete
 *
 * @return void
 */
	public function testAdminDelete() {
		$this->expectFlashAndRedirect('Vocabulary deleted');
		$this->testAction('admin/taxonomy/vocabularies/delete/1'); // ID of categories
		$hasAny = $this->VocabulariesController->Vocabulary->hasAny(array(
			'Vocabulary.alias' => 'categories',
		));
		$this->assertFalse($hasAny);
	}

/**
 * testAdminMoveup
 *
 * @return void
 */
	public function testAdminMoveup() {
		$this->expectFlashAndRedirect('Moved up successfully');
		$this->testAction('admin/taxonomy/vocabularies/moveup/2'); // ID of tags
		$vocabularies = $this->VocabulariesController->Vocabulary->find('list', array(
			'fields' => array(
				'id',
				'alias',
			),
			'order' => 'Vocabulary.weight ASC',
		));
		$expected = array(
			'2' => 'tags',
			'1' => 'categories',
		);
		$this->assertEqual($vocabularies, $expected);
	}

/**
 * testAdminMovedown
 *
 * @return void
 */
	public function testAdminMovedown() {
		$this->expectFlashAndRedirect('Moved down successfully');
		$this->testAction('admin/taxonomy/vocabularies/movedown/1'); // ID of categories
		$vocabularies = $this->VocabulariesController->Vocabulary->find('list', array(
			'fields' => array(
				'id',
				'alias',
			),
			'order' => 'Vocabulary.weight ASC',
		));
		$expected = array(
			'2' => 'tags',
			'1' => 'categories',
		);
		$this->assertEqual($vocabularies, $expected);
	}

}
Back to Top