summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-04-21 06:48:08 -0700
committerTim Almdal <tnalmdal@shaw.ca>2010-04-21 06:48:08 -0700
commit0565d9f0f92ef9bd69c38e997e7c6e6d05d56ee1 (patch)
tree22e5cdf12adbb77bc05e6cfa968ded72d26f5995 /modules
parent027312596c29c1986d3480c7dda48533e6dd3ca8 (diff)
parent2257776f9b4c231033656db1eb23246035aa42fd (diff)
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/controllers/albums.php1
-rw-r--r--modules/gallery/controllers/reauthenticate.php2
-rw-r--r--modules/gallery/tests/Item_Rest_Helper_Test.php70
-rw-r--r--modules/rest/tests/Rest_Controller_Test.php1
-rw-r--r--modules/tag/tests/Tag_Item_Rest_Helper_Test.php2
-rw-r--r--modules/tag/tests/Tag_Rest_Helper_Test.php32
-rw-r--r--modules/tag/tests/Tags_Rest_Helper_Test.php8
-rw-r--r--modules/user/controllers/users.php2
-rw-r--r--modules/user/helpers/user.php8
9 files changed, 59 insertions, 67 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 730db9ae..ea15418f 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -107,6 +107,7 @@ class Albums_Controller extends Items_Controller {
if ($valid) {
$album->save();
+ module::event("album_add_form_completed", $album, $form);
log::success("content", "Created an album",
html::anchor("albums/$album->id", "view album"));
message::success(t("Created album %album_title",
diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php
index b2a67f01..3503d80a 100644
--- a/modules/gallery/controllers/reauthenticate.php
+++ b/modules/gallery/controllers/reauthenticate.php
@@ -63,7 +63,7 @@ class Reauthenticate_Controller extends Controller {
$group->password("password")->label(t("Password"))->id("g-password")->class(null)
->callback("auth::validate_too_many_failed_auth_attempts")
->callback("user::valid_password")
- ->error_messages("invalid", t("Incorrect password"))
+ ->error_messages("invalid_password", t("Incorrect password"))
->error_messages(
"too_many_failed_auth_attempts",
t("Too many incorrect passwords. Try again later"));
diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php
index bef95668..0b5e0471 100644
--- a/modules/gallery/tests/Item_Rest_Helper_Test.php
+++ b/modules/gallery/tests/Item_Rest_Helper_Test.php
@@ -42,13 +42,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo1),
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
$request->url = rest::url("item", $album1);
@@ -56,13 +57,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo1),
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
$request->url = rest::url("item", $album1);
@@ -70,14 +72,15 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array())),
"members" => array(
rest::url("item", $photo1),
rest::url("item", $album2),
rest::url("item", $photo2)),
- "relationships" => array(
- "tags" => array(
- "url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ ),
item_rest::get($request));
}
@@ -96,12 +99,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo2)),
+ ),
item_rest::get($request));
}
@@ -118,12 +122,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array() ))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
}
@@ -134,7 +139,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->title = "my new title";
+ $request->params->entity = new stdClass();
+ $request->params->entity->title = "my new title";
item_rest::put($request);
$this->assert_equal("my new title", $album1->reload()->title);
@@ -147,8 +153,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->title = "my new title";
- $request->params->slug = "not url safe";
+ $request->params->entity = new stdClass();
+ $request->params->entity->title = "my new title";
+ $request->params->entity->slug = "not url safe";
try {
item_rest::put($request);
@@ -166,9 +173,10 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "album";
- $request->params->name = "my album";
- $request->params->title = "my album";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "album";
+ $request->params->entity->name = "my album";
+ $request->params->entity->title = "my album";
$response = item_rest::post($request);
$new_album = rest::resolve($response["url"]);
@@ -183,10 +191,11 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "album";
- $request->params->name = "my album";
- $request->params->title = "my album";
- $request->params->slug = "not url safe";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "album";
+ $request->params->entity->name = "my album";
+ $request->params->entity->title = "my album";
+ $request->params->entity->slug = "not url safe";
try {
item_rest::post($request);
@@ -205,8 +214,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "photo";
- $request->params->name = "my photo.jpg";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "photo";
+ $request->params->entity->name = "my photo.jpg";
$request->file = MODPATH . "gallery/tests/test.jpg";
$response = item_rest::post($request);
$new_photo = rest::resolve($response["url"]);
diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php
index 6d09b214..fe83283d 100644
--- a/modules/rest/tests/Rest_Controller_Test.php
+++ b/modules/rest/tests/Rest_Controller_Test.php
@@ -27,6 +27,7 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case {
public function teardown() {
list($_GET, $_POST, $_SERVER) = $this->_save;
+ identity::set_active_user(identity::admin_user());
}
public function login_test() {
diff --git a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php
index e5acab93..533f832d 100644
--- a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php
+++ b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php
@@ -32,7 +32,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request->url = rest::url("tag_item", $tag, item::root());
$this->assert_equal_array(
array("url" => rest::url("tag_item", $tag, item::root()),
- "members" => array(
+ "entity" => array(
"tag" => rest::url("tag", $tag),
"item" => rest::url("item", item::root()))),
tag_item_rest::get($request));
diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php
index f4d5a14a..a8aa89d4 100644
--- a/modules/tag/tests/Tag_Rest_Helper_Test.php
+++ b/modules/tag/tests/Tag_Rest_Helper_Test.php
@@ -67,41 +67,13 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case {
tag_rest::get($request));
}
- public function post_test() {
- $tag = test::random_tag();
-
- // Create an editable item to be tagged
- $album = test::random_album();
- access::allow(identity::everybody(), "edit", $album);
-
- // Add the album to the tag
- $request = new stdClass();
- $request->url = rest::url("tag", $tag);
- $request->params = new stdClass();
- $request->params->url = rest::url("item", $album);
- $this->assert_equal_array(
- array("url" => rest::url("tag_item", $tag, $album)),
- tag_rest::post($request));
- }
-
- public function post_with_no_item_url_test() {
- $request = new stdClass();
- try {
- tag_rest::post($request);
- } catch (Rest_Exception $e) {
- $this->assert_equal(400, $e->getCode());
- return;
- }
-
- $this->assert_true(false, "Shouldn't get here");
- }
-
public function put_test() {
$tag = test::random_tag();
$request = new stdClass();
$request->url = rest::url("tag", $tag);
$request->params = new stdClass();
- $request->params->name = "new name";
+ $request->params->entity = new stdClass();
+ $request->params->entity->name = "new name";
tag_rest::put($request);
$this->assert_equal("new name", $tag->reload()->name);
diff --git a/modules/tag/tests/Tags_Rest_Helper_Test.php b/modules/tag/tests/Tags_Rest_Helper_Test.php
index a0ebc8c3..99332c7c 100644
--- a/modules/tag/tests/Tags_Rest_Helper_Test.php
+++ b/modules/tag/tests/Tags_Rest_Helper_Test.php
@@ -45,11 +45,12 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case {
}
public function post_test() {
- access::allow(identity::everybody(), "edit", item::root());
+ identity::set_active_user(identity::guest());
$request = new stdClass();
$request->params = new stdClass();
- $request->params->name = "test tag";
+ $request->params->entity = new stdClass();
+ $request->params->entity->name = "test tag";
$this->assert_equal(
array("url" => url::site("rest/tag/1")),
tags_rest::post($request));
@@ -63,7 +64,8 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case {
try {
$request = new stdClass();
$request->params = new stdClass();
- $request->params->name = "test tag";
+ $request->params->entity = new stdClass();
+ $request->params->entity->name = "test tag";
tags_rest::post($request);
} catch (Exception $e) {
$this->assert_equal(403, $e->getCode());
diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php
index e1f1fa2b..7f3f6b1f 100644
--- a/modules/user/controllers/users.php
+++ b/modules/user/controllers/users.php
@@ -167,7 +167,7 @@ class Users_Controller extends Controller {
$group->password("old_password")->label(t("Old password"))->id("g-password")
->callback("auth::validate_too_many_failed_auth_attempts")
->callback("user::valid_password")
- ->error_messages("invalid", t("Incorrect password"))
+ ->error_messages("invalid_password", t("Incorrect password"))
->error_messages(
"too_many_failed_auth_attempts",
t("Too many incorrect passwords. Try again later"));
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 650dcf6a..55153263 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -72,7 +72,13 @@ class user_Core {
static function valid_password($password_input) {
if (!user::is_correct_password(identity::active_user(), $password_input->value)) {
- $password_input->add_error("invalid", 1);
+ $password_input->add_error("invalid_password", 1);
+ }
+ }
+
+ static function valid_username($text_input) {
+ if (!self::lookup_by_name($text_input->value)) {
+ $text_input->add_error("invalid_username", 1);
}
}