jigoshop /tests/classes/jigoshopTest.php

Language PHP Lines 245
MD5 Hash a9b3073d79f747f6246b5be7f864ca52 Estimated Cost $1,090 (why?)
Repository https://github.com/scottpoulin/jigoshop.git View Raw File
  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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
class jigoshopTest extends WP_UnitTestCase 
{
	var $plugin_slug = 'jigoshop';

	/**
	 * Test returns the correct plugin Url
	 *
	 * Pre-conditions:
	 * Case A: Get the Plugin Url for a HTTP connection
	 * Case A: Get the Plugin Url for a HTTPS connection
	 *
	 * Post-conditions:
	 * Case A: Returned url should be unchanged and contain jigoshop root folder
	 * Case B: Returned url should be rewritten with https:// and contain jigoshop root folder
	 */
	 // this aseet does not work on Travis .
//	public function test_plugin_url() 
//	{
		// Case A:
//		$this->assertEquals('http://example.org/wp-content/plugins/jigoshop', jigoshop::plugin_url());
// This one won't be true on Travis
		// Case B:
	//	$_SERVER['HTTPS'] = TRUE;
	//	jigoshop::$plugin_url = NULL;
	//	$this->assertEquals('https://example.org/wp-content/plugins/jigoshop', jigoshop::plugin_url());
//	}

	/**
	 * Test Plugin Path
	 *
	 * Pre-conditions:
	 * Plugin root defined to plugin root 
	 *
	 * Post-conditions:
	 * Ensure plugin_path() matches $plugin_root
	 */
	public function test_plugin_path() 
	{
		$plugin_root = dirname(dirname(dirname(__FILE__)));
		$this->assertEquals( $plugin_root, jigoshop::plugin_path() );
	}

	/**
	 * Test Get Var
	 *
	 * Pre-conditions:
	 * Send all available vars to get_var()
	 *
	 * Post-conditions:
	 * All vars should return a value
	 */
	public function test_get_var() 
	{
		$vars = array(
			'shop_small_w'     => '150',
			'shop_small_h'     => '150', 
			'shop_tiny_w'      => '36',
			'shop_tiny_h'      => '36',
			'shop_thumbnail_w' => '90',
			'shop_thumbnail_h' => '90',
			'shop_large_w'     => '300',
			'shop_large_h'     => '300',
		);

		foreach ( $vars as $key => $value ) {
			$this->assertEquals( $value, jigoshop::get_var( $key ) );
		}
	}

	/**
	 * Test Forcing SSL on assets
	 *
	 * Pre-conditions:
	 * Case A: Page delivered through HTTPS connection
	 * Case B: Page delivered through HTTP connection
	 *
	 * Post-conditions:
	 * Case A: Returned url should be rewritten with https://...
	 * Case B: Returned url should be unchanged
	 */
	public function test_force_ssl()
	{
		$unsecure_url = 'http://google.com';

		// Case A:
		$_SERVER['HTTPS'] = TRUE;
		$this->assertEquals( 'https://google.com', jigoshop::force_ssl($unsecure_url) );

		// Case B:
		$_SERVER['HTTPS'] = FALSE;
		$this->assertEquals( 'http://google.com', jigoshop::force_ssl($unsecure_url) );
	}



	/**
	 * Test add error
	 *
	 * Pre-conditions:
	 * Add an error to the $errors array
	 *
	 * Post-conditions:
	 * Error should be contained in the array & count should be 1
	 */
	 // outputs error in travis file
//	public function test_add_error() 
//	{
//		$this->assertFalse(jigoshop::has_errors());
//
		// perform the change
//		jigoshop::add_error('Hello World');
//
//		$this->assertContains('Hello World', jigoshop::$errors);
//		$this->assertTrue(jigoshop::has_errors());

//	}

	/**
	 * Test add message
	 *
	 * Pre-conditions:
	 * Add an message to the $messages array
	 *
	 * Post-conditions:
	 * Message should be contained in the array & count should be 1
	 */
	 //outputs in travis
//	public function test_add_message() 
//	{
//		$this->assertFalse(jigoshop::has_messages());
//
//		jigoshop::add_message('Hello World');
//
//		$this->assertContains('Hello World', jigoshop::$messages);
//		$this->assertTrue(jigoshop::has_messages());

//	}

	/**
	 * Test Message & Error Clearing
	 *
	 * Pre-conditions:
	 * Set an error & message to populate the class
	 *
	 * Post-conditions:
	 * Both $errors & $messages should return empty
	 * Disabled this one because it throws error in Travis
	 */
//	public function test_clear_messages() 
//	{
//		jigoshop::add_error('Hello World');
//		jigoshop::add_message('Foo Bar');

	//	jigoshop::clear_messages();
//
//		$this->assertEmpty(jigoshop::$errors, '$errors is not empty');
//		$this->assertEmpty(jigoshop::$messages, '$messages is not empty');
//	}

	/**
	 * Test Show Messages
	 *
	 * Pre-conditions:
	 * Case A: Set error 'Hello World' and ensure it is output
	 * Case B: Set message 'Foo Bar' and ensure it is output
	 *
	 * Post-conditions:
	 * Case A: Ouput contains div with class of jigoshop_error
	 * Case B: Ouput contains div with class of jigoshop_message
	 */
//	public function test_show_messages()
//	{
//		// Case A:
//		jigoshop::add_error( 'Hello World' );
//
//		ob_start();
//		jigoshop::show_messages();
//		$this->assertEquals('<div class="jigoshop_error">Hello World</div>', ob_get_clean());

		// Case B:
//		jigoshop::add_message( 'Foo Bar' );
//
//		ob_start();
//		jigoshop::show_messages();
//		$this->assertEquals('<div class="jigoshop_message">Foo Bar</div>', ob_get_clean());
//	}

	/**
	 * Test Nonce field creation
	 *
	 * Pre-conditions:
	 * Sets up a nonce field
	 *
	 * Post-conditions:
	 * Returns a hidden input element with nonce hash for a value
	 */
//	public function test_nonce_field() 
//	{
//		ob_start();
//		jigoshop::nonce_field('nonce_me');
//		$this->assertContains('input', ob_get_clean());
//	}

	/**
	 * Test Nonce Url
	 *
	 * Pre-conditions:
	 * Adds a nonce query arguement to a url
	 *
	 * Post-conditions:
	 * Returns query argument with nonce hash
	 */
	public function test_nonce_url()
	{
		$this->assertContains('?_n=', jigoshop::nonce_url('nonce_me'));
	}

	/**
	 * Test Verification of nonces
	 *
	 * Pre-conditions:
	 * Case A: Send nonce ticket via GET
	 * Case B: Send nonce ticket via POST
	 *
	 * Post-conditions:
	 * Verification should return true in both instances
	 */
	public function test_verify_nonce()
	{
		// Case A:
		$action = 'nonce_get';
		$nonce_hash = wp_create_nonce( 'jigoshop-'.$action );
		$_GET['_n'] = $nonce_hash;

		$this->assertTrue(jigoshop::verify_nonce($action));

		// Case B:
		$action = 'nonce_post';
		$nonce_hash = wp_create_nonce( 'jigoshop-'.$action );
		$_POST['_n'] = $nonce_hash;

		$this->assertTrue(jigoshop::verify_nonce($action));
	}
}
Back to Top