Having a #beer at the local. 🍺
' . PHP_EOL;
$note = Note::factory([
'note' => 'Having a #beer at the local. 🍺',
])->create();
$this->assertEquals($expected, $note->note);
}
/**
* Look for a default image in the contact’s h-card for the makeHCards method.
*/
#[Test]
public function default_image_used_as_fallback_in_makehcards_method(): void
{
// phpcs:ignore
$expected = 'Hi
Tantek Çelik
t
' . PHP_EOL;
Contact::factory()->create([
'nick' => 'tantek',
'name' => 'Tantek Çelik',
'homepage' => 'http://tantek.com',
'twitter' => 't',
'facebook' => null,
]);
$note = Note::factory()->create([
'note' => 'Hi @tantek',
]);
$this->assertEquals($expected, $note->note);
}
/**
* Look for a specific profile image in the contact’s h-card.
*/
#[Test]
public function specific_profile_image_used_in_makehcards_method(): void
{
Contact::factory()->create([
'nick' => 'aaron',
'name' => 'Aaron Parecki',
'homepage' => 'https://aaronparecki.com',
'twitter' => null,
'facebook' => 123456,
]);
$fileSystem = new Filesystem;
$fileSystem->ensureDirectoryExists(public_path('/assets/profile-images/aaronparecki.com'));
if (! $fileSystem->exists(public_path('/assets/profile-images/aaronparecki.com/image'))) {
$fileSystem->copy('./tests/aaron.png', public_path('/assets/profile-images/aaronparecki.com/image'));
}
$note = Note::factory()->create([
'note' => 'Hi @aaron',
]);
// phpcs:ignore
$expected = 'Hi
Aaron Parecki
Facebook
' . PHP_EOL;
$this->assertEquals($expected, $note->note);
}
/**
* Look for twitter URL when there’s no associated contact.
*/
#[Test]
public function twitter_link_is_created_when_no_contact_found(): void
{
$expected = 'Hi @bob
' . PHP_EOL;
$note = Note::factory()->create([
'note' => 'Hi @bob',
]);
$this->assertEquals($expected, $note->note);
}
#[Test]
public function we_get_latitude_longitude_values_of_associated_place_of_note(): void
{
$place = Place::factory()->create([
'latitude' => '53.4983',
'longitude' => '-2.3805',
]);
$note = Note::factory()->create([
'place_id' => $place->id,
]);
$this->assertEquals('53.4983', $note->latitude);
$this->assertEquals('-2.3805', $note->longitude);
}
#[Test]
public function when_no_associated_place_we_get_null_for_latitude_longitude_values(): void
{
$note = Note::factory()->create();
$this->assertNull($note->latitude);
$this->assertNull($note->longitude);
}
#[Test]
public function we_can_get_address_attribute_for_associated_place(): void
{
$place = Place::factory()->create([
'name' => 'The Bridgewater Pub',
'latitude' => '53.4983',
'longitude' => '-2.3805',
]);
$note = Note::factory()->create([
'place_id' => $place->id,
]);
$this->assertEquals('The Bridgewater Pub', $note->address);
}
#[Test]
public function deleting_notes_also_deletes_tags_via_the_event_observer(): void
{
// first we’ll create a temporary note to delete
$note = Note::create(['note' => 'temporary #temp']);
$this->assertDatabaseHas('tags', [
'tag' => 'temp',
]);
$tag = Tag::where('tag', 'temp')->first();
$note->forceDelete();
$this->assertDatabaseMissing('note_tag', [
'tag_id' => $tag->id,
]);
}
#[Test]
public function save_blank_notes_as_null(): void
{
$note = new Note(['note' => '']);
$this->assertNull($note->note);
}
#[Test]
public function reverse_geocode_an_attraction(): void
{
// phpcs:disable Generic.Files.LineLength.TooLong
$json = << 'application/json'], $json),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$address = $note->reverseGeoCode(51.50084, -0.14264);
$this->assertEquals(
'Victoria, London , UK ',
$address
);
}
#[Test]
public function reverse_geocode_a_suburb(): void
{
// phpcs:disable Generic.Files.LineLength.TooLong
$json = << 'application/json'], $json),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$address = $note->reverseGeoCode(51.02, 0.91);
$this->assertEquals(
'Newchurch, Shepway , UK ',
$address
);
}
#[Test]
public function reverse_geocode_a_city(): void
{
// Note I’ve modified this JSON response so it only contains the
// city the Uni is in
// phpcs:disable Generic.Files.LineLength.TooLong
$json = << 'application/json'], $json),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$address = $note->reverseGeoCode(53.466277988406, -2.2304474827445);
$this->assertEquals(
'Manchester , UK ',
$address
);
}
#[Test]
public function reverse_geocode_a_county(): void
{
// Note I’ve removed everything below county to test for queries where
// that’s all that is returned
// phpcs:disable Generic.Files.LineLength.TooLong
$json = << 'application/json'], $json),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$address = $note->reverseGeoCode(51.1, 0.61);
$this->assertEquals('Kent , UK ', $address);
}
#[Test]
public function reverse_geocode_a_country(): void
{
// Note I’ve removed everything below country to test for querires where
// that’s all that is returned
// phpcs:disable Generic.Files.LineLength.TooLong
$json = << 'application/json'], $json),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$address = $note->reverseGeoCode(54.3, 9.4);
$this->assertEquals('Ireland ', $address);
}
#[Test]
public function add_image_element_to_note_content_when_media_associated(): void
{
$media = Media::factory()->create([
'type' => 'image',
'path' => 'test.png',
]);
$note = Note::factory()->create([
'note' => 'A nice image',
]);
$note->media()->save($media);
$expected = 'A nice image
';
$this->assertEquals($expected, $note->content);
}
#[Test]
public function add_video_element_to_note_content_when_media_associated(): void
{
$media = Media::factory()->create([
'type' => 'video',
'path' => 'test.mkv',
]);
$note = Note::factory()->create([
'note' => 'A nice video',
]);
$note->media()->save($media);
$expected = 'A nice video
';
$this->assertEquals($expected, $note->content);
}
#[Test]
public function add_audio_element_to_note_content_when_media_associated(): void
{
$media = Media::factory()->create([
'type' => 'audio',
'path' => 'test.flac',
]);
$note = Note::factory()->create([
'note' => 'Some nice audio',
]);
$note->media()->save($media);
$expected = 'Some nice audio
';
$this->assertEquals($expected, $note->content);
}
/**
* @todo Why do we need to provide text?
*/
#[Test]
public function provide_text_for_blank_content(): void
{
$note = new Note;
$this->assertEquals('A blank note', $note->content);
}
// @todo Sort out twitter requests
/** @test
public function setTwitterContentToNullWhenOembedErrorOccurs(): void
{
$note = new Note();
$note->in_reply_to = 'https://twitter.com/search';
$this->assertNull($note->twitter);
}*/
#[Test]
public function markdown_content_gets_converted(): void
{
$note = Note::factory()->create([
'note' => 'The best search engine? https://kagi.com',
]);
$this->assertSame(
'The best search engine? https://kagi.com
' . PHP_EOL,
$note->note
);
}
/**
* For now, just reply on a cached object instead of actually querying Twitter.
*/
#[Test]
public function check_in_reply_to_is_twitter_link(): void
{
$tempContent = (object) [
'html' => 'something random',
];
Cache::put('933662564587855877', $tempContent);
$note = Note::factory()->create([
'in_reply_to' => 'https://twitter.com/someRando/status/933662564587855877',
]);
$this->assertEquals($tempContent, $note->twitter);
}
#[Test]
public function latitude_and_longitude_can_be_parsed_from_plain_location(): void
{
$note = Note::factory()->create([
'location' => '1.23,4.56',
]);
$this->assertSame(1.23, $note->latitude);
$this->assertSame(4.56, $note->longitude);
}
#[Test]
public function address_attribute_can_be_retrieved_from_plain_location(): void
{
Cache::put('1.23,4.56', 'Antarctica ');
$note = Note::factory()->create([
'location' => '1.23,4.56',
]);
$this->assertSame('Antarctica ', $note->address);
}
#[Test]
public function mastodon_usernames_are_parsed_correctly(): void
{
$expected = 'Hi @freekmurze@phpc.social how are you?
' . PHP_EOL;
$note = Note::factory()->create([
'note' => 'Hi @freekmurze@phpc.social how are you?',
]);
$this->assertSame($expected, $note->note);
}
}