forked from Elgg/Elgg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add admin notice tests and fix bugs
- Loading branch information
1 parent
d5f342d
commit a9d3b1a
Showing
4 changed files
with
98 additions
and
16 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
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
80 changes: 80 additions & 0 deletions
80
engine/tests/phpunit/integration/Elgg/Actions/Admin/AdminNoticesTest.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,80 @@ | ||
<?php | ||
|
||
namespace Elgg\Actions\Admin; | ||
|
||
use Elgg\ActionResponseTestCase; | ||
use Elgg\Http\ErrorResponse; | ||
use Elgg\Http\OkResponse; | ||
|
||
/** | ||
* @group ActionsService | ||
* @group AdminNotices | ||
* @group Admin | ||
*/ | ||
class AdminNoticesTest extends ActionResponseTestCase { | ||
|
||
public function up() { | ||
_elgg_services()->session->setLoggedInUser($this->getAdmin()); | ||
} | ||
|
||
public function down() { | ||
_elgg_services()->session->removeLoggedInUser(); | ||
} | ||
|
||
public function testDeletesSingleAdminNotice() { | ||
|
||
elgg_delete_admin_notice('zen'); | ||
|
||
$notice = elgg_add_admin_notice('zen', 'Maybe the forces of the universe be with you'); | ||
$this->assertInstanceOf(\ElggObject::class, $notice); | ||
$this->assertEquals('zen', $notice->admin_notice_id); | ||
|
||
$this->assertTrue(elgg_admin_notice_exists('zen')); | ||
|
||
$response = $this->executeAction('admin/delete_admin_notice', [ | ||
'guid' => $notice->guid, | ||
]); | ||
|
||
$this->assertInstanceOf(OkResponse::class, $response); | ||
|
||
$this->assertFalse(elgg_admin_notice_exists('zen')); | ||
} | ||
|
||
public function testIgnoresNonAdminNoticesDuringDeleteAction() { | ||
|
||
$object = $this->createObject(); | ||
|
||
$response = $this->executeAction('admin/delete_admin_notice', [ | ||
'guid' => $object->guid, | ||
]); | ||
|
||
$this->assertInstanceOf(ErrorResponse::class, $response); | ||
} | ||
|
||
public function testDeletesBatchAdminNotices() { | ||
|
||
elgg_add_admin_notice('zen1', 'Maybe the forces of the universe be with you'); | ||
elgg_add_admin_notice('zen2', 'Maybe the forces of the universe be with you'); | ||
elgg_add_admin_notice('zen3', 'Maybe the forces of the universe be with you'); | ||
|
||
$count_zens = function() { | ||
return elgg_get_admin_notices([ | ||
'metadata_name_value_pairs' => [ | ||
'name' => 'admin_notice_id', | ||
'value' => 'zen%', | ||
'operand' => 'LIKE', | ||
], | ||
'count' => true, | ||
]); | ||
}; | ||
|
||
$this->assertEquals(3, $count_zens()); | ||
|
||
$response = $this->executeAction('admin/delete_admin_notices'); | ||
|
||
$this->assertInstanceOf(OkResponse::class, $response); | ||
|
||
$this->assertEquals(0, $count_zens()); | ||
} | ||
|
||
} |