context.reactions.test 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. class ContextReactionBlockTest extends DrupalWebTestCase {
  3. protected $profile = 'testing';
  4. public static function getInfo() {
  5. return array(
  6. 'name' => 'Reaction: block',
  7. 'description' => 'Test block reaction.',
  8. 'group' => 'Context',
  9. );
  10. }
  11. function setUp() {
  12. parent::setUp('context', 'ctools', 'block');
  13. $admin_user = $this->drupalCreateUser(array(
  14. 'administer site configuration',
  15. 'administer blocks'
  16. ));
  17. $this->drupalLogin($admin_user);
  18. }
  19. function test() {
  20. ctools_include('export');
  21. $context = ctools_export_new_object('context');
  22. $context->name = 'testcontext';
  23. $context->conditions = array('sitewide' => array('values' => array(1)));
  24. $context->reactions = array('block' => array('blocks' => array(
  25. 'user-online' => array(
  26. 'module' => 'user',
  27. 'delta' => 'online',
  28. 'region' => 'sidebar_first',
  29. 'weight' => 0,
  30. ),
  31. )));
  32. $saved = context_save($context);
  33. $this->assertTrue($saved, "Context 'testcontext' saved.");
  34. theme_enable(array('bartik'));
  35. variable_set('theme_default', 'bartik');
  36. $this->refreshVariables();
  37. $this->drupalGet('node');
  38. $this->assertText('Who\'s online');
  39. // Test title override of code provided block
  40. $edit = array('title' => 'Context Online Block');
  41. $this->drupalPost('admin/structure/block/manage/user/online/configure', $edit, t('Save block'));
  42. $this->drupalPost('admin/config/development/performance', array(), t('Clear all caches'));
  43. $this->drupalGet('node');
  44. $this->assertText('Context Online Block');
  45. // Test title of custom block
  46. $edit = array(
  47. 'info' => 'Context Custom Block Info',
  48. 'title' => 'Context Custom Block Title',
  49. 'body[value]' => $this->randomName(32),
  50. );
  51. $this->drupalPost('admin/structure/block/add', $edit, t('Save block'));
  52. $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $edit['info']))->fetchField();
  53. $context->reactions['block']['blocks']["block-{$bid}"] = array(
  54. 'module' => 'block',
  55. 'delta' => $bid,
  56. 'region' => 'sidebar_first',
  57. 'weight' => 2,
  58. );
  59. $saved = context_save($context);
  60. $this->assertTrue($saved, "Context 'testcontext' saved.");
  61. $this->drupalGet('node');
  62. $this->assertText('Context Custom Block Title');
  63. // Cleanup
  64. context_delete($context);
  65. }
  66. }
  67. class ContextReactionBlockAjaxTest extends DrupalWebTestCase {
  68. protected $profile = 'testing';
  69. public static function getInfo() {
  70. return array(
  71. 'name' => 'Reaction: block ajax',
  72. 'description' => 'Test block reaction ajax behavior.',
  73. 'group' => 'Context',
  74. );
  75. }
  76. function setUp() {
  77. parent::setUp('context', 'ctools');
  78. $admin_user = $this->drupalCreateUser(array('administer site configuration'));
  79. $this->drupalLogin($admin_user);
  80. }
  81. function test() {
  82. $token = drupal_hmac_base64('user-online', $this->session_id . drupal_get_private_key() . drupal_get_hash_salt());
  83. $this->drupalGet('node', array(
  84. 'query' => array('context_block' => 'user-online,testcontext', 'context_token' => $token)
  85. ));
  86. $this->assertText('"status":1', 'Successful return status. $drupal_hash_salt must be set explicitly for this test to pass');
  87. $this->assertText('Who\\u0027s online', 'Expected text in block data. drupal_hash_salt must be set explicitly for this test to pass');
  88. }
  89. }
  90. class ContextReactionMenuTest extends DrupalWebTestCase {
  91. protected $profile = 'testing';
  92. public static function getInfo() {
  93. return array(
  94. 'name' => 'Reaction: menu',
  95. 'description' => 'Test menu reaction.',
  96. 'group' => 'Context',
  97. );
  98. }
  99. function setUp() {
  100. parent::setUp('context', 'ctools', 'menu', 'blog');
  101. $admin_user = $this->drupalCreateUser(array(
  102. 'administer menu',
  103. 'administer nodes',
  104. 'administer site configuration',
  105. 'create blog content',
  106. ));
  107. $this->drupalLogin($admin_user);
  108. }
  109. function test() {
  110. ctools_include('export');
  111. $context = ctools_export_new_object('context');
  112. $context->name = 'testcontext';
  113. $context->conditions = array('sitewide' => array('values' => array(1)));
  114. $context->reactions = array('menu' => 'node/add');
  115. $saved = context_save($context);
  116. $this->assertTrue($saved, "Context 'testcontext' saved.");
  117. $this->drupalPost('admin/structure/menu/settings', array('menu_main_links_source' => 'navigation'), 'Save configuration');
  118. theme_enable(array('bartik'));
  119. variable_set('theme_default', 'bartik');
  120. $this->refreshVariables();
  121. $output = $this->drupalGet('user');
  122. $url = url('node/add');
  123. $active = $this->xpath('//li[contains(@class, "active")]/a[@href="' . $url . '"]');
  124. $this->assertTrue(!empty($active), t('Active menu item found.'));
  125. // Cleanup
  126. context_delete($context);
  127. }
  128. }
  129. class ContextReactionBreadcrumbTest extends DrupalWebTestCase {
  130. protected $profile = 'testing';
  131. public static function getInfo() {
  132. return array(
  133. 'name' => 'Reaction: breadcrumb',
  134. 'description' => 'Test breadcrumb reaction.',
  135. 'group' => 'Context',
  136. );
  137. }
  138. function setUp() {
  139. parent::setUp('context', 'ctools');
  140. $admin_user = $this->drupalCreateUser(array(
  141. 'access administration pages',
  142. 'administer nodes',
  143. 'administer site configuration'
  144. ));
  145. $this->drupalLogin($admin_user);
  146. }
  147. function test() {
  148. ctools_include('export');
  149. $context = ctools_export_new_object('context');
  150. $context->name = 'testcontext';
  151. $context->conditions = array('path' => array('values' => array('node')));
  152. $context->reactions = array('breadcrumb' => 'admin/structure');
  153. $saved = context_save($context);
  154. $this->assertTrue($saved, "Context 'testcontext' saved.");
  155. theme_enable(array('bartik'));
  156. variable_set('theme_default', 'bartik');
  157. $this->refreshVariables();
  158. $output = $this->drupalGet('node');
  159. $this->assertText('Home » Administration » Structure');
  160. $output = $this->drupalGet('user');
  161. $this->assertNoText('Home » Administration » Structure');
  162. // Cleanup
  163. context_delete($context);
  164. }
  165. }
  166. class ContextReactionThemeHtmlTest extends DrupalWebTestCase {
  167. protected $profile = 'testing';
  168. public static function getInfo() {
  169. return array(
  170. 'name' => 'Reaction: theme html',
  171. 'description' => 'Test theme html reaction.',
  172. 'group' => 'Context',
  173. );
  174. }
  175. function setUp() {
  176. parent::setUp('context', 'ctools');
  177. $admin_user = $this->drupalCreateUser(array(
  178. 'access administration pages',
  179. 'administer nodes',
  180. 'administer site configuration'
  181. ));
  182. $this->drupalLogin($admin_user);
  183. }
  184. function test() {
  185. ctools_include('export');
  186. $context = ctools_export_new_object('context');
  187. $context->name = 'testcontext';
  188. $context->conditions = array('sitewide' => array('values' => array(1)));
  189. $context->reactions = array('theme_html' => array('class' => 'context-test-class'));
  190. $saved = context_save($context);
  191. $this->assertTrue($saved, "Context 'testcontext' saved.");
  192. $output = $this->drupalGet('node');
  193. $this->assertRaw('context-test-class');
  194. // Cleanup
  195. context_delete($context);
  196. }
  197. }
  198. class ContextReactionRegionTest extends DrupalWebTestCase {
  199. protected $profile = 'testing';
  200. public static function getInfo() {
  201. return array(
  202. 'name' => 'Reaction: Region',
  203. 'description' => 'Test Region disable reaction.',
  204. 'group' => 'Context',
  205. );
  206. }
  207. function setUp() {
  208. parent::setUp('context', 'ctools');
  209. $admin_user = $this->drupalCreateUser(array(
  210. 'access administration pages',
  211. 'administer nodes',
  212. 'administer site configuration'
  213. ));
  214. $this->drupalLogin($admin_user);
  215. }
  216. function test() {
  217. ctools_include('export');
  218. theme_enable(array('bartik'));
  219. variable_set('theme_default', 'bartik');
  220. global $theme;
  221. $context = ctools_export_new_object('context');
  222. $context->name = 'testcontext';
  223. $context->conditions = array('sitewide' => array('values' => array(1)));
  224. $context->reactions = array(
  225. 'block' => array(
  226. 'blocks' => array(
  227. 'user-online' => array(
  228. 'module' => 'user',
  229. 'delta' => 'online',
  230. 'region' => 'sidebar_first',
  231. 'weight' => '-10',
  232. ),
  233. ),
  234. ),
  235. 'region' => array('bartik' => array('disable' => array('sidebar_first' => 'sidebar_first')))
  236. );
  237. $saved = context_save($context);
  238. $this->assertTrue($saved, "Context 'testcontext' saved.");
  239. $output = $this->drupalGet('node');
  240. $this->assertNoText("Who's online");
  241. // Cleanup
  242. context_delete($context);
  243. }
  244. }