fix all the tests (for sqlite, php7.4, osx, at least)

This commit is contained in:
Shish
2020-01-28 21:19:59 +00:00
parent ac1076b3f3
commit 615da9e9d2
57 changed files with 665 additions and 859 deletions

View File

@@ -113,7 +113,7 @@ class BasePage
// ==============================================
/** @var string */
private $redirect = "";
public $redirect = "";
/**
* Set the URL to redirect to (remember to use make_link() if linking
@@ -256,6 +256,19 @@ class BasePage
$this->blocks[] = $block;
}
/**
* Find a block which contains the given text
* (Useful for unit tests)
*/
public function find_block(string $text): ?Block {
foreach($this->blocks as $block) {
if($block->header == $text) {
return $block;
}
}
return null;
}
// ==============================================
/**
@@ -298,8 +311,7 @@ class BasePage
# header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 600) . ' GMT');
#}
usort($this->blocks, "blockcmp");
$pnbe = new PageNavBuildingEvent();
send_event($pnbe);
$pnbe = send_event(new PageNavBuildingEvent());
$nav_links = $pnbe->links;
@@ -314,14 +326,12 @@ class BasePage
$sub_links = null;
// If one is, we just query for sub-menu options under that one tab
if ($active_link!==null) {
$psnbe = new PageSubNavBuildingEvent($active_link->name);
send_event($psnbe);
$psnbe = send_event(new PageSubNavBuildingEvent($active_link->name));
$sub_links = $psnbe->links;
} else {
// Otherwise we query for the sub-items under each of the tabs
foreach ($nav_links as $link) {
$psnbe = new PageSubNavBuildingEvent($link->name);
send_event($psnbe);
$psnbe = send_event(new PageSubNavBuildingEvent($link->name));
// Now we check for a current link so we can identify the sub-links to show
foreach ($psnbe->links as $sub_link) {
@@ -338,8 +348,6 @@ class BasePage
}
}
$sub_links = $sub_links??[];
usort($nav_links, "sort_nav_links");
usort($sub_links, "sort_nav_links");

View File

@@ -228,7 +228,9 @@ class CommandEvent extends Event
}
}
define("CLI_LOG_LEVEL", $log_level);
if(!defined("CLI_LOG_LEVEL")) {
define("CLI_LOG_LEVEL", $log_level);
}
if (count($opts) > 0) {
$this->cmd = $opts[0];

View File

@@ -8,8 +8,7 @@
* return data to the extension which sent them, for example:
*
* \code
* $tfe = new TextFormattingEvent($original_text);
* send_event($tfe);
* $tfe = send_event(new TextFormattingEvent($original_text));
* $formatted_text = $tfe->formatted;
* \endcode
*
@@ -381,16 +380,14 @@ abstract class DataHandlerExtension extends Extension
throw new UploadException("Data handler failed to create image object from data");
}
$ire = new ImageReplaceEvent($image_id, $image);
send_event($ire);
$ire = send_event(new ImageReplaceEvent($image_id, $image));
$event->image_id = $image_id;
} else {
$image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->hash), $event->metadata);
if (is_null($image)) {
throw new UploadException("Data handler failed to create image object from data");
}
$iae = new ImageAdditionEvent($image);
send_event($iae);
$iae = send_event(new ImageAdditionEvent($image));
$event->image_id = $iae->image->id;
$event->merged = $iae->merged;

View File

@@ -247,8 +247,7 @@ class Image
* Turn a bunch of strings into a bunch of TagCondition
* and ImgCondition objects
*/
$stpe = new SearchTermParseEvent(null, $terms);
send_event($stpe);
$stpe = send_event(new SearchTermParseEvent(null, $terms));
if ($stpe->is_querylet_set()) {
foreach ($stpe->get_querylets() as $querylet) {
$img_conditions[] = new ImgCondition($querylet, true);
@@ -265,8 +264,7 @@ class Image
continue;
}
$stpe = new SearchTermParseEvent($term, $terms);
send_event($stpe);
$stpe = send_event(new SearchTermParseEvent($term, $terms));
if ($stpe->is_querylet_set()) {
foreach ($stpe->get_querylets() as $querylet) {
$img_conditions[] = new ImgCondition($querylet, $positive);
@@ -674,8 +672,7 @@ class Image
public function parse_metatags(array $metatags, int $image_id): void
{
foreach ($metatags as $tag) {
$ttpe = new TagTermParseEvent($tag, $image_id, true);
send_event($ttpe);
send_event(new TagTermParseEvent($tag, $image_id, true));
}
}
@@ -735,8 +732,7 @@ class Image
// nothing seems to use this, sending the event out to 50 exts is a lot of overhead
if (!SPEED_HAX) {
$plte = new ParseLinkTemplateEvent($tmpl, $this);
send_event($plte);
$plte = send_event(new ParseLinkTemplateEvent($tmpl, $this));
$tmpl = $plte->link;
}

View File

@@ -68,11 +68,10 @@ function add_image(string $tmpname, string $filename, string $tags): void
if (array_key_exists('extension', $pathinfo)) {
$metadata['extension'] = $pathinfo['extension'];
}
$metadata['tags'] = Tag::explode($tags);
$metadata['source'] = null;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
send_event(new DataUploadEvent($tmpname, $metadata));
}
/**

View File

@@ -93,13 +93,13 @@ $_shm_event_count = 0;
/**
* Send an event to all registered Extensions.
*/
function send_event(Event $event): void
function send_event(Event $event): Event
{
global $tracer_enabled;
global $_shm_event_listeners, $_shm_event_count, $_tracer;
if (!isset($_shm_event_listeners[get_class($event)])) {
return;
return $event;
}
$method_name = "on".str_replace("Event", "", get_class($event));
@@ -130,4 +130,6 @@ function send_event(Event $event): void
if ($tracer_enabled) {
$_tracer->end();
}
return $event;
}

View File

@@ -178,8 +178,7 @@ function get_session_ip(Config $config): string
*/
function format_text(string $string): string
{
$tfe = new TextFormattingEvent($string);
send_event($tfe);
$tfe = send_event(new TextFormattingEvent($string));
return $tfe->formatted;
}