Skip to content

Commit

Permalink
Misc fixes, mostly getting tests passing on my new Linux box
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgraham committed Aug 12, 2019
1 parent 1f1b9df commit 8b76b72
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion _tests/codechecker/codechecker.sh
@@ -1,7 +1,7 @@
#!/bin/sh

if [ ! -f "netbeans/dist/Code_Quality_Checker.jar" ]; then
cd _tests/codechecker
cd "$(dirname "$0")"
fi

java -jar "netbeans/dist/Code_Quality_Checker.jar"
6 changes: 6 additions & 0 deletions _tests/tests/unit_tests/_lang_spelling.php
Expand Up @@ -31,6 +31,12 @@ public function testSpelling()

// Many of these aren't real words, but they appear for good reasons so we whitelist them
$okay_words = array(
'exifrotated',
'runexiftest',
'runquadranttest',
'toystory',
'turkish',
'yourbaseurl',
'phpbeans',
'javabeans',
'systemd',
Expand Down
4 changes: 2 additions & 2 deletions _tests/tests/unit_tests/addon_references.php
Expand Up @@ -30,7 +30,7 @@ public function setUp()
public function testPHP()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#addon_installed\(\'([^\']*)\'\)#', $_c, $matches);
Expand All @@ -45,7 +45,7 @@ public function testPHP()
public function testTemplates()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.tpl') {
if ((substr($c, -4) == '.tpl') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#\{\$ADDON_INSTALLED,(\w+)\}#', $_c, $matches);
Expand Down
16 changes: 8 additions & 8 deletions _tests/tests/unit_tests/broken_includes.php
Expand Up @@ -30,7 +30,7 @@ public function setUp()
public function testRequireCode()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
if ($c == 'data_custom/execute_temp.php') {
continue;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ public function testRequireCode()
public function testRequireLang()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#require_lang\(\'([^\']+)\'\)#', $_c, $matches);
Expand All @@ -75,7 +75,7 @@ public function testRequireLang()
public function testRequireLangB()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#do_lang(_tempcode)?\(\'([^\']+):([^\']+)\'\)#', $_c, $matches);
Expand All @@ -91,7 +91,7 @@ public function testRequireLangB()
public function testRequireLangC()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.tpl') {
if ((substr($c, -4) == '.tpl') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#\{\!(\w+):(\w+)\}#', $_c, $matches);
Expand All @@ -107,7 +107,7 @@ public function testRequireLangC()
public function testRequireCSS()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#require_css\(\'([^\']+)\'\)#', $_c, $matches);
Expand All @@ -123,7 +123,7 @@ public function testRequireCSS()
public function testRequireCSSB()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.tpl') {
if ((substr($c, -4) == '.tpl') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#\{\$REQUIRE_CSS,(\w+)\}#', $_c, $matches);
Expand All @@ -139,7 +139,7 @@ public function testRequireCSSB()
public function testRequireJavascript()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.php') {
if ((substr($c, -4) == '.php') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#require_javascript\(\'([^\']+)\'\)#', $_c, $matches);
Expand All @@ -155,7 +155,7 @@ public function testRequireJavascript()
public function testRequireJavascriptB()
{
foreach ($this->contents as $c) {
if (substr($c, -4) == '.tpl') {
if ((substr($c, -4) == '.tpl') && (!should_ignore_file($c, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$_c = file_get_contents(get_file_base() . '/' . $c);
$matches = array();
$num_matches = preg_match_all('#\{\$REQUIRE_JAVASCRIPT,(\w+)\}#', $_c, $matches);
Expand Down
3 changes: 2 additions & 1 deletion _tests/tests/unit_tests/database_misc.php
Expand Up @@ -339,6 +339,7 @@ public function testFullTextSearch()

list($content, $boolean_search, $expected, $fields, $raw_fields) = $bits;
list($content_where) = build_content_where($content, $boolean_search, $boolean_operator);
$order = '';
$rows = get_search_rows(
'test',
'id',
Expand All @@ -354,7 +355,7 @@ public function testFullTextSearch()
$fields,
'',
$content_where,
'',
$order,
'r.id',
$raw_fields
);
Expand Down
8 changes: 8 additions & 0 deletions _tests/tests/unit_tests/geocoding.php
Expand Up @@ -18,6 +18,14 @@
*/
class geocoding_test_set extends cms_test_case
{
public function setUp()
{
parent::setUp();

// Please don't use this on a live site, we just need these to test against
set_option('google_geocode_api_key', 'AIzaSyD-jqeO_HlD1bLmA68JhAJOBajZw96-UHE');
}

public function testIPGeocode()
{
$test = $GLOBALS['SITE_DB']->query_select_value_if_there('ip_country', 'id');
Expand Down
4 changes: 2 additions & 2 deletions _tests/tests/unit_tests/modularisation.php
Expand Up @@ -133,9 +133,9 @@ private function do_dir($dir = '')
continue;
}

$ignore = IGNORE_CUSTOM_DIR_GROWN_CONTENTS | IGNORE_NONBUNDLED_EXTREMELY_SCATTERED | IGNORE_CUSTOM_ZONES | IGNORE_CUSTOM_THEMES | IGNORE_NON_EN_SCATTERED_LANGS | IGNORE_BUNDLED_UNSHIPPED_VOLATILE | IGNORE_REVISION_FILES;
$ignore = ((preg_match('#^docs#', $dir . $file) == 0) ? IGNORE_CUSTOM_DIR_GROWN_CONTENTS : 0) | IGNORE_NONBUNDLED_EXTREMELY_SCATTERED | IGNORE_CUSTOM_ZONES | IGNORE_CUSTOM_THEMES | IGNORE_NON_EN_SCATTERED_LANGS | IGNORE_BUNDLED_UNSHIPPED_VOLATILE | IGNORE_REVISION_FILES;
//$ignore = IGNORE_NONBUNDLED_EXTREMELY_SCATTERED | IGNORE_CUSTOM_THEMES | IGNORE_NON_EN_SCATTERED_LANGS | IGNORE_BUNDLED_UNSHIPPED_VOLATILE; Uncomment for more careful testing
if ((should_ignore_file($dir . $file, $ignore, 0)) && (preg_match('#^docs#', $dir . $file) == 0)) {
if (should_ignore_file($dir . $file, $ignore, 0)) {
continue;
}

Expand Down
42 changes: 22 additions & 20 deletions _tests/tests/unit_tests/notifications.php
Expand Up @@ -25,19 +25,21 @@ public function testNotificationsQuerying()
return;
}

if ($GLOBALS['FORUM_DB']->query_select_value('f_members', 'COUNT(*)') > 1000) {
if ($GLOBALS['FORUM_DB']->query_select_value('f_members', 'COUNT(*)') > 300) {
$this->assertTrue(false, 'Test will not work on databases with a lot of users');
return;
}

require_code('notifications');
require_code('hooks/systems/notifications/cns_birthday');
require_code('hooks/systems/notifications/cns_friend_birthday');
require_code('hooks/systems/notifications/comment_posted');
require_code('hooks/systems/notifications/cns_password_changed');

$GLOBALS['SITE_DB']->query_delete('notifications_enabled');
$GLOBALS['SITE_DB']->query_delete('notification_lockdown');
$GLOBALS['SITE_DB']->query_delete('member_zone_access');

$GLOBALS['FORUM_DB']->query_update('f_members', array('m_allow_emails' => 1, 'm_allow_emails_from_staff' => 1));

$all_members = $GLOBALS['FORUM_DB']->query_select('f_members', array('id'), null, 'WHERE id<>' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' AND m_validated=1 AND ' . db_string_equal_to('m_validated_email_confirm_code', ''));

foreach ($all_members as $member) {
Expand All @@ -50,58 +52,58 @@ public function testNotificationsQuerying()

// Check default empty state...

$ob = new Hook_notification_cns_birthday();
$results = $ob->list_members_who_have_enabled('cns_birthday');
$ob = new Hook_notification_comment_posted();
$results = $ob->list_members_who_have_enabled('comment_posted');
$this->assertTrue(count($results[0]) == 0);
$results = $ob->list_members_who_have_enabled('cns_birthday', null, array(get_member())); // Just make sure the member-ID filter doesn't crash
$results = $ob->list_members_who_have_enabled('comment_posted', null, array(get_member())); // Just make sure the member-ID filter doesn't crash

$ob = new Hook_notification_cns_friend_birthday();
$results = $ob->list_members_who_have_enabled('cns_friend_birthday');
$ob = new Hook_notification_cns_password_changed();
$results = $ob->list_members_who_have_enabled('cns_password_changed');
$this->assertTrue(count($results[0]) == count($all_members));

// Check explicitly flipped state...

foreach ($all_members as $member) {
$GLOBALS['SITE_DB']->query_insert('notifications_enabled', array(
'l_member_id' => $member['id'],
'l_notification_code' => 'cns_birthday',
'l_notification_code' => 'comment_posted',
'l_code_category' => '',
'l_setting' => A_INSTANT_EMAIL,
));

$GLOBALS['SITE_DB']->query_insert('notifications_enabled', array(
'l_member_id' => $member['id'],
'l_notification_code' => 'cns_friend_birthday',
'l_notification_code' => 'cns_password_changed',
'l_code_category' => '',
'l_setting' => A_NA,
));
}

$ob = new Hook_notification_cns_birthday();
$results = $ob->list_members_who_have_enabled('cns_birthday');
$ob = new Hook_notification_comment_posted();
$results = $ob->list_members_who_have_enabled('comment_posted');
$this->assertTrue(count($results[0]) == count($all_members));

$ob = new Hook_notification_cns_friend_birthday();
$results = $ob->list_members_who_have_enabled('cns_friend_birthday');
$ob = new Hook_notification_cns_password_changed();
$results = $ob->list_members_who_have_enabled('cns_password_changed');
$this->assertTrue(count($results[0]) == 0);

// Check with locking...

$GLOBALS['SITE_DB']->query_insert('notification_lockdown', array(
'l_notification_code' => 'cns_birthday',
'l_notification_code' => 'comment_posted',
'l_setting' => A_NA,
));
$GLOBALS['SITE_DB']->query_insert('notification_lockdown', array(
'l_notification_code' => 'cns_friend_birthday',
'l_notification_code' => 'cns_password_changed',
'l_setting' => A_INSTANT_EMAIL,
));

$ob = new Hook_notification_cns_birthday();
$results = $ob->list_members_who_have_enabled('cns_birthday');
$ob = new Hook_notification_comment_posted();
$results = $ob->list_members_who_have_enabled('comment_posted');
$this->assertTrue(count($results[0]) == 0);

$ob = new Hook_notification_cns_friend_birthday();
$results = $ob->list_members_who_have_enabled('cns_friend_birthday');
$ob = new Hook_notification_cns_password_changed();
$results = $ob->list_members_who_have_enabled('cns_password_changed');
$this->assertTrue(count($results[0]) == count($all_members));
}

Expand Down
11 changes: 11 additions & 0 deletions _tests/tests/unit_tests/specsettings_documented.php
Expand Up @@ -24,6 +24,8 @@ public function setUp()
@set_time_limit(0);
}

disable_php_memory_limit();

require_code('files2');

parent::setUp();
Expand Down Expand Up @@ -92,6 +94,9 @@ public function testInstallOptions()

$files = get_directory_contents(get_file_base());
foreach ($files as $f) {
if (should_ignore_file($f, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS)) {
continue;
}
if ((substr($f, -4) == '.php') && (basename($f) != 'shared_installs.php') && (strpos($f, '_tests/') === false) && (strpos($f, 'tracker/') === false) && (strpos($f, 'exports/') === false) && (strpos($f, '_custom') === false) && (strpos($f, 'exports/') === false) && ($f != '_config.php') && (basename($f) != 'errorlog.php') && (basename($f) != 'phpstub.php') && (basename($f) != 'permissioncheckslog.php')) {
$c = file_get_contents(get_file_base() . '/' . $f);
$all_code .= $c;
Expand Down Expand Up @@ -166,6 +171,9 @@ public function testValueOptions()

$files = get_directory_contents(get_file_base());
foreach ($files as $f) {
if (should_ignore_file($f, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS)) {
continue;
}
if (((substr($f, -4) == '.php') || (substr($f, -4) == '.tpl') || (substr($f, -3) == '.js')) && (basename($f) != 'upgrade.php') && (basename($f) != 'shared_installs.php') && (strpos($f, '_tests/') === false) && (strpos($f, 'tracker/') === false) && (strpos($f, 'exports/') === false) && (strpos($f, '_custom/') === false) && (strpos($f, 'exports/') === false) && (basename($f) != 'errorlog.php') && (basename($f) != 'phpstub.php') && (basename($f) != 'permissioncheckslog.php')) {
$c = file_get_contents(get_file_base() . '/' . $f);
$all_code .= $c;
Expand Down Expand Up @@ -221,6 +229,9 @@ public function testKeepSettings()
$files = get_directory_contents(get_file_base());
$files[] = 'install.php';
foreach ($files as $f) {
if ((should_ignore_file($f, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS)) && ($f != 'install.php')) {
continue;
}
if (((substr($f, -4) == '.php') || (substr($f, -4) == '.tpl')) && (basename($f) != 'shared_installs.php') && (strpos($f, '_tests/') === false) && (strpos($f, 'tracker/') === false) && (strpos($f, 'exports/') === false) && (strpos($f, '_custom/') === false) && (strpos($f, 'sources/forum/') === false) && (basename($f) != 'errorlog.php') && (basename($f) != 'phpstub.php') && (basename($f) != 'permissioncheckslog.php')) {
$c = file_get_contents($f);
$all_code .= $c;
Expand Down
3 changes: 3 additions & 0 deletions _tests/tests/unit_tests/ssl.php
Expand Up @@ -25,6 +25,9 @@ public function testHTTPSStatus()
return;
}

if (get_domain() == 'localhost') {
set_value('disable_ssl_for__' . get_domain(), '1');
}
$test = http_download_file('https://' . get_domain(), null, false);
if ($test === null) {
$this->assertTrue(false, 'SSL not running on this machine');
Expand Down
2 changes: 1 addition & 1 deletion _tests/tests/unit_tests/tutorials_broken_links.php
Expand Up @@ -50,7 +50,7 @@ public function testLinksFromCode()
require_code('files2');
$files = get_directory_contents(get_file_base());
foreach ($files as $file) {
if (substr($file, -4) == '.php') {
if ((substr($file, -4) == '.php') && (!should_ignore_file($file, IGNORE_BUNDLED_VOLATILE | IGNORE_CUSTOM_DIR_GROWN_CONTENTS))) {
$contents = file_get_contents(get_file_base() . '/' . $file);

$matches = array();
Expand Down
1 change: 1 addition & 0 deletions _tests/tests/unit_tests/tutorials_codebox.php
Expand Up @@ -61,6 +61,7 @@ public function testTutorialLangConsistency()
'URL',
'objc',
'nginx',
'Diff',

// Use this if nothing else (or [font="Courier"]...[/font])
'Text',
Expand Down
2 changes: 1 addition & 1 deletion _tests/tests/unit_tests/xml_sitemaps.php
Expand Up @@ -29,7 +29,7 @@ public function setUp()
public function testSitemapAdd()
{
$id = add_news_category('Test' . uniqid('', true));
$page_link = '_SEARCH:news:browse:' . strval($id);
$page_link = get_module_zone('news') . ':news:browse:' . strval($id);
$last_updated = $GLOBALS['SITE_DB']->query_select_value('sitemap_cache', 'last_updated', array('page_link' => $page_link));
$this->assertTrue($last_updated >= time() - 3);
}
Expand Down
4 changes: 2 additions & 2 deletions data_custom/functions.dat

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sources/locations_geocoding.php
Expand Up @@ -140,14 +140,14 @@ function _google_geocode($url_params, &$error_msg = null)
}

$key = get_option('google_geocode_api_key');
/*if ($key == '') { Actually, does work
if ($key == '') {
$error_msg = do_lang_tempcode('GOOGLE_GEOCODE_API_NOT_CONFIGURED');
return null;
}*/
}

require_code('json');

$url = 'http://maps.googleapis.com/maps/api/geocode/json';
$url = 'https://maps.googleapis.com/maps/api/geocode/json';
$url .= '?language=' . urlencode(strtolower(get_site_default_lang()));
if ($key != '') {
$url .= '&key=' . urlencode($key);
Expand Down
3 changes: 3 additions & 0 deletions sources/sitemap_xml.php
Expand Up @@ -194,6 +194,9 @@ function rebuild_sitemap_index()
}

//$last_updated = $sitemap_set['last_updated']; Actually no, because this cannot find deletes
if (!is_file($path)) {
continue; // Should not happen, but don't crash
}
$last_updated = filemtime($path);
$xml_date = xmlentities(date('Y-m-d\TH:i:s', $last_updated) . substr_replace(date('O', $last_updated), ':', 3, 0));

Expand Down
2 changes: 1 addition & 1 deletion sources/themes.php
Expand Up @@ -146,7 +146,7 @@ function find_theme_image($id, $silent_fail = false, $leave_local = false, $them

// Dynamic fixup possible?
if ($theme != 'default') {
if (!file_exists(get_custom_file_base() . '/.git')) { // Do not automatically remap missing theme images if running out of git - could be that git operator is doing a resync between servers
if (!file_exists(get_custom_file_base() . '/.git')) { // Do not automatically remap missing theme images if running out of git - could be that git operator is doing a re-sync between servers
$url_path = $db->query_select_value_if_there('theme_images', 'path', array('id' => $id, 'theme' => 'default', 'lang' => $lang));
if ($url_path !== null) {
$db->query_update('theme_images', array('path' => $url_path), array('id' => $id, 'theme' => $theme, 'lang' => $lang), '', 1);
Expand Down

0 comments on commit 8b76b72

Please sign in to comment.