TESTING #1931 @1h: add few tests
This commit is contained in:
+2
-1
@@ -33,7 +33,8 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Modules\\": "modules/",
|
"Modules\\": "modules/",
|
||||||
"Templates\\": "templates/"
|
"Templates\\": "templates/",
|
||||||
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+3
-2
@@ -9,8 +9,8 @@
|
|||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false">
|
stopOnFailure="false">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Application Test Suite">
|
<testsuite name="unit">
|
||||||
<directory>./tests/</directory>
|
<directory>./tests/unit/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<filter>
|
||||||
@@ -23,5 +23,6 @@
|
|||||||
<env name="CACHE_DRIVER" value="array"/>
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
<env name="QUEUE_DRIVER" value="sync"/>
|
<env name="QUEUE_DRIVER" value="sync"/>
|
||||||
|
<env name="DB_CONNECTION" value="mysqlTesting"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
+6
-2
@@ -1,6 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
class TestCase extends Illuminate\Foundation\Testing\TestCase
|
use Illuminate\Contracts\Console\Kernel;
|
||||||
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
|
class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The base URL to use while testing the application.
|
* The base URL to use while testing the application.
|
||||||
@@ -18,7 +22,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
{
|
{
|
||||||
$app = require __DIR__.'/../bootstrap/app.php';
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
|
|
||||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
$app->make(Kernel::class)->bootstrap();
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class WritePermissionsTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testStorageDir()
|
|
||||||
{
|
|
||||||
$this->writeToDir(storage_path('test.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLogsDir()
|
|
||||||
{
|
|
||||||
$this->writeToDir(storage_path('logs/test.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFrameworkDir()
|
|
||||||
{
|
|
||||||
$this->writeToDir(storage_path('framework/test.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBootstrapCacheDir()
|
|
||||||
{
|
|
||||||
$this->writeToDir(storage_path('../bootstrap/cache/test.txt'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUploadDir()
|
|
||||||
{
|
|
||||||
$this->writeToDir(config('app.upload_path').'/test.txt');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create and delete some file
|
|
||||||
*
|
|
||||||
* @param $path
|
|
||||||
*/
|
|
||||||
protected function writeToDir($file)
|
|
||||||
{
|
|
||||||
$content = uniqid();
|
|
||||||
$bytesWritten = file_put_contents($file, $content);
|
|
||||||
|
|
||||||
// test writing
|
|
||||||
$this->assertNotFalse($bytesWritten);
|
|
||||||
|
|
||||||
// test deleting
|
|
||||||
$deleted = @unlink($file);
|
|
||||||
$this->assertTrue($deleted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\Admin\Content;
|
||||||
|
|
||||||
|
use App\CMS\Contracts\Repositories\Content;
|
||||||
|
use App\Models\Content\Content as ContentModel;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ContentModelTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Content
|
||||||
|
*/
|
||||||
|
protected $content;
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
/**
|
||||||
|
* @var ContentModel
|
||||||
|
*/
|
||||||
|
protected $parentPage;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->createApplication();
|
||||||
|
|
||||||
|
$this->content = App::make(Content::class);
|
||||||
|
|
||||||
|
// create new rows
|
||||||
|
$this->user = factory(User::class)->create();
|
||||||
|
$this->parentPage = factory(ContentModel::class)->create(['userId' => $this->user->id]);
|
||||||
|
factory(ContentModel::class, 4)->create(['userId' => $this->user->id]);
|
||||||
|
factory(ContentModel::class, 5)->create([
|
||||||
|
'userId' => $this->user->id,
|
||||||
|
'parentId' => $this->parentPage->id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubpages() {
|
||||||
|
|
||||||
|
$subpages = $this->parentPage->subpages;
|
||||||
|
|
||||||
|
$this->assertTrue($subpages instanceof Collection);
|
||||||
|
$this->assertCount(5, $subpages);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
// clean tables
|
||||||
|
ContentModel::getQuery()
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\Admin\Content;
|
||||||
|
|
||||||
|
use App\CMS\Contracts\Repositories\Content;
|
||||||
|
use App\Models\Content\Content as ContentModel;
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class RepositoryTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Content
|
||||||
|
*/
|
||||||
|
protected $content;
|
||||||
|
/**
|
||||||
|
* @var User
|
||||||
|
*/
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->createApplication();
|
||||||
|
|
||||||
|
// clean tables
|
||||||
|
ContentModel::getQuery()
|
||||||
|
->delete();
|
||||||
|
User::getQuery()
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
$this->content = App::make(Content::class);
|
||||||
|
|
||||||
|
// create new rows
|
||||||
|
$this->user = factory(User::class)->create();
|
||||||
|
factory(ContentModel::class, 3)->create(['userId' => $this->user->id, 'status' => Content::STATUS_DRAFT]);
|
||||||
|
factory(ContentModel::class, 1)->create(['userId' => $this->user->id, 'status' => Content::STATUS_PROTECTED]);
|
||||||
|
factory(ContentModel::class, 5)->create(['userId' => $this->user->id, 'status' => Content::STATUS_PUBLIC]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for selecting homepage.
|
||||||
|
*
|
||||||
|
* At first, it tries to select non-existing homepage. On second try, homepage is created.
|
||||||
|
*/
|
||||||
|
public function testSelectingHomepage()
|
||||||
|
{
|
||||||
|
$homepage = $this->content->getHomepage();
|
||||||
|
$this->assertNull($homepage);
|
||||||
|
|
||||||
|
$newHomepage = factory(ContentModel::class)->create([
|
||||||
|
'userId' => $this->user->id,
|
||||||
|
'isHomepage' => 1,
|
||||||
|
'status' => Content::STATUS_PUBLIC,
|
||||||
|
'publishedFrom' => Carbon::now()
|
||||||
|
->subDays(10)
|
||||||
|
]);
|
||||||
|
|
||||||
|
$homepage = $this->content->getHomepage();
|
||||||
|
$this->assertNotNull($homepage);
|
||||||
|
$this->assertTrue($homepage->id === $newHomepage->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSelectingAllPages()
|
||||||
|
{
|
||||||
|
$all = $this->content->all();
|
||||||
|
|
||||||
|
$this->assertCount(6, $all);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function testContentVisibilityByPublishedFrom()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testContentVisibilityByPublishedTo()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testSelectingByURL()
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testSelectingById()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testSelectingInvalidPageByURL()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testSelectingInvalidPageById()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testOverview()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testOvervieWithOneStatus()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public function testOverviewWithMultipleStatuses()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user