-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Johannes Schobel
committed
Jan 28, 2018
1 parent
9bfec36
commit 31eda95
Showing
5 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Containers\ActivityLog\Tests; | ||
|
||
use App\Containers\ActivityLog\Tests\TestCase as BaseTestCase; | ||
|
||
/** | ||
* Class ApiTestCase. | ||
* | ||
* This is the container API TestCase class. Use this class to add your container specific API related helper functions. | ||
*/ | ||
class ApiTestCase extends BaseTestCase | ||
{ | ||
// .. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Containers\ActivityLog\Tests; | ||
|
||
use App\Ship\Parents\Tests\PhpUnit\TestCase as ShipTestCase; | ||
|
||
/** | ||
* Class TestCase. | ||
* | ||
* This is the container Main TestCase class. Use this class to add your container specific helper functions. | ||
*/ | ||
class TestCase extends ShipTestCase | ||
{ | ||
// .. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Containers\ActivityLog\Tests\Unit; | ||
|
||
use Apiato\Core\Foundation\Facades\Apiato; | ||
use App\Containers\ActivityLog\Tasks\CreateActivityLogEntryTask; | ||
use App\Containers\ActivityLog\Tests\TestCase; | ||
use App\Containers\User\Models\User; | ||
use Illuminate\Support\Facades\Config; | ||
use Spatie\Activitylog\Models\Activity; | ||
|
||
/** | ||
* Class CreateActivityLogEntryTest. | ||
* | ||
* @group activitylog | ||
* @group unit | ||
*/ | ||
class CreateActivityLogEntryTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_if_activity_is_created_and_logged_to_database() | ||
{ | ||
// get one user | ||
$causer = $this->getTestingUser(); | ||
$subject = $causer; | ||
|
||
$description = 'Test Entry Created'; | ||
$options = [ | ||
'operation' => 'create', | ||
'variables' => [ | ||
'test' => true, | ||
], | ||
]; | ||
$logname = 'test'; | ||
|
||
/** @var Activity $activity */ | ||
$activity = Apiato::call(CreateActivityLogEntryTask::class, [ | ||
$causer, | ||
$subject, | ||
$description, | ||
$options, | ||
$logname, | ||
]); | ||
|
||
// check if values are correctly set | ||
$this->assertInstanceOf(Activity::class, $activity); | ||
|
||
// check if this entry is in the database | ||
$this->assertDatabaseHas('activity_log', | ||
[ | ||
'id' => $activity->id, | ||
|
||
'causer_id' => $causer->id, | ||
'causer_type' => get_class($causer), | ||
|
||
'description' => $description, | ||
'log_name' => $logname | ||
]); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
ActivityLog/UI/API/Tests/Functional/GetMyActivitiesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Containers\ActivityLog\UI\API\Tests\Functional; | ||
|
||
use Apiato\Core\Foundation\Facades\Apiato; | ||
use App\Containers\ActivityLog\Tasks\CreateActivityLogEntryTask; | ||
use App\Containers\ActivityLog\Tests\ApiTestCase; | ||
|
||
/** | ||
* Class GetMyActivitiesTest. | ||
* | ||
* @group activitylog | ||
* @group api | ||
*/ | ||
class GetMyActivitiesTest extends ApiTestCase | ||
{ | ||
|
||
// the endpoint to be called within this test (e.g., get@v1/users) | ||
protected $endpoint = 'get@v1/my/activities'; | ||
|
||
// fake some access rights | ||
protected $access = [ | ||
'permissions' => '', | ||
'roles' => '', | ||
]; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_with_user_that_has_no_entries() | ||
{ | ||
$data = [ | ||
]; | ||
|
||
// send the HTTP request | ||
$response = $this->makeCall($data); | ||
|
||
// assert the response status | ||
$response->assertSuccessful(); | ||
|
||
// test for empty content | ||
$response->assertJson(['data' => []]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_with_user_that_has_some_entries() | ||
{ | ||
$user = $this->getTestingUser(); | ||
|
||
// create 2 activities | ||
$activity1 = Apiato::call(CreateActivityLogEntryTask::class, [$user, $user, 'test 1', [], 'test']); | ||
$activity2 = Apiato::call(CreateActivityLogEntryTask::class, [$user, $user, 'test 2', [], 'test']); | ||
|
||
$data = [ | ||
]; | ||
|
||
$response = $this->makeCall($data); | ||
|
||
// assert the response status | ||
$response->assertSuccessful(); | ||
$response->assertJsonCount(2, 'data'); | ||
} | ||
|
||
} |