summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-11 11:56:36 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-11 11:56:36 +0200
commitaefe55a70d6f6bae7825f3a1a6b61046c8ec2cc3 (patch)
tree9f1b98e73d2e6f0fcc4f49b2cd581a9e1d8a7338 /tests
parent0496d664f66c68cc56f68562129672a39cf09416 (diff)
downloadgigologadmin-aefe55a70d6f6bae7825f3a1a6b61046c8ec2cc3.tar.gz
gigologadmin-aefe55a70d6f6bae7825f3a1a6b61046c8ec2cc3.tar.bz2
gigologadmin-aefe55a70d6f6bae7825f3a1a6b61046c8ec2cc3.zip
tests: Make an actual test for ConcertsTable
There's a bit of setup to make this work as it should, we need to ensure that the current user and current screen is set to proper values so that the WordPress api's `is_admin()` and `current_user_can()` work as they should. This first test just tests that all the expected forms are being rendered for the admin user accessing the table through the site admin interface.
Diffstat (limited to 'tests')
-rw-r--r--tests/ConcertsTableTest.php29
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/ConcertsTableTest.php b/tests/ConcertsTableTest.php
index 73852c8..ad0e65f 100644
--- a/tests/ConcertsTableTest.php
+++ b/tests/ConcertsTableTest.php
@@ -75,20 +75,39 @@ class ConcertsTableTest extends WP_UnitTestCase
}
function testShowAllControlsToAdminOnAdminPage() {
+ global $current_screen;
+ global $current_user;
+
+ $current_user = $this->factory()->user->create_and_get(['role' => 'administrator']);
+ $this->assertTrue( current_user_can( 'administrator' ) );
+
+ $oldscreen = $current_screen;
+ $current_screen = WP_Screen::get( 'admin_init' );
+ $this->assertTrue(is_admin());
+
$c = new GiglogAdmin_ConcertsTable();
$html = $c->render();
- //$this->assertEquals('balle', $html);
+
+ $current_screen = $oldscreen;
$doc = DOMDocument::loadHTML($html);
$forms = $doc->getElementsByTagName('form');
- $count = 0;
+
+ $assignit_count = 0;
+ $adminactions_count = 0;
+
foreach ($forms as $form) {
$cls = $form->attributes->getNamedItem('class')->nodeValue;
- if ($cls == 'assignit' || $cls == 'unassignit') {
- $count++;
+ if ($cls == 'assign_concert' || $cls == 'unassign_concert') {
+ $assignit_count++;
+ }
+
+ if ($cls == 'adminactions') {
+ $adminactions_count++;
}
}
- $this->assertEquals($count, 64);
+ $this->assertEquals(64, $assignit_count); // four for each gig
+ $this->assertEquals(16, $adminactions_count); // once for each gig
}
}