Add tests for uploading articles from md files

This commit is contained in:
Jonny Barnes 2017-06-16 13:45:09 +01:00
parent 9372059e1e
commit 0a621cd021
2 changed files with 48 additions and 0 deletions

View file

@ -3,6 +3,7 @@
## Version {next}
- Add support for ownyourgram.com sending h-card locations
- change sluggable implementation
- Add tests for uploading new articles from .md files
## Version 0.5.14 (2017-06-11)
- Remove some Log statements in-appropriate for porduction

View file

@ -0,0 +1,47 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Http\UploadedFile;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ArticlesAdminTest extends TestCase
{
use DatabaseTransactions;
public function test_create_new_article()
{
$this->withSession(['loggedin' => true])
->post('/admin/blog', [
'title' => 'Test Title',
'main' => 'Article content'
]);
$this->assertDatabaseHas('articles', ['title' => 'Test Title']);
}
public function test_create_new_article_with_upload()
{
$faker = \Faker\Factory::create();
$text = $faker->text;
if ($fh = fopen(sys_get_temp_dir() . '/article.md', 'w')) {
fwrite($fh, $text);
fclose($fh);
}
$path = sys_get_temp_dir() . '/article.md';
$file = new UploadedFile($path, 'article.md', 'text/plain', filesize($path), null, true);
$this->withSession(['loggedin' => true])
->post('/admin/blog', [
'title' => 'Uploaded Article',
'article' => $file,
]);
$this->assertDatabaseHas('articles', [
'title' => 'Uploaded Article',
'main' => $text,
]);
}
}