context.reactions.test 8.1 KB

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