PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/classes/disabled_jigoshopTest.php

https://github.com/scottpoulin/jigoshop
PHP | 286 lines | 126 code | 43 blank | 117 comment | 0 complexity | 60d67deefa3f881bbcca9273840d03e5 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. // Load the plugin
  3. require_once('jigoshop.php');
  4. require_once('admin/jigoshop-install.php');
  5. class WP_Test_Jigoshop extends WP_UnitTestCase
  6. {
  7. public function setUp() {
  8. parent::setUp();
  9. install_jigoshop();
  10. }
  11. public function test_enqueue() {
  12. unset($GLOBALS['wp_scripts']); // Ensure scripts are fresh
  13. $this->go_to( get_permalink(3) ); // On a jigoshop page
  14. $this->assertFalse( wp_script_is( 'jigoshop_script' ) );
  15. do_action( 'template_redirect' );
  16. $this->assertTrue( wp_script_is( 'jigoshop_script' ) );
  17. }
  18. public function test_enqueue_off() {
  19. unset($GLOBALS['wp_scripts']); // Ensure scripts are fresh
  20. $this->go_to( get_permalink(2) ); // Not a jigo page so no script
  21. $this->assertFalse( wp_script_is( 'jigoshop_script' ) );
  22. do_action( 'template_redirect' );
  23. // @rob: After redirect, we have script now
  24. $this->assertTrue( wp_script_is( 'jigoshop_script' ) );
  25. }
  26. public function test_image_sizes() {
  27. jigoshop_set_image_sizes();
  28. $sizes = get_intermediate_image_sizes();
  29. $this->assertContains('shop_tiny', $sizes);
  30. $this->assertContains('shop_thumbnail', $sizes);
  31. $this->assertContains('shop_small', $sizes);
  32. $this->assertContains('shop_large', $sizes);
  33. }
  34. public function test_page_id() {
  35. $id = jigoshop_get_page_id('cart');
  36. $this->assertLessThan($id, 0);
  37. $id = jigoshop_get_page_id('fake');
  38. $this->assertGreaterThan($id, 0);
  39. }
  40. /**
  41. * Test returns the correct plugin Url
  42. *
  43. * Pre-conditions:
  44. * Case A: Get the Plugin Url for a HTTP connection
  45. * Case A: Get the Plugin Url for a HTTPS connection
  46. *
  47. * Post-conditions:
  48. * Case A: Returned url should be unchanged and contain jigoshop root folder
  49. * Case B: Returned url should be rewritten with https:// and contain jigoshop root folder
  50. */
  51. public function test_plugin_url()
  52. {
  53. // Case A:
  54. $this->assertContains('http://', jigoshop::plugin_url());
  55. // Case B:
  56. $_SERVER['HTTPS'] = TRUE;
  57. jigoshop::$plugin_url = NULL;
  58. $this->assertContains('https://', jigoshop::plugin_url());
  59. }
  60. /**
  61. * Test Plugin Path
  62. *
  63. * Pre-conditions:
  64. * Plugin root defined to plugin root
  65. *
  66. * Post-conditions:
  67. * Ensure plugin_path() matches $plugin_root
  68. */
  69. public function test_plugin_path()
  70. {
  71. $plugin_root = dirname(dirname(dirname(__FILE__)));
  72. $this->assertEquals( $plugin_root, jigoshop::plugin_path() );
  73. }
  74. /**
  75. * Test Get Var
  76. *
  77. * Pre-conditions:
  78. * Send all available vars to get_var()
  79. *
  80. * Post-conditions:
  81. * All vars should return a value
  82. */
  83. public function test_get_var()
  84. {
  85. $vars = array(
  86. 'shop_small_w' => '150',
  87. 'shop_small_h' => '150',
  88. 'shop_tiny_w' => '36',
  89. 'shop_tiny_h' => '36',
  90. 'shop_thumbnail_w' => '90',
  91. 'shop_thumbnail_h' => '90',
  92. 'shop_large_w' => '300',
  93. 'shop_large_h' => '300',
  94. );
  95. foreach ( $vars as $key => $value ) {
  96. $this->assertEquals( $value, jigoshop::get_var( $key ) );
  97. }
  98. }
  99. /**
  100. * Test Forcing SSL on assets
  101. *
  102. * Pre-conditions:
  103. * Case A: Page delivered through HTTPS connection
  104. * Case B: Page delivered through HTTP connection
  105. *
  106. * Post-conditions:
  107. * Case A: Returned url should be rewritten with https://...
  108. * Case B: Returned url should be unchanged
  109. */
  110. public function test_force_ssl()
  111. {
  112. $unsecure_url = 'http://google.com';
  113. // Case A:
  114. $_SERVER['HTTPS'] = TRUE;
  115. $this->assertEquals( 'https://google.com', jigoshop::force_ssl($unsecure_url) );
  116. // Case B:
  117. $_SERVER['HTTPS'] = FALSE;
  118. $this->assertEquals( 'http://google.com', jigoshop::force_ssl($unsecure_url) );
  119. }
  120. /**
  121. * Test add error
  122. *
  123. * Pre-conditions:
  124. * Add an error to the $errors array
  125. *
  126. * Post-conditions:
  127. * Error should be contained in the array & count should be 1
  128. */
  129. public function test_add_error()
  130. {
  131. $this->assertFalse(jigoshop::has_errors());
  132. // perform the change
  133. jigoshop::add_error('Hello World');
  134. $this->assertContains('Hello World', jigoshop::$errors);
  135. $this->assertTrue(jigoshop::has_errors());
  136. }
  137. /**
  138. * Test add message
  139. *
  140. * Pre-conditions:
  141. * Add an message to the $messages array
  142. *
  143. * Post-conditions:
  144. * Message should be contained in the array & count should be 1
  145. */
  146. public function test_add_message()
  147. {
  148. $this->assertFalse(jigoshop::has_messages());
  149. jigoshop::add_message('Hello World');
  150. $this->assertContains('Hello World', jigoshop::$messages);
  151. $this->assertTrue(jigoshop::has_messages());
  152. }
  153. /**
  154. * Test Message & Error Clearing
  155. *
  156. * Pre-conditions:
  157. * Set an error & message to populate the class
  158. *
  159. * Post-conditions:
  160. * Both $errors & $messages should return empty
  161. */
  162. public function test_clear_messages()
  163. {
  164. jigoshop::add_error('Hello World');
  165. jigoshop::clear_messages();
  166. $this->assertEmpty(jigoshop::$errors, '$errors is not empty');
  167. }
  168. /**
  169. * Test Show Messages
  170. *
  171. * Pre-conditions:
  172. * Case A: Set error 'Hello World' and ensure it is output
  173. * Case B: Set message 'Foo Bar' and ensure it is output
  174. *
  175. * Post-conditions:
  176. * Case A: Ouput contains div with class of jigoshop_error
  177. * Case B: Ouput contains div with class of jigoshop_message
  178. */
  179. public function test_show_messages()
  180. {
  181. // Case A:
  182. jigoshop::add_error( 'Hello World' );
  183. ob_start();
  184. jigoshop::show_messages();
  185. $this->assertEquals('<div class="jigoshop_error">Hello World</div>', ob_get_clean());
  186. // Case B:
  187. jigoshop::add_message( 'Foo Bar' );
  188. ob_start();
  189. jigoshop::show_messages();
  190. $this->assertEquals('<div class="jigoshop_message">Foo Bar</div>', ob_get_clean());
  191. }
  192. /**
  193. * Test Nonce field creation
  194. *
  195. * Pre-conditions:
  196. * Sets up a nonce field
  197. *
  198. * Post-conditions:
  199. * Returns a hidden input element with nonce hash for a value
  200. */
  201. public function test_nonce_field()
  202. {
  203. ob_start();
  204. jigoshop::nonce_field('nonce_me');
  205. $this->assertContains('input', ob_get_clean());
  206. }
  207. /**
  208. * Test Nonce Url
  209. *
  210. * Pre-conditions:
  211. * Adds a nonce query arguement to a url
  212. *
  213. * Post-conditions:
  214. * Returns query argument with nonce hash
  215. */
  216. public function test_nonce_url()
  217. {
  218. $this->assertContains('?_n=', jigoshop::nonce_url('nonce_me'));
  219. }
  220. /**
  221. * Test Verification of nonces
  222. *
  223. * Pre-conditions:
  224. * Case A: Send nonce ticket via GET
  225. * Case B: Send nonce ticket via POST
  226. *
  227. * Post-conditions:
  228. * Verification should return true in both instances
  229. */
  230. public function test_verify_nonce()
  231. {
  232. // Case A:
  233. $action = 'nonce_get';
  234. $nonce_hash = wp_create_nonce( 'jigoshop-'.$action );
  235. $_GET['_n'] = $nonce_hash;
  236. $this->assertTrue(jigoshop::verify_nonce($action));
  237. // Case B:
  238. $action = 'nonce_post';
  239. $nonce_hash = wp_create_nonce( 'jigoshop-'.$action );
  240. $_POST['_n'] = $nonce_hash;
  241. $this->assertTrue(jigoshop::verify_nonce($action));
  242. }
  243. }