PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Contacts/Test/Case/Controller/ContactsControllerTest.php

https://github.com/kareypowell/croogo
PHP | 169 lines | 126 code | 10 blank | 33 comment | 0 complexity | 6b29ba0467e9aed0cc7ce5ff6139c4e7 MD5 | raw file
  1. <?php
  2. App::uses('ContactsController', 'Contacts.Controller');
  3. App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');
  4. App::uses('CroogoTestFixture', 'Croogo.TestSuite');
  5. class ContactsControllerTest extends CroogoControllerTestCase {
  6. public $fixtures = array(
  7. 'plugin.users.aco',
  8. 'plugin.users.aro',
  9. 'plugin.users.aros_aco',
  10. 'plugin.blocks.block',
  11. 'plugin.comments.comment',
  12. 'plugin.contacts.contact',
  13. 'plugin.translate.i18n',
  14. 'plugin.settings.language',
  15. 'plugin.menus.link',
  16. 'plugin.menus.menu',
  17. 'plugin.contacts.message',
  18. 'plugin.meta.meta',
  19. 'plugin.nodes.node',
  20. 'plugin.taxonomy.model_taxonomy',
  21. 'plugin.blocks.region',
  22. 'plugin.users.role',
  23. 'plugin.settings.setting',
  24. 'plugin.taxonomy.taxonomy',
  25. 'plugin.taxonomy.term',
  26. 'plugin.taxonomy.type',
  27. 'plugin.taxonomy.types_vocabulary',
  28. 'plugin.users.user',
  29. 'plugin.taxonomy.vocabulary',
  30. );
  31. /**
  32. * setUp
  33. *
  34. * @return void
  35. */
  36. public function setUp() {
  37. parent::setUp();
  38. $this->ContactsController = $this->generate('Contacts.Contacts', array(
  39. 'methods' => array(
  40. 'redirect',
  41. '_send_email',
  42. ),
  43. 'components' => array(
  44. 'Auth' => array('user'),
  45. 'Session',
  46. ),
  47. ));
  48. $this->controller->plugin = 'Contacts';
  49. $this->controller->Auth
  50. ->staticExpects($this->any())
  51. ->method('user')
  52. ->will($this->returnCallback(array($this, 'authUserCallback')));
  53. }
  54. /**
  55. * tearDown
  56. *
  57. * @return void
  58. */
  59. public function tearDown() {
  60. parent::tearDown();
  61. unset($this->ContactsController);
  62. }
  63. /**
  64. * testAdminIndex
  65. *
  66. * @return void
  67. */
  68. public function testAdminIndex() {
  69. $this->testAction('/admin/contacts/contacts/index');
  70. $this->assertNotEmpty($this->vars['contacts']);
  71. }
  72. /**
  73. * testAdminAdd
  74. *
  75. * @return void
  76. */
  77. public function testAdminAdd() {
  78. $this->expectFlashAndRedirect('The Contact has been saved');
  79. $this->testAction('/admin/contacts/contacts/add', array(
  80. 'data' => array(
  81. 'Contact' => array(
  82. 'title' => 'New contact',
  83. 'alias' => 'new_contact',
  84. ),
  85. ),
  86. ));
  87. $newContact = $this->ContactsController->Contact->findByAlias('new_contact');
  88. $this->assertEqual($newContact['Contact']['title'], 'New contact');
  89. }
  90. /**
  91. * testAdminEdit
  92. *
  93. * @return void
  94. */
  95. public function testAdminEdit() {
  96. $this->expectFlashAndRedirect('The Contact has been saved');
  97. $this->testAction('/admin/contacts/contacts/edit/1', array(
  98. 'data' => array(
  99. 'Contact' => array(
  100. 'id' => 1,
  101. 'title' => 'Contact [modified]',
  102. ),
  103. ),
  104. ));
  105. $result = $this->controller->Contact->findByAlias('contact');
  106. $this->assertEquals('Contact [modified]', $result['Contact']['title']);
  107. }
  108. /**
  109. * testAdminDelete
  110. *
  111. * @return void
  112. */
  113. public function testAdminDelete() {
  114. $this->expectFlashAndRedirect('Contact deleted');
  115. $this->testAction('admin/contacts/contacts/delete/1');
  116. $hasAny = $this->ContactsController->Contact->hasAny(array(
  117. 'Contact.alias' => 'contact',
  118. ));
  119. $this->assertFalse($hasAny);
  120. }
  121. /**
  122. * testView
  123. */
  124. public function testView() {
  125. $Contacts = $this->generate('Contacts', array(
  126. 'methods' => array(
  127. '_spam_protection',
  128. '_captcha',
  129. '_send_email'
  130. ),
  131. ));
  132. $Contacts->plugin = 'Contacts';
  133. $Contacts->expects($this->once())
  134. ->method('_spam_protection')
  135. ->will($this->returnValue(true));
  136. $Contacts->expects($this->once())
  137. ->method('_captcha')
  138. ->will($this->returnValue(true));
  139. $Contacts->expects($this->once())
  140. ->method('_send_email')
  141. ->will($this->returnValue(true));
  142. $this->controller->request->params['action'] = 'view';
  143. $this->controller->request->params['url']['url'] = 'contacts/contacts/view/contact';
  144. $this->controller->request->data = array(
  145. 'Message' => array(
  146. 'name' => 'John Smith',
  147. 'email' => 'john.smith@example.com',
  148. 'title' => 'Hello',
  149. 'body' => 'text here',
  150. ),
  151. );
  152. $this->controller->startupProcess();
  153. $this->controller->view('contact');
  154. $this->assertEqual($this->controller->viewVars['continue'], true);
  155. $this->controller->testView = true;
  156. $output = $this->controller->render('view');
  157. $this->assertFalse(strpos($output, '<pre class="cake-debug">'));
  158. }
  159. }