Skip to content

Commit

Permalink
Update all tests. No functional changes, but now they all pass - woot!
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Apr 29, 2013
1 parent 13ff0f8 commit 8f83326
Showing 1 changed file with 58 additions and 72 deletions.
130 changes: 58 additions & 72 deletions modules/gallery/tests/Item_Model_Test.php
Expand Up @@ -129,8 +129,7 @@ public function test_photo_rename_wont_accept_slash() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_slashes", $errors["name"]);
$this->assertEquals("no_slashes", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand All @@ -149,8 +148,7 @@ public function test_photo_rename_wont_accept_backslash() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_backslashes", $errors["name"]);
$this->assertEquals("no_backslashes", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand All @@ -169,8 +167,7 @@ public function test_photo_rename_wont_accept_trailing_period() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_trailing_period", $errors["name"]);
$this->assertEquals("no_trailing_period", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand All @@ -189,8 +186,7 @@ public function test_album_rename_wont_accept_slash() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_slashes", $errors["name"]);
$this->assertEquals("no_slashes", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand All @@ -209,8 +205,7 @@ public function test_album_rename_wont_accept_backslash() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_backslashes", $errors["name"]);
$this->assertEquals("no_backslashes", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand All @@ -229,8 +224,7 @@ public function test_album_rename_wont_accept_trailing_period() {
$item->check();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$errors = $e->validation->errors();
$this->assertSame("no_trailing_period", $errors["name"]);
$this->assertEquals("no_trailing_period", $e->errors()["name"][0]);
}
// Should be corrected on save.
$item->save();
Expand Down Expand Up @@ -310,8 +304,8 @@ public function test_move_album_with_conflicting_target_gets_uniquified() {
$source->save();

// foo should become foo-01
$this->assertSame("{$album->name}-01", $source->name);
$this->assertSame("{$album->slug}-01", $source->slug);
$this->assertEquals("{$album->name}-01", $source->name);
$this->assertEquals("{$album->slug}-01", $source->slug);
}

public function test_move_album_fails_wrong_target_type() {
Expand All @@ -324,11 +318,10 @@ public function test_move_album_fails_wrong_target_type() {
try {
$album->parent_id = $photo->id;
$album->save();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertEquals(array("parent_id" => "invalid"), $e->validation->errors());
return;
$this->assertEquals("invalid", $e->errors()["parent_id"][0]);
}
$this->assertTrue(false, "Shouldn't get here");
}

public function test_move_photo_with_conflicting_target_gets_uniquified() {
Expand All @@ -345,10 +338,10 @@ public function test_move_photo_with_conflicting_target_gets_uniquified() {
$photo2->save();

// foo.jpg should become foo-01.jpg
$this->assertSame(pathinfo($photo1->name, PATHINFO_FILENAME) . "-01.jpg", $photo2->name);
$this->assertEquals(pathinfo($photo1->name, PATHINFO_FILENAME) . "-01.jpg", $photo2->name);

// foo should become foo-01
$this->assertSame("{$photo1->slug}-01", $photo2->slug);
$this->assertEquals("{$photo1->slug}-01", $photo2->slug);
}

public function test_move_album_inside_descendent_fails() {
Expand All @@ -359,11 +352,10 @@ public function test_move_album_inside_descendent_fails() {
try {
$album1->parent_id = $album3->id;
$album1->save();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertEquals(array("parent_id" => "invalid"), $e->validation->errors());
return;
$this->assertEquals("invalid", $e->errors()["parent_id"][0]);
}
$this->assertTrue(false, "Shouldn't get here");
}


Expand All @@ -380,20 +372,17 @@ public function test_basic_validation() {
$item->type = "bogus";
try {
$item->save();
$this->assertFalse(true, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(array("description" => "max_length",
"name" => "not_empty",
"title" => "not_empty",
"album_cover_item_id" => "valid_album_cover",
"parent_id" => "invalid",
"sort_column" => "invalid",
"sort_order" => "invalid",
"type" => "invalid"),
$e->validation->errors());
return;
$this->assertEquals("max_length", $e->errors()["description"][0]);
$this->assertEquals("not_empty", $e->errors()["name"][0]);
$this->assertEquals("not_empty", $e->errors()["title"][0]);
$this->assertEquals("invalid_item", $e->errors()["album_cover_item_id"][0]);
$this->assertEquals("invalid", $e->errors()["parent_id"][0]);
$this->assertEquals("invalid", $e->errors()["sort_column"][0]);
$this->assertEquals("invalid", $e->errors()["sort_order"][0]);
$this->assertEquals("invalid", $e->errors()["type"][0]);
}

$this->assertFalse(true, "Shouldn't get here");
}

public function test_slug_is_url_safe() {
Expand All @@ -403,7 +392,7 @@ public function test_slug_is_url_safe() {
$album->save();
$this->assertTrue(false, "Shouldn't be able to save");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(array("slug" => "not_url_safe"), $e->validation->errors());
$this->assertEquals("not_url_safe", $e->errors()["slug"][0]);
}

// This should work
Expand All @@ -423,13 +412,13 @@ public function test_cant_change_item_type() {
$photo->type = "movie";
$photo->mime_type = "video/x-flv";
$photo->save();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(
array("name" => "illegal_data_file_extension", "type" => "read_only"),
$e->validation->errors());
return; // pass
array("name" => array("illegal_data_file_extension", null),
"type" => array("read_only", null)),
$e->errors());
}
$this->assertTrue(false, "Shouldn't get here");
}

public function test_photo_files_must_have_an_extension() {
Expand All @@ -449,11 +438,10 @@ public function test_movie_files_must_have_an_extension() {
public function test_cant_delete_root_album() {
try {
Item::root()->delete();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(array("id" => "cant_delete_root_album"), $e->validation->errors());
return; // pass
$this->assertEquals("cant_delete_root_album", $e->errors()["id"][0]);
}
$this->assertTrue(false, "Shouldn't get here");
}

public function test_as_restful_array() {
Expand All @@ -462,8 +450,8 @@ public function test_as_restful_array() {
$album->reload();

$result = $album->as_restful_array();
$this->assertSame(Rest::url("item", Item::root()), $result["parent"]);
$this->assertSame(Rest::url("item", $photo), $result["album_cover"]);
$this->assertEquals(Rest::url("item", Item::root()), $result["parent"]);
$this->assertEquals(Rest::url("item", $photo), $result["album_cover"]);
$this->assertTrue(!array_key_exists("parent_id", $result));
$this->assertTrue(!array_key_exists("album_cover_item_id", $result));
}
Expand Down Expand Up @@ -538,11 +526,10 @@ public function test_unsafe_data_file_replacement() {
$photo = Test::random_photo();
$photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php");
$photo->save();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(array("name" => "invalid_data_file"), $e->validation->errors());
return; // pass
$this->assertEquals("invalid_data_file", $e->errors()["name"][0]);
}
$this->assertTrue(false, "Shouldn't get here");
}

public function test_unsafe_data_file_replacement_with_valid_extension() {
Expand All @@ -552,11 +539,10 @@ public function test_unsafe_data_file_replacement_with_valid_extension() {
$photo = Test::random_photo();
$photo->set_data_file($temp_file);
$photo->save();
$this->assertTrue(false, "Shouldn't get here");
} catch (ORM_Validation_Exception $e) {
$this->assertSame(array("name" => "invalid_data_file"), $e->validation->errors());
return; // pass
$this->assertEquals("invalid_data_file", $e->errors()["name"][0]);
}
$this->assertTrue(false, "Shouldn't get here");
}

public function test_urls() {
Expand Down Expand Up @@ -657,8 +643,8 @@ public function test_no_conflict_when_parents_different() {
$photo2->save();

// photo2 has same name and slug as photo1 but different parent - no conflict.
$this->assertSame($photo1->name, $photo2->name);
$this->assertSame($photo1->slug, $photo2->slug);
$this->assertEquals($photo1->name, $photo2->name);
$this->assertEquals($photo1->slug, $photo2->slug);
}

public function test_fix_conflict_when_names_identical() {
Expand All @@ -673,8 +659,8 @@ public function test_fix_conflict_when_names_identical() {
$photo2->save();

// photo2 has same name as photo1 - conflict resolved by renaming with -01.
$this->assertSame("{$photo1_orig_base}-01.jpg", $photo2->name);
$this->assertSame("{$photo2_orig_slug}-01", $photo2->slug);
$this->assertEquals("{$photo1_orig_base}-01.jpg", $photo2->name);
$this->assertEquals("{$photo2_orig_slug}-01", $photo2->slug);
}

public function test_fix_conflict_when_slugs_identical() {
Expand All @@ -688,8 +674,8 @@ public function test_fix_conflict_when_slugs_identical() {
$photo2->save();

// photo2 has same slug as photo1 - conflict resolved by renaming with -01.
$this->assertSame("{$photo2_orig_base}-01.jpg", $photo2->name);
$this->assertSame("{$photo1->slug}-01", $photo2->slug);
$this->assertEquals("{$photo2_orig_base}-01.jpg", $photo2->name);
$this->assertEquals("{$photo1->slug}-01", $photo2->slug);
}

public function test_no_conflict_when_parents_different_for_albums() {
Expand All @@ -703,8 +689,8 @@ public function test_no_conflict_when_parents_different_for_albums() {
$album2->save();

// album2 has same name and slug as album1 but different parent - no conflict.
$this->assertSame($album1->name, $album2->name);
$this->assertSame($album1->slug, $album2->slug);
$this->assertEquals($album1->name, $album2->name);
$this->assertEquals($album1->slug, $album2->slug);
}

public function test_fix_conflict_when_names_identical_for_albums() {
Expand All @@ -718,8 +704,8 @@ public function test_fix_conflict_when_names_identical_for_albums() {
$album2->save();

// album2 has same name as album1 - conflict resolved by renaming with -01.
$this->assertSame("{$album1->name}-01", $album2->name);
$this->assertSame("{$album2_orig_slug}-01", $album2->slug);
$this->assertEquals("{$album1->name}-01", $album2->name);
$this->assertEquals("{$album2_orig_slug}-01", $album2->slug);
}

public function test_fix_conflict_when_slugs_identical_for_albums() {
Expand All @@ -733,8 +719,8 @@ public function test_fix_conflict_when_slugs_identical_for_albums() {
$album2->save();

// album2 has same slug as album1 - conflict resolved by renaming with -01.
$this->assertSame("{$album2_orig_name}-01", $album2->name);
$this->assertSame("{$album1->slug}-01", $album2->slug);
$this->assertEquals("{$album2_orig_name}-01", $album2->name);
$this->assertEquals("{$album1->slug}-01", $album2->slug);
}

public function test_no_conflict_when_base_names_identical_between_album_and_photo() {
Expand All @@ -748,8 +734,8 @@ public function test_no_conflict_when_base_names_identical_between_album_and_pho
$photo->save();

// photo has same base name as album - no conflict.
$this->assertSame("{$album->name}.jpg", $photo->name);
$this->assertSame($photo_orig_slug, $photo->slug);
$this->assertEquals("{$album->name}.jpg", $photo->name);
$this->assertEquals($photo_orig_slug, $photo->slug);
}

public function test_fix_conflict_when_full_names_identical_between_album_and_photo() {
Expand All @@ -763,8 +749,8 @@ public function test_fix_conflict_when_full_names_identical_between_album_and_ph
$album->save();

// album has same full name as album - conflict resolved by renaming with -01.
$this->assertSame("{$photo->name}-01", $album->name);
$this->assertSame("{$album_orig_slug}-01", $album->slug);
$this->assertEquals("{$photo->name}-01", $album->name);
$this->assertEquals("{$album_orig_slug}-01", $album->slug);
}

public function test_fix_conflict_when_slugs_identical_between_album_and_photo() {
Expand All @@ -778,8 +764,8 @@ public function test_fix_conflict_when_slugs_identical_between_album_and_photo()
$photo->save();

// photo has same slug as album - conflict resolved by renaming with -01.
$this->assertSame("{$photo_orig_base}-01.jpg", $photo->name);
$this->assertSame("{$album->slug}-01", $photo->slug);
$this->assertEquals("{$photo_orig_base}-01.jpg", $photo->name);
$this->assertEquals("{$album->slug}-01", $photo->slug);
}

public function test_fix_conflict_when_base_names_identical_between_jpg_png_flv() {
Expand All @@ -800,9 +786,9 @@ public function test_fix_conflict_when_base_names_identical_between_jpg_png_flv(
$item3->save();

// item2 and item3 have same base name as item1 - conflict resolved by renaming with -01 and -02.
$this->assertSame("{$item1_orig_base}-01.png", $item2->name);
$this->assertSame("{$item2_orig_slug}-01", $item2->slug);
$this->assertSame("{$item1_orig_base}-02.flv", $item3->name);
$this->assertSame("{$item3_orig_slug}-02", $item3->slug);
$this->assertEquals("{$item1_orig_base}-01.png", $item2->name);
$this->assertEquals("{$item2_orig_slug}-01", $item2->slug);
$this->assertEquals("{$item1_orig_base}-02.flv", $item3->name);
$this->assertEquals("{$item3_orig_slug}-02", $item3->slug);
}
}

0 comments on commit 8f83326

Please sign in to comment.