FeatureContext.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. use Behat\Behat\Context\ClosuredContextInterface,
  3. Behat\Behat\Context\TranslatedContextInterface,
  4. Behat\Behat\Context\BehatContext,
  5. Behat\MinkExtension\Context\MinkContext;
  6. //
  7. // Require 3rd-party libraries here:
  8. //
  9. // require_once 'PHPUnit/Autoload.php';
  10. // require_once 'PHPUnit/Framework/Assert/Functions.php';
  11. //
  12. /**
  13. * Features context. (MinkContext extends BehatContext)
  14. */
  15. class FeatureContext extends MinkContext
  16. {
  17. /**
  18. * Initializes context.
  19. * Every scenario gets its own context object.
  20. */
  21. public function __construct()
  22. {
  23. }
  24. /**
  25. * @Given /^I am a platform administrator$/
  26. */
  27. public function iAmAPlatformAdministrator()
  28. {
  29. $this->visit('/index.php?logout=logout');
  30. $this->iAmOnHomepage();
  31. $this->fillField('login', 'admin');
  32. $this->fillField('password', 'admin');
  33. $this->pressButton('submitAuth');
  34. $this->getSession()->back();
  35. }
  36. /**
  37. * @Given /^I am a session administrator$/
  38. */
  39. public function iAmASessionAdministrator()
  40. {
  41. $this->visit('/index.php?logout=logout');
  42. $this->iAmOnHomepage();
  43. $this->fillFields(new \Behat\Gherkin\Node\TableNode([
  44. ['login', 'amaurichard'],
  45. ['password', 'amaurichard']
  46. ]));
  47. $this->pressButton('submitAuth');
  48. }
  49. /**
  50. * @Given /^I am a teacher$/
  51. */
  52. public function iAmATeacher()
  53. {
  54. $this->visit('/index.php?logout=logout');
  55. $this->iAmOnHomepage();
  56. $this->fillField('login', 'mmosquera');
  57. $this->fillField('password', 'mmosquera');
  58. $this->pressButton('submitAuth');
  59. }
  60. /**
  61. * @Given /^I am a teacher in course "([^"]*)"$/
  62. * @Todo implement
  63. */
  64. public function iAmATeacherInCourse($course)
  65. {
  66. //$sql = "SELECT * FROM course_rel_user WHERE c_id = X AND user_id = ";
  67. //$result = ...
  68. //if ($result !== false) { ... }
  69. }
  70. /**
  71. * @Given /^I am a student$/
  72. */
  73. public function iAmAStudent()
  74. {
  75. $this->visit('/index.php?logout=logout');
  76. $this->iAmOnHomepage();
  77. $this->fillField('login', 'mbrandybuck');
  78. $this->fillField('password', 'mbrandybuck');
  79. $this->pressButton('submitAuth');
  80. }
  81. /**
  82. * @Given /^I am an HR manager$/
  83. */
  84. public function iAmAnHR()
  85. {
  86. $this->visit('/index.php?logout=logout');
  87. $this->iAmOnHomepage();
  88. $this->fillField('login', 'ptook');
  89. $this->fillField('password', 'ptook');
  90. $this->pressButton('submitAuth');
  91. }
  92. /**
  93. * @Given /^I am a student boss$/
  94. */
  95. public function iAmAStudentBoss()
  96. {
  97. $this->visit('/index.php?logout=logout');
  98. $this->iAmOnHomepage();
  99. $this->fillField('login', 'abaggins');
  100. $this->fillField('password', 'abaggins');
  101. $this->pressButton('submitAuth');
  102. }
  103. /**
  104. * @Given /^I am an invitee$/
  105. */
  106. public function iAmAnInvitee()
  107. {
  108. $this->visit('/index.php?logout=logout');
  109. $this->iAmOnHomepage();
  110. $this->fillField('login', 'bproudfoot');
  111. $this->fillField('password', 'bproudfoot');
  112. $this->pressButton('submitAuth');
  113. }
  114. /**
  115. * @Given /^course "([^"]*)" exists$/
  116. */
  117. public function courseExists($argument)
  118. {
  119. $this->iAmAPlatformAdministrator();
  120. $this->visit('/main/admin/course_list.php?keyword=' . $argument);
  121. $this->assertPageContainsText($argument);
  122. }
  123. /**
  124. * @Given /^course "([^"]*)" is deleted$/
  125. */
  126. public function courseIsDeleted($argument)
  127. {
  128. $this->iAmAPlatformAdministrator();
  129. $this->visit('/main/admin/course_list.php?keyword=' . $argument);
  130. $this->clickLink('Delete');
  131. }
  132. /**
  133. * @Given /^I am in course "([^"]*)"$/
  134. * @Todo redefine function to be different from I am on course TEMP homepage
  135. */
  136. public function iAmInCourse($argument)
  137. {
  138. $this->visit('/main/course_home/course_home.php?cDir=' . $argument);
  139. $this->assertElementNotOnPage('.alert-danger');
  140. }
  141. /**
  142. * @Given /^I am on course "([^"]*)" homepage$/
  143. */
  144. public function iAmOnCourseXHomepage($argument)
  145. {
  146. $this->visit('/main/course_home/course_home.php?cDir=' . $argument);
  147. $this->assertElementNotOnPage('.alert-danger');
  148. }
  149. /**
  150. * @Given /^I am a "([^"]*)" user$/
  151. */
  152. public function iAmAXUser($argument)
  153. {
  154. $this->visit('/main/auth/profile.php');
  155. $this->assertFieldContains('language', $argument);
  156. }
  157. /**
  158. * @Given /^I am logged as "([^"]*)"$/
  159. */
  160. public function iAmLoggedAs($username)
  161. {
  162. $this->visit('/index.php?logout=logout');
  163. $this->iAmOnHomepage();
  164. $this->fillFields(new \Behat\Gherkin\Node\TableNode([
  165. ['login', $username],
  166. ['password', $username]
  167. ]));
  168. $this->pressButton('submitAuth');
  169. }
  170. /**
  171. * @Given /^I have a friend named "([^"]*)" with id "([^"]*)"$/
  172. */
  173. public function iHaveAFriend($friendUsername, $friendId)
  174. {
  175. $adminId = 1;
  176. $friendId = $friendId;
  177. $friendUsername = $friendUsername;
  178. $sendInvitationURL = '/main/inc/ajax/message.ajax.php?' . http_build_query([
  179. 'a' => 'send_invitation',
  180. 'user_id' => $friendId,
  181. 'content' => 'Add me'
  182. ]);
  183. $acceptInvitationURL = '/main/inc/ajax/social.ajax.php?' . http_build_query([
  184. 'a' => 'add_friend',
  185. 'friend_id' => $adminId,
  186. 'is_my_friend' => 'friend'
  187. ]);
  188. $this->iAmAPlatformAdministrator();
  189. $this->visit($sendInvitationURL);
  190. $this->iAmLoggedAs($friendUsername);
  191. $this->visit($acceptInvitationURL);
  192. $this->iAmAPlatformAdministrator();
  193. }
  194. /**
  195. * @Given /^I have a public password-protected course named "([^"]*)" with password "([^"]*)"$/
  196. */
  197. public function iHaveAPublicPasswordProtectedCourse($code, $password)
  198. {
  199. $this->visit('/main/admin/course_add.php');
  200. $this->fillFields(new \Behat\Gherkin\Node\TableNode([
  201. ['title', 'Password Protected'],
  202. ['visual_code', $code],
  203. ['visibility', 3]
  204. ]));
  205. $this->pressButton('submit');
  206. $this->visit('/main/course_info/infocours.php?cidReq=' . $code);
  207. $this->assertPageContainsText('Course registration password');
  208. $this->fillField('course_registration_password', $password);
  209. $this->pressButton('submit_save');
  210. $this->assertFieldContains('course_registration_password', $password);
  211. }
  212. /**
  213. * @Given /^I am not logged$/
  214. */
  215. public function iAmNotLogged()
  216. {
  217. $this->visit('/index.php?logout=logout');
  218. $this->visit('I am on homepage');
  219. }
  220. /**
  221. * @When /^I invite to a friend with id "([^"]*)" to a social group with id "([^"]*)"$/
  222. */
  223. public function iInviteAFrienToASocialGroup($friendId, $groupId)
  224. {
  225. $this->visit('/main/social/group_invitation.php?id=' . $groupId);
  226. $this->fillField('invitation[]', $friendId);
  227. $this->pressButton('submit');
  228. }
  229. /**
  230. * Sometimes the top admin toolbar has form buttons
  231. * that conflicts with the main page forms so we need
  232. * to disable it
  233. * @Given /^Admin top bar is disabled$/
  234. */
  235. public function adminTopBarIsDisabled()
  236. {
  237. $this->iAmAPlatformAdministrator();
  238. $this->visit('/main/admin/settings.php');
  239. $this->fillField('search_field', 'show_admin_toolbar');
  240. $this->pressButton('submit_button');
  241. $this->selectOption('show_admin_toolbar', 'do_not_show');
  242. $this->pressButton('submit');
  243. }
  244. /**
  245. * @Given /^Admin top bar is enabled$/
  246. */
  247. public function adminTopBarIsEnabled()
  248. {
  249. $this->iAmAPlatformAdministrator();
  250. $this->visit('/main/admin/settings.php');
  251. $this->fillField('search_field', 'show_admin_toolbar');
  252. $this->pressButton('submit_button');
  253. $this->selectOption('show_admin_toolbar', 'show_to_admin_and_teachers');
  254. $this->pressButton('submit');
  255. }
  256. /**
  257. * @Given /^I am on the social group members page with id "([^"]*)"$/
  258. */
  259. public function iAmOnSocialGroupMembersPageWithId($groupId)
  260. {
  261. $this->visit('/main/social/group_view.php?id=' . $groupId);
  262. }
  263. /**
  264. * @When /^I try delete a friend with id "([^"]*)" from the social group with id "([^"]*)"$/
  265. */
  266. public function iTryDeleteAFriendFromSocialGroup($friendId, $groupId)
  267. {
  268. $this->visit('/main/social/group_members.php?' . http_build_query([
  269. 'id' => $groupId,
  270. 'u' => $friendId,
  271. 'action' => 'delete'
  272. ]));
  273. }
  274. }