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

/modules/gallery/tests/Albums_Controller_Test.php

http://github.com/gallery/gallery3
PHP | 74 lines | 45 code | 9 blank | 20 comment | 0 complexity | 71372f3c96a116cf701ed272cb737f2f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php defined("SYSPATH") or die("No direct script access.");
  2. /**
  3. * Gallery - a web based photo album viewer and editor
  4. * Copyright (C) 2000-2013 Bharat Mediratta
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. class Albums_Controller_Test extends Gallery_Unit_Test_Case {
  21. public function setup() {
  22. $this->_save = array($_POST, $_SERVER);
  23. }
  24. public function teardown() {
  25. list($_POST, $_SERVER) = $this->_save;
  26. }
  27. public function change_album_test() {
  28. $controller = new Albums_Controller();
  29. $album = test::random_album();
  30. // Randomize to avoid conflicts.
  31. $new_name = "new_name_" . test::random_string(6);
  32. $_POST["name"] = $new_name;
  33. $_POST["title"] = "new title";
  34. $_POST["description"] = "new description";
  35. $_POST["column"] = "weight";
  36. $_POST["direction"] = "ASC";
  37. $_POST["csrf"] = access::csrf_token();
  38. $_POST["slug"] = "new-name";
  39. access::allow(identity::everybody(), "edit", item::root());
  40. ob_start();
  41. $controller->update($album->id);
  42. $album->reload();
  43. $results = ob_get_contents();
  44. ob_end_clean();
  45. $this->assert_equal(json_encode(array("result" => "success")), $results);
  46. $this->assert_equal($new_name, $album->name);
  47. $this->assert_equal("new title", $album->title);
  48. $this->assert_equal("new description", $album->description);
  49. }
  50. public function change_album_no_csrf_fails_test() {
  51. $controller = new Albums_Controller();
  52. $album = test::random_album();
  53. $_POST["name"] = "new name";
  54. $_POST["title"] = "new title";
  55. $_POST["description"] = "new description";
  56. access::allow(identity::everybody(), "edit", item::root());
  57. try {
  58. $controller->update($album->id);
  59. $this->assert_true(false, "This should fail");
  60. } catch (Exception $e) {
  61. // pass
  62. $this->assert_same("@todo FORBIDDEN", $e->getMessage());
  63. }
  64. }
  65. }