FeatureContext.php 10 KB

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