Skip to content

Commit

Permalink
Merge branch 'master' into talmdal_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Almdal committed Apr 21, 2010
2 parents 0273125 + 2257776 commit 0565d9f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 67 deletions.
1 change: 1 addition & 0 deletions modules/gallery/controllers/albums.php
Expand Up @@ -107,6 +107,7 @@ public function create($parent_id) {

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",
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/controllers/reauthenticate.php
Expand Up @@ -63,7 +63,7 @@ private static function _form() {
$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"));
Expand Down
70 changes: 40 additions & 30 deletions modules/gallery/tests/Item_Rest_Helper_Test.php
Expand Up @@ -42,42 +42,45 @@ public function get_scope_test() {
$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);
$request->params->scope = "direct";
$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);
$request->params->scope = "all";
$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));
}

Expand All @@ -96,12 +99,13 @@ public function get_children_like_test() {
$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));
}

Expand All @@ -118,12 +122,13 @@ public function get_children_type_test() {
$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));
}

Expand All @@ -134,7 +139,8 @@ public function update_album_test() {
$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);
Expand All @@ -147,8 +153,9 @@ public function update_album_illegal_value_fails_test() {
$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);
Expand All @@ -166,9 +173,10 @@ public function add_album_test() {
$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"]);

Expand All @@ -183,10 +191,11 @@ public function add_album_illegal_value_fails_test() {
$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);
Expand All @@ -205,8 +214,9 @@ public function add_photo_test() {
$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"]);
Expand Down
1 change: 1 addition & 0 deletions modules/rest/tests/Rest_Controller_Test.php
Expand Up @@ -27,6 +27,7 @@ public function setup() {

public function teardown() {
list($_GET, $_POST, $_SERVER) = $this->_save;
identity::set_active_user(identity::admin_user());
}

public function login_test() {
Expand Down
2 changes: 1 addition & 1 deletion modules/tag/tests/Tag_Item_Rest_Helper_Test.php
Expand Up @@ -32,7 +32,7 @@ public function get_test() {
$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));
Expand Down
32 changes: 2 additions & 30 deletions modules/tag/tests/Tag_Rest_Helper_Test.php
Expand Up @@ -67,41 +67,13 @@ public function get_with_no_relationships_test() {
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);
Expand Down
8 changes: 5 additions & 3 deletions modules/tag/tests/Tags_Rest_Helper_Test.php
Expand Up @@ -45,11 +45,12 @@ public function get_test() {
}

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));
Expand All @@ -63,7 +64,8 @@ public function post_fails_without_permissions_test() {
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());
Expand Down
2 changes: 1 addition & 1 deletion modules/user/controllers/users.php
Expand Up @@ -167,7 +167,7 @@ private function _get_change_password_form($user) {
$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"));
Expand Down
8 changes: 7 additions & 1 deletion modules/user/helpers/user.php
Expand Up @@ -72,7 +72,13 @@ static function is_correct_password($user, $password) {

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);
}
}

Expand Down

0 comments on commit 0565d9f

Please sign in to comment.