Skip to content

Commit

Permalink
Add tests for edit capability
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Apr 18, 2024
1 parent 6d0a38e commit 1551e30
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/event/event-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Wporg\Tests\Event;

use GP_UnitTestCase;
use Wporg\TranslationEvents\Attendee\Attendee;
use Wporg\TranslationEvents\Attendee\Attendee_Repository;
use Wporg\TranslationEvents\Event\Event_Repository;
use Wporg\TranslationEvents\Tests\Event_Factory;
Expand Down Expand Up @@ -33,4 +34,55 @@ public function test_can_create_if_crud_permission() {

$this->assertTrue( current_user_can( 'create_translation_event' ) );
}

public function test_author_can_edit() {
$this->set_normal_user_as_current();

$event_id = $this->event_factory->create_active();

$this->assertTrue( current_user_can( 'edit_translation_event', $event_id ) );

Check failure on line 43 in tests/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that false is true.

Check failure on line 43 in tests/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that false is true.
}

public function test_non_author_cannot_edit() {
$this->set_normal_user_as_current();
$non_author_user_id = get_current_user_id();
$this->set_normal_user_as_current(); // This user is the author.

$event_id = $this->event_factory->create_active();

$this->assertFalse( user_can( $non_author_user_id, 'edit_translation_event', $event_id ) );
}

public function test_host_can_edit() {
$this->set_normal_user_as_current();
$non_author_user_id = get_current_user_id();
$this->set_normal_user_as_current(); // This user is the author.

$event_id = $this->event_factory->create_active();

$attendee = new Attendee( $event_id, $non_author_user_id );
$attendee->mark_as_host();
$this->attendee_repository->insert_attendee( $attendee );

$this->assertTrue( user_can( $non_author_user_id, 'edit_translation_event', $event_id ) );

Check failure on line 67 in tests/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / PHPUnit 7.4

Failed asserting that false is true.

Check failure on line 67 in tests/event/event-capabilities.php

View workflow job for this annotation

GitHub Actions / PHPUnit 8.3

Failed asserting that false is true.
}


public function test_cannot_edit_past_event() {
$this->set_normal_user_as_current();

$event_id = $this->event_factory->create_inactive_past();

$this->assertFalse( current_user_can( 'edit_translation_event', $event_id ) );
}

public function test_cannot_edit_event_with_stats() {
$this->set_normal_user_as_current();
$author_user_id = get_current_user_id();

$event_id = $this->event_factory->create_active();
$this->stats_factory->create( $event_id, $author_user_id, 1, 'create' );

$this->assertFalse( current_user_can( 'edit_translation_event', $event_id ) );
}
}

0 comments on commit 1551e30

Please sign in to comment.