forked from Cavemanon/cavepaintings
fix all the tests (for sqlite, php7.4, osx, at least)
This commit is contained in:
@@ -39,6 +39,14 @@ class AddAliasEvent extends Event
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteAliasEvent extends Event {
|
||||
public $oldtag;
|
||||
|
||||
public function __construct(string $oldtag) {
|
||||
$this->oldtag = $oldtag;
|
||||
}
|
||||
}
|
||||
|
||||
class AddAliasException extends SCoreException
|
||||
{
|
||||
}
|
||||
@@ -58,8 +66,7 @@ class AliasEditor extends Extension
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["c_oldtag"=>"string", "c_newtag"=>"string"]);
|
||||
try {
|
||||
$aae = new AddAliasEvent($input['c_oldtag'], $input['c_newtag']);
|
||||
send_event($aae);
|
||||
send_event(new AddAliasEvent($input['c_oldtag'], $input['c_newtag']));
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("alias/list"));
|
||||
} catch (AddAliasException $ex) {
|
||||
@@ -70,8 +77,7 @@ class AliasEditor extends Extension
|
||||
if ($user->can(Permissions::MANAGE_ALIAS_LIST)) {
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["d_oldtag"=>"string"]);
|
||||
$database->execute("DELETE FROM aliases WHERE oldtag=:oldtag", ["oldtag" => $input['d_oldtag']]);
|
||||
log_info("alias_editor", "Deleted alias for ".$input['d_oldtag'], "Deleted alias");
|
||||
send_event(new DeleteAliasEvent($input['d_oldtag']));
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("alias/list"));
|
||||
}
|
||||
@@ -136,6 +142,12 @@ class AliasEditor extends Extension
|
||||
log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}", "Added alias");
|
||||
}
|
||||
|
||||
public function onDeleteAlias(DeleteAliasEvent $event) {
|
||||
global $database;
|
||||
$database->execute("DELETE FROM aliases WHERE oldtag=:oldtag", ["oldtag" => $event->oldtag]);
|
||||
log_info("alias_editor", "Deleted alias for {$event->oldtag}", "Deleted alias");
|
||||
}
|
||||
|
||||
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
|
||||
{
|
||||
if ($event->parent=="tags") {
|
||||
@@ -168,8 +180,7 @@ class AliasEditor extends Extension
|
||||
$parts = str_getcsv($line);
|
||||
if (count($parts) == 2) {
|
||||
try {
|
||||
$aae = new AddAliasEvent($parts[0], $parts[1]);
|
||||
send_event($aae);
|
||||
send_event(new AddAliasEvent($parts[0], $parts[1]));
|
||||
} catch (AddAliasException $ex) {
|
||||
$this->theme->display_error(500, "Error adding alias", $ex->getMessage());
|
||||
}
|
||||
|
@@ -10,98 +10,74 @@ class AliasEditorTest extends ShimmiePHPUnitTestCase
|
||||
|
||||
public function testAliasListReadOnly()
|
||||
{
|
||||
// Check that normal users can't add aliases.
|
||||
$this->log_in_as_user();
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->assert_no_text("Add");
|
||||
|
||||
$this->log_out();
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->assert_no_text("Add");
|
||||
}
|
||||
|
||||
public function testAliasEditor()
|
||||
{
|
||||
/*
|
||||
**********************************************************************
|
||||
* FIXME: TODO:
|
||||
* For some reason the alias tests always fail when they are running
|
||||
* inside the TravisCI VM environment. I have tried to determine
|
||||
* the exact cause of this, but have been unable to pin it down.
|
||||
*
|
||||
* For now, I am commenting them out until I have more time to
|
||||
* dig into this and determine exactly what is happening.
|
||||
*
|
||||
*********************************************************************
|
||||
*/
|
||||
$this->markTestIncomplete();
|
||||
|
||||
public function testAliasOneToOne() {
|
||||
$this->log_in_as_admin();
|
||||
|
||||
# test one to one
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->set_field('oldtag', "test1");
|
||||
$this->set_field('newtag', "test2");
|
||||
$this->clickSubmit('Add');
|
||||
$this->assert_no_text("Error adding alias");
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
$this->assert_no_text("test1");
|
||||
|
||||
send_event(new AddAliasEvent("test1", "test2"));
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_text("test1");
|
||||
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
$this->assert_text("test1,test2");
|
||||
$this->assert_text('"test1","test2"');
|
||||
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test1");
|
||||
$this->get_page("post/view/$image_id"); # check that the tag has been replaced
|
||||
$this->assert_title("Image $image_id: test2");
|
||||
$this->get_page("post/list/test1/1"); # searching for an alias should find the master tag
|
||||
$this->assert_title("Image $image_id: test2");
|
||||
$this->assert_response(302);
|
||||
$this->get_page("post/list/test2/1"); # check that searching for the main tag still works
|
||||
$this->assert_title("Image $image_id: test2");
|
||||
$this->assert_response(302);
|
||||
$this->delete_image($image_id);
|
||||
|
||||
$this->get_page('alias/list');
|
||||
$this->click("Remove");
|
||||
send_event(new DeleteAliasEvent("test1"));
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->assert_no_text("test1");
|
||||
}
|
||||
|
||||
# test one to many
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->set_field('oldtag', "onetag");
|
||||
$this->set_field('newtag', "multi tag");
|
||||
$this->click("Add");
|
||||
public function testAliasOneToMany() {
|
||||
$this->log_in_as_admin();
|
||||
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
$this->assert_no_text("multi");
|
||||
|
||||
send_event(new AddAliasEvent("onetag", "multi tag"));
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_text("multi");
|
||||
$this->assert_text("tag");
|
||||
|
||||
$this->get_page("alias/export/aliases.csv");
|
||||
$this->assert_text("onetag,multi tag");
|
||||
$this->assert_text('"onetag","multi tag"');
|
||||
|
||||
$image_id_1 = $this->post_image("tests/pbx_screenshot.jpg", "onetag");
|
||||
$image_id_2 = $this->post_image("tests/bedroom_workshop.jpg", "onetag");
|
||||
// FIXME: known broken
|
||||
//$this->get_page("post/list/onetag/1"); # searching for an aliased tag should find its aliases
|
||||
//$this->assert_title("onetag");
|
||||
//$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/onetag/1"); # searching for an aliased tag should find its aliases
|
||||
$this->assert_title("multi tag");
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/multi/1");
|
||||
$this->assert_title("multi");
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->get_page("post/list/multi%20tag/1");
|
||||
$this->get_page("post/list/multi tag/1");
|
||||
$this->assert_title("multi tag");
|
||||
$this->assert_no_text("No Images Found");
|
||||
$this->delete_image($image_id_1);
|
||||
$this->delete_image($image_id_2);
|
||||
|
||||
$this->get_page('alias/list');
|
||||
$this->click("Remove");
|
||||
send_event(new DeleteAliasEvent("onetag"));
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->assert_no_text("test1");
|
||||
|
||||
$this->log_out();
|
||||
|
||||
$this->get_page('alias/list');
|
||||
$this->assert_title("Alias List");
|
||||
$this->assert_no_text("Add");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user