From e0fdde32878216e1c291386e7d3931ac0de5c807 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 17:13:54 +0000 Subject: [PATCH] Fix the tests, hopefully --- src/Model/Contact.php | 2 +- tests/datasets/api.fixture.php | 205 +++++++++++--------- tests/datasets/storage/database.fixture.php | 8 + 3 files changed, 125 insertions(+), 90 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 3fa8e74b48..0184861c3c 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1077,7 +1077,7 @@ class Contact if (!empty($contact)) { $contact_id = $contact["id"]; - if (empty($update)) { + if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]); return $contact_id; } diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index fbf2aad47c..2c6512f8c6 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -71,95 +71,6 @@ return [ 'theme' => 'frio', ], ], - 'contact' => [ - [ - 'id' => 42, - 'uid' => 42, - 'name' => 'Self contact', - 'nick' => 'selfcontact', - 'self' => 1, - 'nurl' => 'http://localhost/profile/selfcontact', - 'url' => 'http://localhost/profile/selfcontact', - 'about' => 'User used in tests', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FOLLOWER, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - // Having the same name and nick allows us to test - // the fallback to api_get_nick() in api_get_user() - [ - 'id' => 43, - 'uid' => 0, - 'name' => 'othercontact', - 'nick' => 'othercontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/othercontact', - 'url' => 'http://localhost/profile/othercontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::NOTHING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 44, - 'uid' => 42, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 45, - 'uid' => 0, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 46, - 'uid' => 42, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FRIEND, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 47, - 'uid' => 0, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - ], 'item-uri' => [ [ 'id' => 1, @@ -191,6 +102,122 @@ return [ 'uri' => '6', 'guid' => '6', ], + + [ + 'id' => 42, + 'uri' => 'http://localhost/profile/selfcontact', + 'guid' => '42', + ], + [ + 'id' => 43, + 'uri' => 'http://localhost/profile/othercontact', + 'guid' => '43', + ], + [ + 'id' => 44, + 'uri' => 'http://localhost/profile/friendcontact', + 'guid' => '44', + ], + [ + 'id' => 46, + 'uri' => 'http://localhost/profile/mutualcontact', + 'guid' => '46', + ], + ], + 'contact' => [ + [ + 'id' => 42, + 'uid' => 42, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 1, + 'nurl' => 'http://localhost/profile/selfcontact', + 'url' => 'http://localhost/profile/selfcontact', + 'about' => 'User used in tests', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FOLLOWER, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + // Having the same name and nick allows us to test + // the fallback to api_get_nick() in api_get_user() + [ + 'id' => 43, + 'uid' => 0, + 'uri-id' => 43, + 'name' => 'othercontact', + 'nick' => 'othercontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/othercontact', + 'url' => 'http://localhost/profile/othercontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::NOTHING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 44, + 'uid' => 42, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 45, + 'uid' => 0, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 46, + 'uid' => 42, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FRIEND, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 47, + 'uid' => 0, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], ], 'verb' => [ [ diff --git a/tests/datasets/storage/database.fixture.php b/tests/datasets/storage/database.fixture.php index 6a73d4ed2a..9a8c675319 100644 --- a/tests/datasets/storage/database.fixture.php +++ b/tests/datasets/storage/database.fixture.php @@ -33,10 +33,18 @@ return [ 'theme' => 'frio', ], ], + 'item-uri' => [ + [ + 'id' => 42, + 'uri' => 'http://localhost/profile/selfcontact', + 'guid' => '42', + ], + ], 'contact' => [ [ 'id' => 42, 'uid' => 42, + 'uri-id' => 42, 'name' => 'Self contact', 'nick' => 'selfcontact', 'self' => 1,