context.reactions.test 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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', 'context_ui', 'ctools');
  78. $admin_user = $this->drupalCreateUser(array('context ajax block access'));
  79. $this->drupalLogin($admin_user);
  80. }
  81. function test() {
  82. $this->drupalGet('node', array(
  83. 'query' => array('context_block' => 'user-online,testcontext')
  84. ));
  85. $this->assertText('"status":1', 'Successful return status.');
  86. $this->assertText('Who\\u0027s online', 'Expected text in block data.');
  87. }
  88. }
  89. class ContextReactionBlockAjaxAccessTest extends DrupalWebTestCase {
  90. protected $profile = 'testing';
  91. public static function getInfo() {
  92. return array(
  93. 'name' => 'Reaction: block ajax access',
  94. 'description' => 'Test block reaction ajax access behavior.',
  95. 'group' => 'Context',
  96. );
  97. }
  98. function setUp() {
  99. parent::setUp('context', 'ctools');
  100. $admin_user = $this->drupalCreateUser();
  101. $this->drupalLogin($admin_user);
  102. }
  103. function test() {
  104. $this->drupalGet('node', array(
  105. 'query' => array('context_block' => 'user-online,testcontext')
  106. ));
  107. $this->assertText('"status":0', 'Failed return status.');
  108. }
  109. }
  110. class ContextReactionMenuTest extends DrupalWebTestCase {
  111. protected $profile = 'testing';
  112. public static function getInfo() {
  113. return array(
  114. 'name' => 'Reaction: menu',
  115. 'description' => 'Test menu reaction.',
  116. 'group' => 'Context',
  117. );
  118. }
  119. function setUp() {
  120. parent::setUp('context', 'ctools', 'menu', 'blog');
  121. $admin_user = $this->drupalCreateUser(array(
  122. 'administer menu',
  123. 'administer nodes',
  124. 'administer site configuration',
  125. 'create blog content',
  126. ));
  127. $this->drupalLogin($admin_user);
  128. }
  129. function test() {
  130. ctools_include('export');
  131. $context = ctools_export_new_object('context');
  132. $context->name = 'testcontext';
  133. $context->conditions = array('sitewide' => array('values' => array(1)));
  134. $context->reactions = array('menu' => 'node/add');
  135. $saved = context_save($context);
  136. $this->assertTrue($saved, "Context 'testcontext' saved.");
  137. $this->drupalPost('admin/structure/menu/settings', array('menu_main_links_source' => 'navigation'), 'Save configuration');
  138. theme_enable(array('bartik'));
  139. variable_set('theme_default', 'bartik');
  140. $this->refreshVariables();
  141. $output = $this->drupalGet('user');
  142. $url = url('node/add');
  143. $active = $this->xpath('//li[contains(@class, "active")]/a[@href="' . $url . '"]');
  144. $this->assertTrue(!empty($active), t('Active menu item found.'));
  145. // Cleanup
  146. context_delete($context);
  147. }
  148. }
  149. class ContextReactionBreadcrumbTest extends DrupalWebTestCase {
  150. protected $profile = 'testing';
  151. public static function getInfo() {
  152. return array(
  153. 'name' => 'Reaction: breadcrumb',
  154. 'description' => 'Test breadcrumb reaction.',
  155. 'group' => 'Context',
  156. );
  157. }
  158. function setUp() {
  159. parent::setUp('context', 'ctools');
  160. $admin_user = $this->drupalCreateUser(array(
  161. 'access administration pages',
  162. 'administer nodes',
  163. 'administer site configuration'
  164. ));
  165. $this->drupalLogin($admin_user);
  166. }
  167. function test() {
  168. ctools_include('export');
  169. $context = ctools_export_new_object('context');
  170. $context->name = 'testcontext';
  171. $context->conditions = array('path' => array('values' => array('node')));
  172. $context->reactions = array('breadcrumb' => 'admin/structure');
  173. $saved = context_save($context);
  174. $this->assertTrue($saved, "Context 'testcontext' saved.");
  175. theme_enable(array('bartik'));
  176. variable_set('theme_default', 'bartik');
  177. $this->refreshVariables();
  178. $output = $this->drupalGet('node');
  179. $this->assertText('Home » Administration » Structure');
  180. $output = $this->drupalGet('user');
  181. $this->assertNoText('Home » Administration » Structure');
  182. // Cleanup
  183. context_delete($context);
  184. }
  185. }
  186. class ContextReactionThemeHtmlTest extends DrupalWebTestCase {
  187. protected $profile = 'testing';
  188. public static function getInfo() {
  189. return array(
  190. 'name' => 'Reaction: theme html',
  191. 'description' => 'Test theme html reaction.',
  192. 'group' => 'Context',
  193. );
  194. }
  195. function setUp() {
  196. parent::setUp('context', 'ctools');
  197. $admin_user = $this->drupalCreateUser(array(
  198. 'access administration pages',
  199. 'administer nodes',
  200. 'administer site configuration'
  201. ));
  202. $this->drupalLogin($admin_user);
  203. }
  204. function test() {
  205. ctools_include('export');
  206. $context = ctools_export_new_object('context');
  207. $context->name = 'testcontext';
  208. $context->conditions = array('sitewide' => array('values' => array(1)));
  209. $context->reactions = array('theme_html' => array('class' => 'context-test-class'));
  210. $saved = context_save($context);
  211. $this->assertTrue($saved, "Context 'testcontext' saved.");
  212. $output = $this->drupalGet('node');
  213. $this->assertRaw('context-test-class');
  214. // Cleanup
  215. context_delete($context);
  216. }
  217. }
  218. class ContextReactionRegionTest extends DrupalWebTestCase {
  219. protected $profile = 'testing';
  220. public static function getInfo() {
  221. return array(
  222. 'name' => 'Reaction: Region',
  223. 'description' => 'Test Region disable reaction.',
  224. 'group' => 'Context',
  225. );
  226. }
  227. function setUp() {
  228. parent::setUp('context', 'ctools');
  229. $admin_user = $this->drupalCreateUser(array(
  230. 'access administration pages',
  231. 'administer nodes',
  232. 'administer site configuration'
  233. ));
  234. $this->drupalLogin($admin_user);
  235. }
  236. function test() {
  237. ctools_include('export');
  238. theme_enable(array('bartik'));
  239. variable_set('theme_default', 'bartik');
  240. global $theme;
  241. $context = ctools_export_new_object('context');
  242. $context->name = 'testcontext';
  243. $context->conditions = array('sitewide' => array('values' => array(1)));
  244. $context->reactions = array(
  245. 'block' => array(
  246. 'blocks' => array(
  247. 'user-online' => array(
  248. 'module' => 'user',
  249. 'delta' => 'online',
  250. 'region' => 'sidebar_first',
  251. 'weight' => '-10',
  252. ),
  253. ),
  254. ),
  255. 'region' => array('bartik' => array('disable' => array('sidebar_first' => 'sidebar_first')))
  256. );
  257. $saved = context_save($context);
  258. $this->assertTrue($saved, "Context 'testcontext' saved.");
  259. $output = $this->drupalGet('node');
  260. $this->assertNoText("Who's online");
  261. // Cleanup
  262. context_delete($context);
  263. }
  264. }