diff --git a/.env.test b/.env.test
index eaca2af88..30a953ffb 100644
--- a/.env.test
+++ b/.env.test
@@ -6,7 +6,8 @@ PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
# Mbin variables
-DATABASE_URL="postgresql://kbin:ChangeMe@127.0.0.1:5432/kbin_test?serverVersion=13&charset=utf8"
+DATABASE_URL="postgresql://mbin:ChangeThisPostgresPass@127.0.0.1:5433/mbin?serverVersion=16&charset=utf8"
+REDIS_DNS=redis://123456789@127.0.0.1:6380
MAILER_DSN=null://default
KBIN_JS_ENABLED=false
KBIN_DEFAULT_LANG=en
@@ -14,3 +15,10 @@ KBIN_DOMAIN=kbin.test
ELASTICSEARCH_ENABLED=false
KBIN_API_ITEMS_PER_PAGE=2
KBIN_FEDERATION_ENABLED=false
+
+###> league/oauth2-server-bundle ###
+OAUTH_PRIVATE_KEY=%kernel.project_dir%/config/oauth2/tests/private.pem
+OAUTH_PUBLIC_KEY=%kernel.project_dir%/config/oauth2/tests/public.pem
+OAUTH_ENCRYPTION_KEY=MF3Sks6dIHhMvk1SALv68e8LydunZopLennBuF9jALk=
+OAUTH_PASSPHRASE=null
+###< league/oauth2-server-bundle ###
diff --git a/.github/workflows/action.yaml b/.github/workflows/action.yaml
index d2a68aee1..6d792eb77 100644
--- a/.github/workflows/action.yaml
+++ b/.github/workflows/action.yaml
@@ -81,6 +81,61 @@ jobs:
SYMFONY_DEPRECATIONS_HELPER: disabled
run: php bin/phpunit tests/Unit
+ integration-test:
+ runs-on: ubuntu-latest
+ container:
+ image: danger89/mbin-pipeline:1.2.0
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Get Composer Cache Directory
+ id: composer-cache
+ run: |
+ echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - run: cp .env.example .env
+ - name: Composer install
+ run: composer install --no-scripts --no-progress
+
+ - uses: actions/cache@v4
+ with:
+ path: ${{ steps.composer-cache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: ${{ runner.os }}-composer-
+
+ - name: Run integration tests
+ env:
+ COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }}
+ SYMFONY_DEPRECATIONS_HELPER: disabled
+ run: php bin/phpunit tests/Functional
+ services:
+ postgres:
+ # Docker Hub image
+ image: postgres
+ # Provide the password for postgres
+ env:
+ POSTGRES_DB: mbin_test
+ POSTGRES_USER: mbin
+ POSTGRES_PASSWORD: ChangeThisPostgresPass
+ # Set health checks to wait until postgres has started
+ options: >-
+ --health-cmd pg_isready
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ redis:
+ # Docker Hub image
+ image: redis
+ # Set health checks to wait until redis has started
+ options: >-
+ --health-cmd "redis-cli ping"
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ ports:
+ # Maps port 6379 on service container to the host
+ - 6380:6379
+
audit-check:
runs-on: ubuntu-latest
container:
diff --git a/config/oauth2/tests/private.pem b/config/oauth2/tests/private.pem
new file mode 100644
index 000000000..8ef6e27df
--- /dev/null
+++ b/config/oauth2/tests/private.pem
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDwTLg0F+MPOubO
+8QXiNBAzWVFdP8LKemjKjUWembvcSIkeKhyIvk5YSbsX56vc7ArJnX8ikdnhVw5u
+wK7K9vwU8+FJBFStHypexOQGJchSpV76kWYK4J6zFVy11bCbsHPrlwM0chM7pBgU
+JSJ2c5KPaGhKUwZ/DzsP+qzLh1Us/LKtuLc5uPPEN1824Up7DFr6RiM0dWKjyvEB
+bNJmDAFr/F4j6K7zZLv52U49kdWetHNMLXQxWB8WMU6hJHRGqgz8rJI+gcqyHLDC
+eKlMJErnnA9kDC3pKTjDugUFSVS3bgi7tv1q+/KiYHUf1STV5oY74JC4JfRPYmoB
++ZmKf9gLAgMBAAECggEAD2kEHnHHtxgnvsQDL2n3qKtaMJjgWjwhEJhLC4GVZBTn
+bN6g0ijOJ72hY3DmeyD3YiLuXnOsXYCdOtSy1kOiOopspfztRzrqlzBDj/IIAjt7
+t1BFaH4rf0A9SqXyZlGZutUw40H2N3VtsTZecD/iJBM7LkUGc3XbwPRqShUa4msP
+DLfYymEtShJ71uNdveNmTSWntuw8crFHZhZGxFlqiNdJ8sJXH5qxJvV69p9rJe21
+7F9zCoWsdAs33u1xb7zSh6XumnvtqQ8kLO0pXqx0zSF1Xqt/35qo2qQfRgNRspiK
+uQkn6qGbpzZ73PZ1raIXjbiNXPVy2yb3aQI9I2UxlQKBgQD+OXx5c/M2JaGNsDEv
+cWCNgm5YDQATpFp1GaSW0dlyUpWN8nF7AwAa7+o40yPEHyDuKjKKJDIRdbtcocqI
+UD+EQ8qeDXL+e9mljK/hoIVoystZryyON+SbTrzobzTVp51I0olKwv318R7nzFep
+qSyczDjfvs29zNZwzLuwLjVzbwKBgQDx+lZ7vwNkl7S3TSzVeMPCeIaY22IO7wKN
+yoDsth/DyC/qINwhQLdCiTCZNhqsqKtlacWXd7CRJsesU41Za1cEGY0Zad2kxc0g
+I59SaoHE6RNbW2xQ6u2/elmxHs9jyfIcEJ2lRMlVDh38Qk29CNKmmO+xiByfXNKy
+pM1MRbPnJQKBgD0NmzojwYYAdZLsfHNzXAfACjX1MU6GSv8SYHej//+3m5kSX3R2
+XQEbGvn4ov9HpoXr9mU8mhWdW5i8dkJUW1ytVyyr+DDrl3JtnhOmlEN9aGaqbh3d
+iHZP64g6pMqmzVwey7/7ojf9Zzmt1mO1cDRby1DYptptJhbC5FREVKvbAoGBAJLf
+k0zLNSECoBM+ib8M7S2GAJSZXJyZ4F/2EWkcZo1sXgDrbxHT+Sguo0vrtickvdvx
+Zpi4cni4JCxqDnq/F3MKm0VYp8rSsN4YISViNmAx5KjoBgfbgPFfLz+95r24Hvd/
+8mAVL2ssBXFPQWZDC7FJVPvaFR15tv3t4BqymC7tAoGBAKR9e/VLI2cajpBdXzK4
+JhaQ59R/ybxPdg5JhyGC3n9WN5lK71pdbR04vNVAT3+LwpNu49DKEYkiSCfo3tAl
+iJPnKe8mGgQ4f1W7bvbW9GxMYWp/SGQRE3MZbH1ChUlCiqlzhkmwq1LgOFURCO+3
+GyQt5+0mF/tTqsFwt+n1VOtI
+-----END PRIVATE KEY-----
diff --git a/config/oauth2/tests/public.pem b/config/oauth2/tests/public.pem
new file mode 100644
index 000000000..f5c9f1f87
--- /dev/null
+++ b/config/oauth2/tests/public.pem
@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8Ey4NBfjDzrmzvEF4jQQ
+M1lRXT/Cynpoyo1Fnpm73EiJHiociL5OWEm7F+er3OwKyZ1/IpHZ4VcObsCuyvb8
+FPPhSQRUrR8qXsTkBiXIUqVe+pFmCuCesxVctdWwm7Bz65cDNHITO6QYFCUidnOS
+j2hoSlMGfw87D/qsy4dVLPyyrbi3ObjzxDdfNuFKewxa+kYjNHVio8rxAWzSZgwB
+a/xeI+iu82S7+dlOPZHVnrRzTC10MVgfFjFOoSR0RqoM/KySPoHKshywwnipTCRK
+55wPZAwt6Sk4w7oFBUlUt24Iu7b9avvyomB1H9Uk1eaGO+CQuCX0T2JqAfmZin/Y
+CwIDAQAB
+-----END PUBLIC KEY-----
diff --git a/docker/tests/compose.yml b/docker/tests/compose.yml
new file mode 100644
index 000000000..3fc5961af
--- /dev/null
+++ b/docker/tests/compose.yml
@@ -0,0 +1,20 @@
+services:
+ db:
+ image: postgres:${POSTGRES_VERSION:-16}-alpine
+ container_name: mbin-tests-db
+ restart: unless-stopped
+ ports:
+ - "5433:5432"
+ environment:
+ - POSTGRES_DB=mbin_test
+ - POSTGRES_USER=mbin
+ - POSTGRES_PASSWORD=ChangeThisPostgresPass
+ redis:
+ image: redis:alpine
+ container_name: mbin-tests-redis
+ restart: unless-stopped
+ command: /bin/sh -c "redis-server --requirepass 123456789"
+ ports:
+ - "6380:6379"
+ healthcheck:
+ test: ["CMD", "redis-cli", "ping"]
diff --git a/docs/03-contributing/01-getting_started.md b/docs/03-contributing/01-getting_started.md
index 80b93e739..67f4dd6d0 100644
--- a/docs/03-contributing/01-getting_started.md
+++ b/docs/03-contributing/01-getting_started.md
@@ -192,7 +192,7 @@ _Optionally:_ If you want to start federating, you will also need to messenger j
More info: [Contributing guide](https://github.com/MbinOrg/mbin/blob/main/CONTRIBUTING.md), [Admin guide](../02-admin/README.md) and [Symfony Local Web Server](https://symfony.com/doc/current/setup/symfony_server.html)
-## Unit tests
+## Testing
When fixing a bug or implementing a new feature or improvement, we expect that test code will also be included with every delivery of production code. There are three levels of tests that we distinguish between:
@@ -200,7 +200,9 @@ When fixing a bug or implementing a new feature or improvement, we expect that t
- Integration Tests: test larger part of the code, combining multiple units together (classes, services or alike).
- Application Tests: test high-level functionality, APIs or web calls.
-### Prepare for unit tests
+For more info read: [Symfony Testing guide](https://symfony.com/doc/current/testing.html).
+
+### Prepare testing
1. First increase execution time in your PHP config file: `/etc/php/8.3/fpm/php.ini`:
@@ -226,7 +228,21 @@ Running the unit tests can be done by executing:
SYMFONY_DEPRECATIONS_HELPER=disabled ./bin/phpunit tests/Unit
```
-For more info read: [Symfony Testing guide](https://symfony.com/doc/current/testing.html).
+### Running integration tests
+
+Our integration tests depend on a database and a caching server (Valkey / KeyDB / Redis).
+The database and cache are cleared / dumped every test run.
+To start the services:
+
+```sh
+cd docker/tests && docker compose up -d
+```
+
+To run the integration tests:
+
+```sh
+SYMFONY_DEPRECATIONS_HELPER=disabled ./bin/phpunit tests/Functional
+```
## Linting
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 87cd7b42c..74eb279eb 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -12,7 +12,8 @@
-
+
+
diff --git a/src/Controller/Api/Instance/InstanceRetrieveStatsApi.php b/src/Controller/Api/Instance/InstanceRetrieveStatsApi.php
index f3b45b25d..6721b2c34 100644
--- a/src/Controller/Api/Instance/InstanceRetrieveStatsApi.php
+++ b/src/Controller/Api/Instance/InstanceRetrieveStatsApi.php
@@ -229,14 +229,14 @@ public function content(
if (null === $startString) {
$start = null;
} else {
- $start = new \DateTime($startString);
+ $start = new \DateTimeImmutable($startString);
}
$endString = $request->get('end');
if (null === $endString) {
$end = null;
} else {
- $end = new \DateTime($endString);
+ $end = new \DateTimeImmutable($endString);
}
} catch (\Exception $e) {
throw new BadRequestHttpException('Failed to parse start or end time');
diff --git a/src/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApi.php b/src/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApi.php
index 71d8465d7..8f8dc3acb 100644
--- a/src/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApi.php
+++ b/src/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApi.php
@@ -284,14 +284,14 @@ public function content(
if (null === $startString) {
$start = null;
} else {
- $start = new \DateTime($startString);
+ $start = new \DateTimeImmutable($startString);
}
$endString = $request->get('end');
if (null === $endString) {
$end = null;
} else {
- $end = new \DateTime($endString);
+ $end = new \DateTimeImmutable($endString);
}
} catch (\Exception $e) {
throw new BadRequestHttpException('Failed to parse start or end time');
diff --git a/src/DTO/EntryRequestDto.php b/src/DTO/EntryRequestDto.php
index 3068fbd45..f97c35526 100644
--- a/src/DTO/EntryRequestDto.php
+++ b/src/DTO/EntryRequestDto.php
@@ -71,6 +71,7 @@ public function mergeIntoDto(EntryDto $dto): EntryDto
$dto->isOc = $this->isOc ?? $dto->isOc;
$dto->lang = $this->lang ?? $dto->lang ?? SettingsManager::getValue('KBIN_DEFAULT_LANG');
$dto->url = $this->url ?? $dto->url;
+ $dto->tags = $this->tags ?? $dto->tags;
return $dto;
}
diff --git a/src/Entity/Entry.php b/src/Entity/Entry.php
index 75f96955d..e09757817 100644
--- a/src/Entity/Entry.php
+++ b/src/Entity/Entry.php
@@ -166,6 +166,7 @@ public function __construct(
$this->favourites = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->badges = new ArrayCollection();
+ $this->hashtags = new ArrayCollection();
$user->addEntry($this);
diff --git a/src/Entity/Magazine.php b/src/Entity/Magazine.php
index 405585510..595ad79dd 100644
--- a/src/Entity/Magazine.php
+++ b/src/Entity/Magazine.php
@@ -134,6 +134,8 @@ public function __construct(
$this->reports = new ArrayCollection();
$this->badges = new ArrayCollection();
$this->logs = new ArrayCollection();
+ $this->moderatorRequests = new ArrayCollection();
+ $this->ownershipRequests = new ArrayCollection();
if (null !== $user) {
$this->addModerator(new Moderator($this, $user, null, true, true));
diff --git a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php
index 8e7ab4a4c..814e64d8d 100644
--- a/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/ActivityHandler.php
@@ -30,6 +30,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -39,6 +40,7 @@ class ActivityHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly SignatureValidator $signatureValidator,
private readonly SettingsManager $settingsManager,
private readonly MessageBusInterface $bus,
@@ -48,7 +50,7 @@ public function __construct(
private readonly RemoteInstanceManager $remoteInstanceManager,
private readonly LoggerInterface $logger
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(ActivityMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/AddHandler.php b/src/MessageHandler/ActivityPub/Inbox/AddHandler.php
index 23b635dcf..25164012b 100644
--- a/src/MessageHandler/ActivityPub/Inbox/AddHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/AddHandler.php
@@ -22,6 +22,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -30,6 +31,7 @@ class AddHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly ApHttpClient $apHttpClient,
private readonly ApActivityRepository $apActivityRepository,
@@ -41,7 +43,7 @@ public function __construct(
private readonly EntryManager $entryManager,
private readonly SettingsManager $settingsManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(AddMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/AnnounceHandler.php b/src/MessageHandler/ActivityPub/Inbox/AnnounceHandler.php
index 21e2b1110..536115b8c 100644
--- a/src/MessageHandler/ActivityPub/Inbox/AnnounceHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/AnnounceHandler.php
@@ -14,6 +14,7 @@
use App\Service\VoteManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -24,11 +25,12 @@ public function __construct(
private readonly ActivityPubManager $activityPubManager,
private readonly EntityManagerInterface $entityManager,
private readonly MessageBusInterface $bus,
+ private readonly KernelInterface $kernel,
private readonly VoteManager $manager,
private readonly VoteHandleSubscriber $voteHandleSubscriber,
private readonly LoggerInterface $logger,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(AnnounceMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php
index 1b858f249..d0970bff8 100644
--- a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php
@@ -26,6 +26,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -34,6 +35,7 @@ class ChainActivityHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly LoggerInterface $logger,
private readonly ApHttpClient $client,
private readonly MessageBusInterface $bus,
@@ -42,7 +44,7 @@ public function __construct(
private readonly Page $page,
private readonly SettingsManager $settingsManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(ChainActivityMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/CreateHandler.php b/src/MessageHandler/ActivityPub/Inbox/CreateHandler.php
index 1e4a0801c..e6dee028b 100644
--- a/src/MessageHandler/ActivityPub/Inbox/CreateHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/CreateHandler.php
@@ -26,6 +26,7 @@
use App\Service\MessageManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -34,6 +35,7 @@ class CreateHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly Note $note,
private readonly Page $page,
private readonly MessageBusInterface $bus,
@@ -42,7 +44,7 @@ public function __construct(
private readonly ActivityPubManager $activityPubManager,
private readonly ApActivityRepository $repository
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
/**
diff --git a/src/MessageHandler/ActivityPub/Inbox/DeleteHandler.php b/src/MessageHandler/ActivityPub/Inbox/DeleteHandler.php
index d92a655e7..1f56a7898 100644
--- a/src/MessageHandler/ActivityPub/Inbox/DeleteHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/DeleteHandler.php
@@ -21,6 +21,7 @@
use App\Service\PostCommentManager;
use App\Service\PostManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -30,6 +31,7 @@ class DeleteHandler extends MbinMessageHandler
public function __construct(
private readonly MessageBusInterface $bus,
private readonly ActivityPubManager $activityPubManager,
+ private readonly KernelInterface $kernel,
private readonly ApActivityRepository $apActivityRepository,
private readonly EntityManagerInterface $entityManager,
private readonly UserRepository $userRepository,
@@ -38,7 +40,7 @@ public function __construct(
private readonly PostManager $postManager,
private readonly PostCommentManager $postCommentManager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(DeleteMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/DislikeHandler.php b/src/MessageHandler/ActivityPub/Inbox/DislikeHandler.php
index 44d34af22..68ed40814 100644
--- a/src/MessageHandler/ActivityPub/Inbox/DislikeHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/DislikeHandler.php
@@ -20,6 +20,7 @@
use App\Utils\DownvotesMode;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -28,13 +29,14 @@ class DislikeHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly MessageBusInterface $bus,
private readonly VoteManager $voteManager,
private readonly LoggerInterface $logger,
private readonly SettingsManager $settingsManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(DislikeMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/FlagHandler.php b/src/MessageHandler/ActivityPub/Inbox/FlagHandler.php
index 5852c135a..fef4ae121 100644
--- a/src/MessageHandler/ActivityPub/Inbox/FlagHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/FlagHandler.php
@@ -20,6 +20,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -27,6 +28,7 @@ class FlagHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly ReportManager $reportManager,
private readonly EntryRepository $entryRepository,
@@ -36,7 +38,7 @@ public function __construct(
private readonly SettingsManager $settingsManager,
private readonly LoggerInterface $logger,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(FlagMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/FollowHandler.php b/src/MessageHandler/ActivityPub/Inbox/FollowHandler.php
index d3eeb2673..47e7b48cc 100644
--- a/src/MessageHandler/ActivityPub/Inbox/FollowHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/FollowHandler.php
@@ -16,6 +16,7 @@
use App\Service\UserManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -23,6 +24,7 @@ class FollowHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly UserManager $userManager,
private readonly MagazineManager $magazineManager,
@@ -30,7 +32,7 @@ public function __construct(
private readonly LoggerInterface $logger,
private readonly FollowResponseWrapper $followResponseWrapper
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(FollowMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/LikeHandler.php b/src/MessageHandler/ActivityPub/Inbox/LikeHandler.php
index a2f92f044..d0ba97b29 100644
--- a/src/MessageHandler/ActivityPub/Inbox/LikeHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/LikeHandler.php
@@ -18,6 +18,7 @@
use App\Service\VoteManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -26,13 +27,14 @@ class LikeHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $activityPubManager,
private readonly VoteManager $voteManager,
private readonly MessageBusInterface $bus,
private readonly FavouriteManager $manager,
private readonly LoggerInterface $logger,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(LikeMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/RemoveHandler.php b/src/MessageHandler/ActivityPub/Inbox/RemoveHandler.php
index 0c694f9f0..910f7ef60 100644
--- a/src/MessageHandler/ActivityPub/Inbox/RemoveHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/RemoveHandler.php
@@ -19,6 +19,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -26,6 +27,7 @@ class RemoveHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ApActivityRepository $apActivityRepository,
private readonly ActivityPubManager $activityPubManager,
private readonly MagazineRepository $magazineRepository,
@@ -35,7 +37,7 @@ public function __construct(
private readonly EntryManager $entryManager,
private readonly SettingsManager $settingsManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(RemoveMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Inbox/UpdateHandler.php b/src/MessageHandler/ActivityPub/Inbox/UpdateHandler.php
index fdb26e4af..4cbfd9d9a 100644
--- a/src/MessageHandler/ActivityPub/Inbox/UpdateHandler.php
+++ b/src/MessageHandler/ActivityPub/Inbox/UpdateHandler.php
@@ -39,6 +39,7 @@
use App\Service\PostManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -48,6 +49,7 @@ class UpdateHandler extends MbinMessageHandler
public function __construct(
private readonly ActivityPubManager $activityPubManager,
private readonly ApActivityRepository $apActivityRepository,
+ private readonly KernelInterface $kernel,
private readonly EntityManagerInterface $entityManager,
private readonly EntryManager $entryManager,
private readonly EntryCommentManager $entryCommentManager,
@@ -65,7 +67,7 @@ public function __construct(
private readonly MagazineFactory $magazineFactory,
private readonly ImageFactory $imageFactory,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(UpdateMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/AddHandler.php b/src/MessageHandler/ActivityPub/Outbox/AddHandler.php
index 0baba8291..94d52aa4e 100644
--- a/src/MessageHandler/ActivityPub/Outbox/AddHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/AddHandler.php
@@ -13,6 +13,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -20,13 +21,14 @@ class AddHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly UserRepository $userRepository,
private readonly MagazineRepository $magazineRepository,
private readonly SettingsManager $settingsManager,
private readonly AddRemoveFactory $factory,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(AddMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/AnnounceHandler.php b/src/MessageHandler/ActivityPub/Outbox/AnnounceHandler.php
index edc8c3279..dddc68ed4 100644
--- a/src/MessageHandler/ActivityPub/Outbox/AnnounceHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/AnnounceHandler.php
@@ -23,6 +23,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -31,6 +32,7 @@ class AnnounceHandler extends MbinMessageHandler
{
public function __construct(
private readonly UserRepository $userRepository,
+ private readonly KernelInterface $kernel,
private readonly MagazineRepository $magazineRepository,
private readonly EntityManagerInterface $entityManager,
private readonly AnnounceWrapper $announceWrapper,
@@ -41,7 +43,7 @@ public function __construct(
private readonly DeliverManager $deliverManager,
private readonly SettingsManager $settingsManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(AnnounceMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/AnnounceLikeHandler.php b/src/MessageHandler/ActivityPub/Outbox/AnnounceLikeHandler.php
index 21fe71e13..ac532971f 100644
--- a/src/MessageHandler/ActivityPub/Outbox/AnnounceLikeHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/AnnounceLikeHandler.php
@@ -21,6 +21,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -30,6 +31,7 @@ class AnnounceLikeHandler extends MbinMessageHandler
public function __construct(
private readonly UserRepository $userRepository,
private readonly MagazineRepository $magazineRepository,
+ private readonly KernelInterface $kernel,
private readonly EntityManagerInterface $entityManager,
private readonly AnnounceWrapper $announceWrapper,
private readonly UndoWrapper $undoWrapper,
@@ -40,7 +42,7 @@ public function __construct(
private readonly PersonFactory $personFactory,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(AnnounceLikeMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/CreateHandler.php b/src/MessageHandler/ActivityPub/Outbox/CreateHandler.php
index c24d5ebda..937331876 100644
--- a/src/MessageHandler/ActivityPub/Outbox/CreateHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/CreateHandler.php
@@ -17,6 +17,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -32,8 +33,9 @@ public function __construct(
private readonly MessageManager $messageManager,
private readonly LoggerInterface $logger,
private readonly DeliverManager $deliverManager,
+ private readonly KernelInterface $kernel,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(CreateMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/DeleteHandler.php b/src/MessageHandler/ActivityPub/Outbox/DeleteHandler.php
index 4ff12d4c8..49e0f3585 100644
--- a/src/MessageHandler/ActivityPub/Outbox/DeleteHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/DeleteHandler.php
@@ -13,6 +13,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -20,13 +21,14 @@ class DeleteHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly UserRepository $userRepository,
private readonly MagazineRepository $magazineRepository,
private readonly ActivityPubManager $activityPubManager,
private readonly SettingsManager $settingsManager,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(DeleteMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php b/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php
index 360cf635d..a674f861b 100644
--- a/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/DeliverHandler.php
@@ -18,6 +18,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -30,13 +31,14 @@ class DeliverHandler extends MbinMessageHandler
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ApHttpClient $client,
private readonly ActivityPubManager $manager,
private readonly SettingsManager $settingsManager,
private readonly LoggerInterface $logger,
private readonly InstanceRepository $instanceRepository,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
/**
diff --git a/src/MessageHandler/ActivityPub/Outbox/EntryPinMessageHandler.php b/src/MessageHandler/ActivityPub/Outbox/EntryPinMessageHandler.php
index 20729e8db..79c528b09 100644
--- a/src/MessageHandler/ActivityPub/Outbox/EntryPinMessageHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/EntryPinMessageHandler.php
@@ -15,6 +15,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -22,6 +23,7 @@ class EntryPinMessageHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly SettingsManager $settingsManager,
private readonly EntryRepository $entryRepository,
private readonly UserRepository $userRepository,
@@ -30,7 +32,7 @@ public function __construct(
private readonly DeliverManager $deliverManager,
private readonly LoggerInterface $logger,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryPinMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php b/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php
index 44391c1f5..c0acf405b 100644
--- a/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/FlagHandler.php
@@ -15,6 +15,7 @@
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -22,13 +23,14 @@ class FlagHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly SettingsManager $settingsManager,
private readonly ReportRepository $reportRepository,
private readonly FlagFactory $factory,
private readonly LoggerInterface $logger,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(FlagMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/FollowHandler.php b/src/MessageHandler/ActivityPub/Outbox/FollowHandler.php
index 6df9eec11..4280c1b1f 100644
--- a/src/MessageHandler/ActivityPub/Outbox/FollowHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/FollowHandler.php
@@ -16,6 +16,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -23,6 +24,7 @@ class FollowHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly UserRepository $userRepository,
private readonly MagazineRepository $magazineRepository,
private readonly ActivityPubManager $activityPubManager,
@@ -32,7 +34,7 @@ public function __construct(
private readonly SettingsManager $settingsManager,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(FollowMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/GenericAnnounceHandler.php b/src/MessageHandler/ActivityPub/Outbox/GenericAnnounceHandler.php
index e3dcd32ff..48b021035 100644
--- a/src/MessageHandler/ActivityPub/Outbox/GenericAnnounceHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/GenericAnnounceHandler.php
@@ -12,6 +12,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -20,13 +21,14 @@ class GenericAnnounceHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly SettingsManager $settingsManager,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly MagazineRepository $magazineRepository,
private readonly AnnounceWrapper $announceWrapper,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(GenericAnnounceMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/LikeHandler.php b/src/MessageHandler/ActivityPub/Outbox/LikeHandler.php
index a662e6415..0dccfedd0 100644
--- a/src/MessageHandler/ActivityPub/Outbox/LikeHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/LikeHandler.php
@@ -20,6 +20,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -27,6 +28,7 @@ class LikeHandler extends MbinMessageHandler
{
public function __construct(
private readonly UserRepository $userRepository,
+ private readonly KernelInterface $kernel,
private readonly MagazineRepository $magazineRepository,
private readonly EntityManagerInterface $entityManager,
private readonly LikeWrapper $likeWrapper,
@@ -36,7 +38,7 @@ public function __construct(
private readonly SettingsManager $settingsManager,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(LikeMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/RemoveHandler.php b/src/MessageHandler/ActivityPub/Outbox/RemoveHandler.php
index 675ed2acb..029967f23 100644
--- a/src/MessageHandler/ActivityPub/Outbox/RemoveHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/RemoveHandler.php
@@ -13,6 +13,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -20,13 +21,14 @@ class RemoveHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly UserRepository $userRepository,
private readonly MagazineRepository $magazineRepository,
private readonly SettingsManager $settingsManager,
private readonly AddRemoveFactory $factory,
private readonly DeliverManager $deliverManager,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(RemoveMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/Outbox/UpdateHandler.php b/src/MessageHandler/ActivityPub/Outbox/UpdateHandler.php
index 44c88765d..441c84914 100644
--- a/src/MessageHandler/ActivityPub/Outbox/UpdateHandler.php
+++ b/src/MessageHandler/ActivityPub/Outbox/UpdateHandler.php
@@ -23,6 +23,7 @@
use App\Service\DeliverManager;
use App\Service\SettingsManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -36,8 +37,9 @@ public function __construct(
private readonly SettingsManager $settingsManager,
private readonly DeliverManager $deliverManager,
private readonly UpdateWrapper $updateWrapper,
+ private readonly KernelInterface $kernel,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(UpdateMessage $message): void
diff --git a/src/MessageHandler/ActivityPub/UpdateActorHandler.php b/src/MessageHandler/ActivityPub/UpdateActorHandler.php
index 7f9aa73de..13f61f351 100644
--- a/src/MessageHandler/ActivityPub/UpdateActorHandler.php
+++ b/src/MessageHandler/ActivityPub/UpdateActorHandler.php
@@ -13,6 +13,7 @@
use App\Service\ActivityPubManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
@@ -21,6 +22,7 @@ class UpdateActorHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly ActivityPubManager $manager,
private readonly ApHttpClient $apHttpClient,
private readonly LockFactory $lockFactory,
@@ -28,7 +30,7 @@ public function __construct(
private readonly MagazineRepository $magazineRepository,
private readonly LoggerInterface $logger,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(UpdateActorMessage $message): void
diff --git a/src/MessageHandler/AttachEntryEmbedHandler.php b/src/MessageHandler/AttachEntryEmbedHandler.php
index 59b1e313b..f2b9c33c5 100644
--- a/src/MessageHandler/AttachEntryEmbedHandler.php
+++ b/src/MessageHandler/AttachEntryEmbedHandler.php
@@ -13,6 +13,7 @@
use App\Service\ImageManager;
use App\Utils\Embed;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -21,12 +22,13 @@ class AttachEntryEmbedHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntryRepository $entryRepository,
+ private readonly KernelInterface $kernel,
private readonly Embed $embed,
private readonly ImageManager $manager,
private readonly ImageRepository $imageRepository,
private readonly EntityManagerInterface $entityManager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryEmbedMessage $message): void
diff --git a/src/MessageHandler/DeleteImageHandler.php b/src/MessageHandler/DeleteImageHandler.php
index 18ac7b1e3..1006fe3a3 100644
--- a/src/MessageHandler/DeleteImageHandler.php
+++ b/src/MessageHandler/DeleteImageHandler.php
@@ -10,6 +10,7 @@
use App\Service\ImageManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -17,11 +18,12 @@ class DeleteImageHandler extends MbinMessageHandler
{
public function __construct(
private readonly ImageRepository $imageRepository,
+ private readonly KernelInterface $kernel,
private readonly ImageManager $imageManager,
private readonly EntityManagerInterface $entityManager,
private readonly ManagerRegistry $managerRegistry
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(DeleteImageMessage $message): void
@@ -34,7 +36,7 @@ public function doWork(MessageInterface $message): void
if (!($message instanceof DeleteImageMessage)) {
throw new \LogicException();
}
- $image = $this->imageRepository->find($message->id);
+ $image = $this->imageRepository->findOneBy(['id' => $message->id]);
if ($image) {
$this->entityManager->beginTransaction();
diff --git a/src/MessageHandler/DeleteUserHandler.php b/src/MessageHandler/DeleteUserHandler.php
index 228385e8b..55e67de32 100644
--- a/src/MessageHandler/DeleteUserHandler.php
+++ b/src/MessageHandler/DeleteUserHandler.php
@@ -14,6 +14,7 @@
use App\Service\UserManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -24,12 +25,13 @@ class DeleteUserHandler extends MbinMessageHandler
public function __construct(
private readonly LoggerInterface $logger,
private readonly ImageManager $imageManager,
+ private readonly KernelInterface $kernel,
private readonly UserManager $userManager,
private readonly DeleteWrapper $deleteWrapper,
private readonly MessageBusInterface $bus,
private readonly EntityManagerInterface $entityManager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(DeleteUserMessage $message): void
diff --git a/src/MessageHandler/LinkEmbedHandler.php b/src/MessageHandler/LinkEmbedHandler.php
index 06e823d4f..b37cef3e9 100644
--- a/src/MessageHandler/LinkEmbedHandler.php
+++ b/src/MessageHandler/LinkEmbedHandler.php
@@ -10,6 +10,7 @@
use App\Utils\Embed;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Cache\CacheItemPoolInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
@@ -17,11 +18,12 @@ class LinkEmbedHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EmbedRepository $embedRepository,
private readonly Embed $embed,
private readonly CacheItemPoolInterface $markdownCache
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(LinkEmbedMessage $message): void
diff --git a/src/MessageHandler/MagazinePurgeHandler.php b/src/MessageHandler/MagazinePurgeHandler.php
index 9d12d730d..b7e963a88 100644
--- a/src/MessageHandler/MagazinePurgeHandler.php
+++ b/src/MessageHandler/MagazinePurgeHandler.php
@@ -19,6 +19,7 @@
use App\Service\PostCommentManager;
use App\Service\PostManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\MessageBusInterface;
@@ -35,9 +36,10 @@ public function __construct(
private readonly PostCommentManager $postCommentManager,
private readonly PostManager $postManager,
private readonly MessageBusInterface $bus,
- private readonly EntityManagerInterface $entityManager
+ private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(MagazinePurgeMessage $message): void
diff --git a/src/MessageHandler/MbinMessageHandler.php b/src/MessageHandler/MbinMessageHandler.php
index 9607005aa..ca67afad7 100644
--- a/src/MessageHandler/MbinMessageHandler.php
+++ b/src/MessageHandler/MbinMessageHandler.php
@@ -7,11 +7,13 @@
use App\Message\Contracts\MessageInterface;
use Doctrine\DBAL\Exception;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
abstract class MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
) {
}
@@ -21,14 +23,19 @@ public function __construct(
*/
public function workWrapper(MessageInterface $message): void
{
- $conn = $this->entityManager->getConnection();
- if (!$conn->isConnected()) {
- $conn->connect();
+ // when we are in the test environment this would throw: ConnectionException: There is no active transaction.
+ if ('test' !== $this->kernel->getEnvironment()) {
+ $conn = $this->entityManager->getConnection();
+ if (!$conn->isConnected()) {
+ $conn->connect();
+ }
+
+ $conn->transactional(fn () => $this->doWork($message));
+
+ $conn->close();
+ } else {
+ $this->doWork($message);
}
-
- $conn->transactional(fn () => $this->doWork($message));
-
- $conn->close();
}
abstract public function doWork(MessageInterface $message): void;
diff --git a/src/MessageHandler/Notification/SentEntryCommentCreatedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryCommentCreatedNotificationHandler.php
index 52b87dcdf..c3b8a0542 100644
--- a/src/MessageHandler/Notification/SentEntryCommentCreatedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryCommentCreatedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryCommentCreatedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryCommentCreatedNotificationMessage $message)
diff --git a/src/MessageHandler/Notification/SentEntryCommentDeletedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryCommentDeletedNotificationHandler.php
index b4eb80e36..baa92c296 100644
--- a/src/MessageHandler/Notification/SentEntryCommentDeletedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryCommentDeletedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryCommentDeletedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryCommentDeletedNotificationMessage $message)
diff --git a/src/MessageHandler/Notification/SentEntryCommentEditedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryCommentEditedNotificationHandler.php
index fc62b9ac5..b849f8898 100644
--- a/src/MessageHandler/Notification/SentEntryCommentEditedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryCommentEditedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryCommentEditedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryCommentEditedNotificationMessage $message)
diff --git a/src/MessageHandler/Notification/SentEntryCreatedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryCreatedNotificationHandler.php
index 647d4ac8d..51220502a 100644
--- a/src/MessageHandler/Notification/SentEntryCreatedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryCreatedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryCreatedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryCreatedNotificationMessage $message)
diff --git a/src/MessageHandler/Notification/SentEntryDeletedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryDeletedNotificationHandler.php
index 6a386f7b2..ca73da1d9 100644
--- a/src/MessageHandler/Notification/SentEntryDeletedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryDeletedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryDeletedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryDeletedNotificationMessage $message)
diff --git a/src/MessageHandler/Notification/SentEntryEditedNotificationHandler.php b/src/MessageHandler/Notification/SentEntryEditedNotificationHandler.php
index 14d02c954..7cedfa0e9 100644
--- a/src/MessageHandler/Notification/SentEntryEditedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentEntryEditedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\EntryRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentEntryEditedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly EntryRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(EntryEditedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentFavouriteNotificationHandler.php b/src/MessageHandler/Notification/SentFavouriteNotificationHandler.php
index b1089a180..decb92ee4 100644
--- a/src/MessageHandler/Notification/SentFavouriteNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentFavouriteNotificationHandler.php
@@ -5,7 +5,6 @@
namespace App\MessageHandler\Notification;
use App\Entity\Contracts\FavouriteInterface;
-use App\Factory\MagazineFactory;
use App\Message\Contracts\MessageInterface;
use App\Message\Notification\FavouriteNotificationMessage;
use App\MessageHandler\MbinMessageHandler;
@@ -14,6 +13,7 @@
use App\Service\VotableRepositoryResolver;
use App\Utils\IriGenerator;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
@@ -23,13 +23,13 @@ class SentFavouriteNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
- private readonly MagazineFactory $magazineFactory,
+ private readonly KernelInterface $kernel,
private readonly VotableRepositoryResolver $resolver,
private readonly HubInterface $publisher,
private readonly GenerateHtmlClassService $classService,
private readonly SettingsManager $settingsManager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(FavouriteNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentMagazineBanNotificationHandler.php b/src/MessageHandler/Notification/SentMagazineBanNotificationHandler.php
index 817afc6ec..4fbfb0234 100644
--- a/src/MessageHandler/Notification/SentMagazineBanNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentMagazineBanNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\MagazineBanRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentMagazineBanNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly MagazineBanRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(MagazineBanNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostCommentCreatedNotificationHandler.php b/src/MessageHandler/Notification/SentPostCommentCreatedNotificationHandler.php
index 990f3740f..58c11d164 100644
--- a/src/MessageHandler/Notification/SentPostCommentCreatedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostCommentCreatedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostCommentCreatedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostCommentCreatedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostCommentDeletedNotificationHandler.php b/src/MessageHandler/Notification/SentPostCommentDeletedNotificationHandler.php
index e6fa8d958..0c6eadb2e 100644
--- a/src/MessageHandler/Notification/SentPostCommentDeletedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostCommentDeletedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostCommentDeletedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostCommentDeletedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostCommentEditedNotificationHandler.php b/src/MessageHandler/Notification/SentPostCommentEditedNotificationHandler.php
index 48fded6f0..422faf640 100644
--- a/src/MessageHandler/Notification/SentPostCommentEditedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostCommentEditedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostCommentRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostCommentEditedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostCommentRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostCommentEditedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostCreatedNotificationHandler.php b/src/MessageHandler/Notification/SentPostCreatedNotificationHandler.php
index 80900b344..554404018 100644
--- a/src/MessageHandler/Notification/SentPostCreatedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostCreatedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostCreatedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostCreatedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostDeletedNotificationHandler.php b/src/MessageHandler/Notification/SentPostDeletedNotificationHandler.php
index 781d8740c..a5b8e51dc 100644
--- a/src/MessageHandler/Notification/SentPostDeletedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostDeletedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostDeletedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostDeletedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentPostEditedNotificationHandler.php b/src/MessageHandler/Notification/SentPostEditedNotificationHandler.php
index 0712cf894..f14229a11 100644
--- a/src/MessageHandler/Notification/SentPostEditedNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentPostEditedNotificationHandler.php
@@ -10,6 +10,7 @@
use App\Repository\PostRepository;
use App\Service\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
@@ -18,10 +19,11 @@ class SentPostEditedNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly PostRepository $repository,
private readonly NotificationManager $manager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(PostEditedNotificationMessage $message): void
diff --git a/src/MessageHandler/Notification/SentVoteNotificationHandler.php b/src/MessageHandler/Notification/SentVoteNotificationHandler.php
index 569af19f4..e83d77659 100644
--- a/src/MessageHandler/Notification/SentVoteNotificationHandler.php
+++ b/src/MessageHandler/Notification/SentVoteNotificationHandler.php
@@ -5,7 +5,6 @@
namespace App\MessageHandler\Notification;
use App\Entity\Contracts\VotableInterface;
-use App\Factory\MagazineFactory;
use App\Message\Contracts\MessageInterface;
use App\Message\Notification\VoteNotificationMessage;
use App\MessageHandler\MbinMessageHandler;
@@ -14,6 +13,7 @@
use App\Service\VotableRepositoryResolver;
use App\Utils\IriGenerator;
use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
@@ -23,13 +23,13 @@ class SentVoteNotificationHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
- private readonly MagazineFactory $magazineFactory,
+ private readonly KernelInterface $kernel,
private readonly VotableRepositoryResolver $resolver,
private readonly HubInterface $publisher,
private readonly GenerateHtmlClassService $classService,
private readonly SettingsManager $settingsManager
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(VoteNotificationMessage $message): void
diff --git a/src/MessageHandler/SentUserConfirmationEmailHandler.php b/src/MessageHandler/SentUserConfirmationEmailHandler.php
index 5185b611b..8e6eeea3f 100644
--- a/src/MessageHandler/SentUserConfirmationEmailHandler.php
+++ b/src/MessageHandler/SentUserConfirmationEmailHandler.php
@@ -13,6 +13,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Mime\Address;
@@ -23,13 +24,14 @@ class SentUserConfirmationEmailHandler extends MbinMessageHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
+ private readonly KernelInterface $kernel,
private readonly SettingsManager $settingsManager,
private readonly EmailVerifier $emailVerifier,
private readonly UserRepository $repository,
private readonly ParameterBagInterface $params,
private readonly TranslatorInterface $translator
) {
- parent::__construct($this->entityManager);
+ parent::__construct($this->entityManager, $this->kernel);
}
public function __invoke(SendConfirmationEmailInterface $message): void
diff --git a/src/Repository/StatsContentRepository.php b/src/Repository/StatsContentRepository.php
index 66c5e4429..41326fe84 100644
--- a/src/Repository/StatsContentRepository.php
+++ b/src/Repository/StatsContentRepository.php
@@ -46,8 +46,8 @@ private function getMonthlyStats(string $table): array
$onlyLocalWhere = $this->onlyLocal ? ' AND e.ap_id IS NULL' : '';
$userWhere = $this->user ? ' AND e.user_id = :userId ' : '';
$magazineWhere = $this->magazine ? ' AND e.magazine_id = :magazineId ' : '';
- $sql = "SELECT to_char(e.created_at,'Mon') as month, extract(year from e.created_at) as year, COUNT(e.id) as count FROM $table e
- INNER JOIN public.user u ON u.id = user_id
+ $sql = "SELECT to_char(e.created_at,'Mon') as month, extract(year from e.created_at) as year, COUNT(e.id) as count FROM $table e
+ INNER JOIN public.user u ON u.id = user_id
WHERE u.is_deleted = false $onlyLocalWhere $userWhere $magazineWhere GROUP BY 1,2";
$stmt = $conn->prepare($sql);
@@ -89,7 +89,7 @@ private function getDailyStats(string $table): array
$onlyLocalWhere = $this->onlyLocal ? ' AND e.ap_id IS NULL' : '';
$userWhere = $this->user ? ' AND e.user_id = :userId ' : '';
$magazineWhere = $this->magazine ? ' AND e.magazine_id = :magazineId ' : '';
- $sql = "SELECT date_trunc('day', e.created_at) as day, COUNT(e.id) as count FROM $table e
+ $sql = "SELECT date_trunc('day', e.created_at) as day, COUNT(e.id) as count FROM $table e
INNER JOIN public.user u ON e.user_id = u.id
WHERE u.is_deleted = false AND e.created_at >= :startDate $userWhere $magazineWhere $onlyLocalWhere GROUP BY 1";
@@ -109,7 +109,7 @@ private function getDailyStats(string $table): array
return $results;
}
- public function getStats(?Magazine $magazine, string $interval, ?\DateTime $start, ?\DateTime $end, ?bool $onlyLocal): array
+ public function getStats(?Magazine $magazine, string $interval, ?\DateTimeImmutable $start, ?\DateTimeImmutable $end, ?bool $onlyLocal): array
{
switch ($interval) {
case 'all':
@@ -122,9 +122,9 @@ public function getStats(?Magazine $magazine, string $interval, ?\DateTime $star
throw new \LogicException('Invalid interval provided');
}
if (null !== $start && null === $end) {
- $end = $start->modify('-1 '.$interval);
+ $end = $start->modify('+1 '.$interval);
} elseif (null === $start && null !== $end) {
- $start = $end->modify('+1 '.$interval);
+ $start = $end->modify('-1 '.$interval);
}
return [
diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php
index 397e58656..e44b74609 100644
--- a/src/Service/ActivityPubManager.php
+++ b/src/Service/ActivityPubManager.php
@@ -93,7 +93,7 @@ public function findRemoteActor(string $actorUrl): ?User
return $this->userRepository->findOneBy(['apProfileId' => $actorUrl]);
}
- public function createCcFromBody(string $body): array
+ public function createCcFromBody(?string $body): array
{
$mentions = $this->mentionManager->extract($body) ?? [];
diff --git a/src/Service/EntryManager.php b/src/Service/EntryManager.php
index 0d600a1f9..da6047f3e 100644
--- a/src/Service/EntryManager.php
+++ b/src/Service/EntryManager.php
@@ -131,7 +131,8 @@ public function create(EntryDto $dto, User $user, bool $rateLimit = true, bool $
$this->entityManager->persist($entry);
$this->entityManager->flush();
- $this->tagManager->updateEntryTags($entry, $this->tagExtractor->extract($entry->body) ?? []);
+ $tags = array_unique(array_merge($this->tagExtractor->extract($entry->body) ?? [], $dto->tags ?? []));
+ $this->tagManager->updateEntryTags($entry, $tags);
$this->dispatcher->dispatch(new EntryCreatedEvent($entry));
diff --git a/src/Service/SearchManager.php b/src/Service/SearchManager.php
index 8b62a943f..528a79cfe 100644
--- a/src/Service/SearchManager.php
+++ b/src/Service/SearchManager.php
@@ -74,7 +74,8 @@ public function findActivityPubActorsByUsername(string $query): array
}
$objects = [];
- $name = str_starts_with($query, '@') ? $query : '@'.$query;
+ $name = str_starts_with($query, '!') ? '@'.substr($query, 1) : $query;
+ $name = str_starts_with($name, '@') ? $name : '@'.$name;
preg_match(RegPatterns::AP_USER, $name, $matches);
if (\count(array_filter($matches)) >= 4) {
try {
diff --git a/src/Service/TagExtractor.php b/src/Service/TagExtractor.php
index a107c68f0..8d3832609 100644
--- a/src/Service/TagExtractor.php
+++ b/src/Service/TagExtractor.php
@@ -8,7 +8,7 @@
class TagExtractor
{
- public function joinTagsToBody(string $body, array $tags): string
+ public function joinTagsToBody(?string $body, array $tags): string
{
$current = $this->extract($body) ?? [];
diff --git a/tests/FactoryTrait.php b/tests/FactoryTrait.php
index 91f595fb7..539d2b9fc 100644
--- a/tests/FactoryTrait.php
+++ b/tests/FactoryTrait.php
@@ -46,6 +46,7 @@
use League\Bundle\OAuth2ServerBundle\ValueObject\Grant;
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
use League\Bundle\OAuth2ServerBundle\ValueObject\Scope;
+use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -240,16 +241,20 @@ static function (User $user) use ($username) {
}
)->first();
- $user = $user ?: $this->createUser($username, hideAdult: $hideAdult, about: $about, active: $active);
+ if ($user) {
+ return $user;
+ }
+
+ $user = $this->createUser($username, hideAdult: $hideAdult, about: $about, active: $active);
if ($isAdmin) {
$user->roles = ['ROLE_ADMIN'];
- $manager = $this->getService(EntityManagerInterface::class);
-
- $manager->persist($user);
- $manager->flush();
}
+ $manager = $this->getService(EntityManagerInterface::class);
+ $manager->persist($user);
+ $manager->flush();
+
return $user;
}
@@ -326,7 +331,7 @@ static function (Magazine $magazine) use ($name) {
}
)->first();
- return $magazine ?: $this->createMagazine($name, null, $user, $isAdult);
+ return $magazine ?: $this->createMagazine($name, $name, $user, $isAdult);
}
protected function getMagazineByNameNoRSAKey(string $name, ?User $user = null, bool $isAdult = false): Magazine
@@ -501,7 +506,10 @@ public function createPostCommentReply(string $body, ?Post $post = null, ?User $
public function createImage(string $fileName): Image
{
- return new Image(
+ $imageRepo = self::getService(ImageRepository::class);
+ $image = $imageRepo->findOneBy(['fileName' => $fileName]);
+
+ return $image ?? new Image(
$fileName,
'/dev/random',
hash('sha256', $fileName),
@@ -576,6 +584,38 @@ public function createModlogMessages(): void
$magazineManager->ban($magazine, $user, $moderator, MagazineBanDto::create('test ban', new \DateTimeImmutable('+12 hours')));
}
+ public function register($active = false): KernelBrowser
+ {
+ $crawler = $this->client->request('GET', '/register');
+
+ $this->client->submit(
+ $crawler->filter('form[name=user_register]')->selectButton('Register')->form(
+ [
+ 'user_register[username]' => 'JohnDoe',
+ 'user_register[email]' => 'johndoe@kbin.pub',
+ 'user_register[plainPassword][first]' => 'secret',
+ 'user_register[plainPassword][second]' => 'secret',
+ 'user_register[agreeTerms]' => true,
+ ]
+ )
+ );
+ if (302 === $this->client->getResponse()->getStatusCode()) {
+ $this->client->followRedirect();
+ }
+ self::assertResponseIsSuccessful();
+
+ if ($active) {
+ $user = self::getContainer()->get('doctrine')->getRepository(User::class)
+ ->findOneBy(['username' => 'JohnDoe']);
+ $user->isVerified = true;
+
+ self::getContainer()->get('doctrine')->getManager()->flush();
+ self::getContainer()->get('doctrine')->getManager()->refresh($user);
+ }
+
+ return $this->client;
+ }
+
public function getKibbyImageDto(): ImageDto
{
$imageRepository = $this->getService(ImageRepository::class);
diff --git a/tests/Functional/Controller/Admin/AdminFederationControllerTest.php b/tests/Functional/Controller/Admin/AdminFederationControllerTest.php
index 4f5931453..f591ef550 100644
--- a/tests/Functional/Controller/Admin/AdminFederationControllerTest.php
+++ b/tests/Functional/Controller/Admin/AdminFederationControllerTest.php
@@ -12,15 +12,13 @@ class AdminFederationControllerTest extends WebTestCase
{
public function testAdminCanClearBannedInstances(): void
{
- $client = $this->createClient();
-
$this->getService(SettingsManager::class)->set('KBIN_BANNED_INSTANCES', ['www.example.com']);
- $client->loginUser($this->getUserByUsername('admin', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('admin', isAdmin: true));
- $crawler = $client->request('GET', '/admin/federation');
+ $crawler = $this->client->request('GET', '/admin/federation');
- $client->submit($crawler->filter('#content form[name=instances] button')->form(
+ $this->client->submit($crawler->filter('#content form[name=instances] button[type=submit]')->form(
['instances[instances]' => ''],
));
diff --git a/tests/Functional/Controller/Api/Domain/DomainBlockApiTest.php b/tests/Functional/Controller/Api/Domain/DomainBlockApiTest.php
index e2567a0e7..2faff62f5 100644
--- a/tests/Functional/Controller/Api/Domain/DomainBlockApiTest.php
+++ b/tests/Functional/Controller/Api/Domain/DomainBlockApiTest.php
@@ -11,44 +11,38 @@ class DomainBlockApiTest extends WebTestCase
{
public function testApiCannotBlockDomainAnonymous()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
- $client->request('PUT', "/api/domain/{$domain->getId()}/block");
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/block");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotBlockDomainWithoutScope()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanBlockDomain()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:block');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -60,10 +54,10 @@ public function testApiCanBlockDomain()
self::assertNull($jsonData['isUserSubscribed']);
// Idempotent when called multiple times
- $client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/block", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -77,47 +71,41 @@ public function testApiCanBlockDomain()
public function testApiCannotUnblockDomainAnonymous()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
- $client->request('PUT', "/api/domain/{$domain->getId()}/unblock");
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unblock");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnblockDomainWithoutScope()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnblockDomain()
{
- $client = self::createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$manager = $this->getService(DomainManager::class);
$manager->block($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:block');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -129,10 +117,10 @@ public function testApiCanUnblockDomain()
self::assertNull($jsonData['isUserSubscribed']);
// Idempotent when called multiple times
- $client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unblock", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Domain/DomainRetrieveApiTest.php b/tests/Functional/Controller/Api/Domain/DomainRetrieveApiTest.php
index 54b8155f1..d5f14cdd0 100644
--- a/tests/Functional/Controller/Api/Domain/DomainRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Domain/DomainRetrieveApiTest.php
@@ -11,14 +11,12 @@ class DomainRetrieveApiTest extends WebTestCase
{
public function testApiCanRetrieveDomainsAnonymous()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a domain', 'https://example.com');
- $client->request('GET', '/api/domains');
+ $this->client->request('GET', '/api/domains');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -39,19 +37,17 @@ public function testApiCanRetrieveDomainsAnonymous()
public function testApiCanRetrieveDomains()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a domain', 'https://example.com');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -73,22 +69,20 @@ public function testApiCanRetrieveDomains()
public function testApiCanRetrieveDomainsSubscriptionAndBlockStatus()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
$manager = $this->getService(DomainManager::class);
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:subscribe domain:block');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:subscribe domain:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -110,16 +104,12 @@ public function testApiCanRetrieveDomainsSubscriptionAndBlockStatus()
public function testApiCannotRetrieveSubscribedDomainsAnonymous()
{
- $client = self::createClient();
-
- $client->request('GET', '/api/domains/subscribed');
+ $this->client->request('GET', '/api/domains/subscribed');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveSubscribedDomainsWithoutScope()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a second domain', 'https://example.org');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
@@ -127,18 +117,16 @@ public function testApiCannotRetrieveSubscribedDomainsWithoutScope()
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveSubscribedDomains()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a second domain', 'https://example.org');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
@@ -146,14 +134,14 @@ public function testApiCanRetrieveSubscribedDomains()
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:subscribe');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -176,16 +164,12 @@ public function testApiCanRetrieveSubscribedDomains()
public function testApiCannotRetrieveBlockedDomainsAnonymous()
{
- $client = self::createClient();
-
- $client->request('GET', '/api/domains/blocked');
+ $this->client->request('GET', '/api/domains/blocked');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveBlockedDomainsWithoutScope()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a second domain', 'https://example.org');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
@@ -193,18 +177,16 @@ public function testApiCannotRetrieveBlockedDomainsWithoutScope()
$manager->block($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveBlockedDomains()
{
- $client = self::createClient();
-
$this->getEntryByTitle('Test link to a second domain', 'https://example.org');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
@@ -212,14 +194,14 @@ public function testApiCanRetrieveBlockedDomains()
$manager->block($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:block');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/domains/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/domains/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -242,14 +224,12 @@ public function testApiCanRetrieveBlockedDomains()
public function testApiCanRetrieveDomainByIdAnonymous()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
- $client->request('GET', "/api/domain/{$domain->getId()}");
+ $this->client->request('GET', "/api/domain/{$domain->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -262,22 +242,20 @@ public function testApiCanRetrieveDomainByIdAnonymous()
public function testApiCanRetrieveDomainById()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
$manager = $this->getService(DomainManager::class);
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -291,22 +269,20 @@ public function testApiCanRetrieveDomainById()
public function testApiCanRetrieveDomainByIdSubscriptionAndBlockStatus()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$user = $this->getUserByUsername('JohnDoe');
$manager = $this->getService(DomainManager::class);
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:subscribe domain:block');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:subscribe domain:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Domain/DomainSubscribeApiTest.php b/tests/Functional/Controller/Api/Domain/DomainSubscribeApiTest.php
index 300ac4c0f..8402157d0 100644
--- a/tests/Functional/Controller/Api/Domain/DomainSubscribeApiTest.php
+++ b/tests/Functional/Controller/Api/Domain/DomainSubscribeApiTest.php
@@ -11,44 +11,38 @@ class DomainSubscribeApiTest extends WebTestCase
{
public function testApiCannotSubscribeToDomainAnonymous()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
- $client->request('PUT', "/api/domain/{$domain->getId()}/subscribe");
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/subscribe");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSubscribeToDomainWithoutScope()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSubscribeToDomain()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:subscribe');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -60,10 +54,10 @@ public function testApiCanSubscribeToDomain()
self::assertNull($jsonData['isBlockedByUser']);
// Idempotent when called multiple times
- $client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/subscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -77,47 +71,41 @@ public function testApiCanSubscribeToDomain()
public function testApiCannotUnsubscribeFromDomainAnonymous()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
- $client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe");
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnsubscribeFromDomainWithoutScope()
{
- $client = self::createClient();
-
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnsubscribeFromDomain()
{
- $client = self::createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
$manager = $this->getService(DomainManager::class);
$manager->subscribe($domain, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read domain:subscribe');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read domain:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
@@ -129,10 +117,10 @@ public function testApiCanUnsubscribeFromDomain()
self::assertNull($jsonData['isBlockedByUser']);
// Idempotent when called multiple times
- $client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/domain/{$domain->getId()}/unsubscribe", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(DomainRetrieveApiTest::DOMAIN_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Admin/EntryChangeMagazineApiTest.php b/tests/Functional/Controller/Api/Entry/Admin/EntryChangeMagazineApiTest.php
index ceac1c1bd..235d23eea 100644
--- a/tests/Functional/Controller/Api/Entry/Admin/EntryChangeMagazineApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Admin/EntryChangeMagazineApiTest.php
@@ -10,68 +10,64 @@ class EntryChangeMagazineApiTest extends WebTestCase
{
public function testApiCannotChangeEntryMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$magazine2 = $this->getMagazineByNameNoRSAKey('acme2');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}");
+ $this->client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonAdminCannotChangeEntryMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$magazine2 = $this->getMagazineByNameNoRSAKey('acme2');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:magazine:move_entry');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:magazine:move_entry');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotChangeEntryMagazineWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$magazine2 = $this->getMagazineByNameNoRSAKey('acme2');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanChangeEntryMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$magazine2 = $this->getMagazineByNameNoRSAKey('acme2');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:magazine:move_entry');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:magazine:move_entry');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/admin/entry/{$entry->getId()}/change-magazine/{$magazine2->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -89,7 +85,7 @@ public function testApiCanChangeEntryMagazine(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/Admin/EntryPurgeApiTest.php b/tests/Functional/Controller/Api/Entry/Admin/EntryPurgeApiTest.php
index 2556b5ae8..00195034e 100644
--- a/tests/Functional/Controller/Api/Entry/Admin/EntryPurgeApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Admin/EntryPurgeApiTest.php
@@ -10,145 +10,135 @@ class EntryPurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeArticleEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', magazine: $magazine);
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeArticleEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminCannotPurgeArticleEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPurgeArticleEntry(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotPurgeLinkEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', magazine: $magazine);
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeLinkEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminCannotPurgeLinkEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPurgeLinkEntry(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotPurgeImageEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
$entry = $this->getEntryByTitle('test image', image: $imageDto, magazine: $magazine);
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeImageEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user', isAdmin: true);
@@ -156,18 +146,17 @@ public function testApiCannotPurgeImageEntryWithoutScope(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminCannotPurgeImageEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -176,18 +165,17 @@ public function testApiNonAdminCannotPurgeImageEntry(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPurgeImageEntry(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -196,12 +184,12 @@ public function testApiCanPurgeImageEntry(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/entry/{$entry->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
}
diff --git a/tests/Functional/Controller/Api/Entry/Comment/Admin/EntryCommentPurgeApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/Admin/EntryCommentPurgeApiTest.php
index e8e29780a..352687e7f 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/Admin/EntryCommentPurgeApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/Admin/EntryCommentPurgeApiTest.php
@@ -11,14 +11,13 @@ class EntryCommentPurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeArticleEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry);
$commentRepository = $this->getService(EntryCommentRepository::class);
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge");
self::assertResponseStatusCodeSame(401);
$comment = $commentRepository->find($comment->getId());
@@ -27,7 +26,6 @@ public function testApiCannotPurgeArticleEntryAnonymous(): void
public function testApiCannotPurgeArticleEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $user, magazine: $magazine);
@@ -36,12 +34,12 @@ public function testApiCannotPurgeArticleEntryWithoutScope(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -50,7 +48,6 @@ public function testApiCannotPurgeArticleEntryWithoutScope(): void
public function testApiNonAdminCannotPurgeComment(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -60,12 +57,12 @@ public function testApiNonAdminCannotPurgeComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -74,7 +71,6 @@ public function testApiNonAdminCannotPurgeComment(): void
public function testApiCanPurgeComment(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -84,12 +80,12 @@ public function testApiCanPurgeComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
@@ -98,7 +94,6 @@ public function testApiCanPurgeComment(): void
public function testApiCannotPurgeImageCommentAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
@@ -107,7 +102,7 @@ public function testApiCannotPurgeImageCommentAnonymous(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge");
self::assertResponseStatusCodeSame(401);
$comment = $commentRepository->find($comment->getId());
@@ -116,7 +111,6 @@ public function testApiCannotPurgeImageCommentAnonymous(): void
public function testApiCannotPurgeImageCommentWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user', isAdmin: true);
@@ -127,12 +121,12 @@ public function testApiCannotPurgeImageCommentWithoutScope(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -141,7 +135,6 @@ public function testApiCannotPurgeImageCommentWithoutScope(): void
public function testApiNonAdminCannotPurgeImageComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -152,12 +145,12 @@ public function testApiNonAdminCannotPurgeImageComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -166,7 +159,6 @@ public function testApiNonAdminCannotPurgeImageComment(): void
public function testApiCanPurgeImageComment(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -177,12 +169,12 @@ public function testApiCanPurgeImageComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:entry_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:entry_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
diff --git a/tests/Functional/Controller/Api/Entry/Comment/DomainEntryCommentRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/DomainEntryCommentRetrieveApiTest.php
index 78f62a595..f5aeb2a6c 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/DomainEntryCommentRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/DomainEntryCommentRetrieveApiTest.php
@@ -13,16 +13,15 @@ class DomainEntryCommentRetrieveApiTest extends WebTestCase
{
public function testApiCanGetDomainEntryCommentsAnonymous(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry);
$domain = $entry->domain;
- $client->request('GET', "/api/domain/{$domain->getId()}/comments");
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -48,7 +47,6 @@ public function testApiCanGetDomainEntryCommentsAnonymous(): void
public function testApiCanGetDomainEntryComments(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -56,14 +54,14 @@ public function testApiCanGetDomainEntryComments(): void
$domain = $entry->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -89,7 +87,6 @@ public function testApiCanGetDomainEntryComments(): void
public function testApiCanGetDomainEntryCommentsDepth(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -100,14 +97,14 @@ public function testApiCanGetDomainEntryCommentsDepth(): void
$domain = $entry->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -144,7 +141,6 @@ public function testApiCanGetDomainEntryCommentsDepth(): void
public function testApiCanGetDomainEntryCommentsNewest(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -162,14 +158,14 @@ public function testApiCanGetDomainEntryCommentsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -195,7 +191,6 @@ public function testApiCanGetDomainEntryCommentsNewest(): void
public function testApiCanGetDomainEntryCommentsOldest(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -213,14 +208,14 @@ public function testApiCanGetDomainEntryCommentsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -246,7 +241,6 @@ public function testApiCanGetDomainEntryCommentsOldest(): void
public function testApiCanGetDomainEntryCommentsActive(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -264,14 +258,14 @@ public function testApiCanGetDomainEntryCommentsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -297,7 +291,6 @@ public function testApiCanGetDomainEntryCommentsActive(): void
public function testApiCanGetDomainEntryCommentsTop(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -310,14 +303,14 @@ public function testApiCanGetDomainEntryCommentsTop(): void
$favouriteManager->toggle($this->getUserByUsername('voter1'), $second);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -346,7 +339,6 @@ public function testApiCanGetDomainEntryCommentsTop(): void
public function testApiCanGetDomainEntryCommentsHot(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -359,14 +351,14 @@ public function testApiCanGetDomainEntryCommentsHot(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -395,7 +387,6 @@ public function testApiCanGetDomainEntryCommentsHot(): void
public function testApiCanGetDomainEntryCommentsWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -403,14 +394,14 @@ public function testApiCanGetDomainEntryCommentsWithUserVoteStatus(): void
$domain = $entry->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -431,9 +422,11 @@ public function testApiCanGetDomainEntryCommentsWithUserVoteStatus(): void
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
self::assertIsArray($jsonData['items'][0]['user']);
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['childCount']);
self::assertIsArray($jsonData['items'][0]['children']);
self::assertEmpty($jsonData['items'][0]['children']);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentCreateApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentCreateApiTest.php
index f8917d3d5..bba448a69 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentCreateApiTest.php
@@ -11,7 +11,6 @@ class EntryCommentCreateApiTest extends WebTestCase
{
public function testApiCannotCreateCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -20,7 +19,7 @@ public function testApiCannotCreateCommentAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments",
parameters: $comment
);
@@ -30,7 +29,6 @@ public function testApiCannotCreateCommentAnonymous(): void
public function testApiCannotCreateCommentWithoutScope(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -40,12 +38,12 @@ public function testApiCannotCreateCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
@@ -55,7 +53,6 @@ public function testApiCannotCreateCommentWithoutScope(): void
public function testApiCanCreateComment(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -66,18 +63,18 @@ public function testApiCanCreateComment(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -97,7 +94,6 @@ public function testApiCanCreateComment(): void
public function testApiCannotCreateCommentReplyAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -107,7 +103,7 @@ public function testApiCannotCreateCommentReplyAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply",
parameters: $comment
);
@@ -117,7 +113,6 @@ public function testApiCannotCreateCommentReplyAnonymous(): void
public function testApiCannotCreateCommentReplyWithoutScope(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -128,12 +123,12 @@ public function testApiCannotCreateCommentReplyWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
@@ -143,7 +138,6 @@ public function testApiCannotCreateCommentReplyWithoutScope(): void
public function testApiCanCreateCommentReply(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -155,18 +149,18 @@ public function testApiCanCreateCommentReply(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -186,7 +180,6 @@ public function testApiCanCreateCommentReply(): void
public function testApiCannotCreateImageCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -200,7 +193,7 @@ public function testApiCannotCreateImageCommentAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image]
);
@@ -210,7 +203,6 @@ public function testApiCannotCreateImageCommentAnonymous(): void
public function testApiCannotCreateImageCommentWithoutScope(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -225,12 +217,12 @@ public function testApiCannotCreateImageCommentWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -241,7 +233,6 @@ public function testApiCannotCreateImageCommentWithoutScope(): void
public function testApiCanCreateImageComment(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = [
@@ -257,19 +248,19 @@ public function testApiCanCreateImageComment(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -289,7 +280,6 @@ public function testApiCanCreateImageComment(): void
public function testApiCannotCreateImageCommentReplyAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -304,7 +294,7 @@ public function testApiCannotCreateImageCommentReplyAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image]
);
@@ -314,7 +304,6 @@ public function testApiCannotCreateImageCommentReplyAnonymous(): void
public function testApiCannotCreateImageCommentReplyWithoutScope(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -329,12 +318,12 @@ public function testApiCannotCreateImageCommentReplyWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -345,7 +334,6 @@ public function testApiCannotCreateImageCommentReplyWithoutScope(): void
public function testApiCanCreateImageCommentReply(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$entryComment = $this->createEntryComment('a comment', $entry);
@@ -362,19 +350,19 @@ public function testApiCanCreateImageCommentReply(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/entry/{$entry->getId()}/comments/{$entryComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentDeleteApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentDeleteApiTest.php
index 0198bcb3f..7abf2f9a8 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentDeleteApiTest.php
@@ -11,55 +11,51 @@ class EntryCommentDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->request('DELETE', "/api/comments/{$comment->getId()}");
+ $this->client->request('DELETE', "/api/comments/{$comment->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -67,12 +63,12 @@ public function testApiCanDeleteComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
@@ -81,7 +77,6 @@ public function testApiCanDeleteComment(): void
public function testApiCanSoftDeleteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -90,12 +85,12 @@ public function testApiCanSoftDeleteComment(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentReportApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentReportApiTest.php
index 357e3063a..9121830e1 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentReportApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentReportApiTest.php
@@ -11,7 +11,6 @@ class EntryCommentReportApiTest extends WebTestCase
{
public function testApiCannotReportCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
@@ -19,14 +18,13 @@ public function testApiCannotReportCommentAnonymous(): void
'reason' => 'This comment breaks the rules!',
];
- $client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report);
+ $this->client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotReportCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -36,19 +34,18 @@ public function testApiCannotReportCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanReportOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$entry = $this->getEntryByTitle('an entry', body: 'test');
@@ -61,12 +58,12 @@ public function testApiCanReportOtherUsersComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$report = $reportRepository->findBySubject($comment);
@@ -77,7 +74,6 @@ public function testApiCanReportOtherUsersComment(): void
public function testApiCanReportOwnComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -89,12 +85,12 @@ public function testApiCanReportOwnComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$report = $reportRepository->findBySubject($comment);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentRetrieveApiTest.php
index 7530433a8..89c4ff2ed 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentRetrieveApiTest.php
@@ -11,15 +11,14 @@ class EntryCommentRetrieveApiTest extends WebTestCase
{
public function testApiCanGetEntryCommentsAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
}
- $client->request('GET', "/api/entry/{$entry->getId()}/comments");
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -56,7 +55,7 @@ public function testApiCanGetEntryCommentsAnonymous(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -65,19 +64,17 @@ public function testApiCanGetEntryCommentsAnonymous(): void
public function testApiCannotGetEntryCommentsByPreferredLangAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
}
- $client->request('GET', "/api/entry/{$entry->getId()}/comments?usePreferredLangs=true");
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments?usePreferredLangs=true");
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetEntryCommentsByPreferredLang(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
@@ -93,14 +90,14 @@ public function testApiCanGetEntryCommentsByPreferredLang(): void
$entityManager->persist($user);
$entityManager->flush();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}/comments?usePreferredLangs=true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments?usePreferredLangs=true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -138,7 +135,7 @@ public function testApiCanGetEntryCommentsByPreferredLang(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -147,7 +144,6 @@ public function testApiCanGetEntryCommentsByPreferredLang(): void
public function testApiCanGetEntryCommentsWithLanguageAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
@@ -155,9 +151,9 @@ public function testApiCanGetEntryCommentsWithLanguageAnonymous(): void
$this->createEntryComment("test dutch comment {$i}", $entry, lang: 'nl');
}
- $client->request('GET', "/api/entry/{$entry->getId()}/comments?lang[]=en&lang[]=de");
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments?lang[]=en&lang[]=de");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -194,7 +190,7 @@ public function testApiCanGetEntryCommentsWithLanguageAnonymous(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -203,7 +199,6 @@ public function testApiCanGetEntryCommentsWithLanguageAnonymous(): void
public function testApiCanGetEntryCommentsWithLanguage(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
@@ -212,14 +207,14 @@ public function testApiCanGetEntryCommentsWithLanguage(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}/comments?lang[]=en&lang[]=de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments?lang[]=en&lang[]=de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -257,7 +252,7 @@ public function testApiCanGetEntryCommentsWithLanguage(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -266,21 +261,20 @@ public function testApiCanGetEntryCommentsWithLanguage(): void
public function testApiCanGetEntryComments(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$this->createEntryComment("test parent comment {$i}", $entry);
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -318,7 +312,7 @@ public function testApiCanGetEntryComments(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -327,7 +321,6 @@ public function testApiCanGetEntryComments(): void
public function testApiCanGetEntryCommentsWithChildren(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 5; ++$i) {
$comment = $this->createEntryComment("test parent comment {$i}", $entry);
@@ -335,14 +328,14 @@ public function testApiCanGetEntryCommentsWithChildren(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -383,7 +376,7 @@ public function testApiCanGetEntryCommentsWithChildren(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -392,7 +385,6 @@ public function testApiCanGetEntryCommentsWithChildren(): void
public function testApiCanGetEntryCommentsLimitedDepth(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
for ($i = 0; $i < 2; ++$i) {
$comment = $this->createEntryComment("test parent comment {$i}", $entry);
@@ -403,14 +395,14 @@ public function testApiCanGetEntryCommentsLimitedDepth(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}/comments?d=3", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}/comments?d=3", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -459,7 +451,7 @@ public function testApiCanGetEntryCommentsLimitedDepth(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -468,13 +460,12 @@ public function testApiCanGetEntryCommentsLimitedDepth(): void
public function testApiCanGetEntryCommentByIdAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
$comment = $this->createEntryComment('test parent comment', $entry);
- $client->request('GET', "/api/comments/{$comment->getId()}");
+ $this->client->request('GET', "/api/comments/{$comment->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -501,7 +492,7 @@ public function testApiCanGetEntryCommentByIdAnonymous(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
@@ -509,19 +500,18 @@ public function testApiCanGetEntryCommentByIdAnonymous(): void
public function testApiCanGetEntryCommentById(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
$comment = $this->createEntryComment('test parent comment', $entry);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -549,7 +539,7 @@ public function testApiCanGetEntryCommentById(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
@@ -557,7 +547,6 @@ public function testApiCanGetEntryCommentById(): void
public function testApiCanGetEntryCommentByIdWithDepth(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('test entry', body: 'test');
$comment = $this->createEntryComment('test parent comment', $entry);
$parent = $comment;
@@ -566,14 +555,14 @@ public function testApiCanGetEntryCommentByIdWithDepth(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/comments/{$comment->getId()}?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/comments/{$comment->getId()}?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -601,7 +590,7 @@ public function testApiCanGetEntryCommentByIdWithDepth(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentUpdateApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentUpdateApiTest.php
index 4af025c74..5b83bddd5 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentUpdateApiTest.php
@@ -10,7 +10,6 @@ class EntryCommentUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
@@ -20,14 +19,13 @@ public function testApiCannotUpdateCommentAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update);
+ $this->client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -39,19 +37,18 @@ public function testApiCannotUpdateCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$entry = $this->getEntryByTitle('an entry', body: 'test');
@@ -64,19 +61,18 @@ public function testApiCannotUpdateOtherUsersComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -92,15 +88,15 @@ public function testApiCanUpdateComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/comments/{$comment->getId()}?d=2", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/comments/{$comment->getId()}?d=2", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentVoteApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentVoteApiTest.php
index 41b7965f5..d8feac45d 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/EntryCommentVoteApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/EntryCommentVoteApiTest.php
@@ -12,50 +12,47 @@ class EntryCommentVoteApiTest extends WebTestCase
{
public function testApiCannotUpvoteCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/1");
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpvoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpvoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -68,50 +65,47 @@ public function testApiCanUpvoteComment(): void
public function testApiCannotDownvoteCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1");
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDownvoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDownvoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -124,21 +118,19 @@ public function testApiCanDownvoteComment(): void
public function testApiCannotRemoveVoteCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
$voteManager = $this->getService(VoteManager::class);
$voteManager->vote(1, $comment, $this->getUserByUsername('user'), rateLimit: false);
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/0");
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/0");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRemoveVoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -147,19 +139,18 @@ public function testApiCannotRemoveVoteCommentWithoutScope(): void
$voteManager->vote(1, $comment, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRemoveVoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -168,15 +159,15 @@ public function testApiCanRemoveVoteComment(): void
$voteManager->vote(1, $comment, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -189,50 +180,47 @@ public function testApiCanRemoveVoteComment(): void
public function testApiCannotFavouriteCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->request('PUT', "/api/comments/{$comment->getId()}/favourite");
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/favourite");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotFavouriteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanFavouriteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -245,7 +233,6 @@ public function testApiCanFavouriteComment(): void
public function testApiCannotUnfavouriteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -254,19 +241,18 @@ public function testApiCannotUnfavouriteCommentWithoutScope(): void
$favouriteManager->toggle($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnfavouriteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user);
@@ -275,15 +261,15 @@ public function testApiCanUnfavouriteComment(): void
$favouriteManager->toggle($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetAdultApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetAdultApiTest.php
index 87a52eb4d..32f605985 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetAdultApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetAdultApiTest.php
@@ -14,83 +14,83 @@ class EntryCommentSetAdultApiTest extends WebTestCase
{
public function testApiCannotSetCommentAdultAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true");
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSetCommentAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('user2');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotSetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -99,7 +99,6 @@ public function testApiCanSetCommentAdult(): void
public function testApiCannotUnsetCommentAdultAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
@@ -108,23 +107,24 @@ public function testApiCannotUnsetCommentAdultAnonymous(): void
$entityManager->persist($comment);
$entityManager->flush();
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false");
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnsetCommentAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('user2');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -133,19 +133,18 @@ public function testApiCannotUnsetCommentAdultWithoutScope(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotUnsetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
@@ -157,28 +156,29 @@ public function testApiNonModCannotUnsetCommentAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnsetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -189,15 +189,15 @@ public function testApiCanUnsetCommentAdult(): void
$commentRepository = $this->getService(EntryCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetLanguageApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetLanguageApiTest.php
index c2eeda5ed..21a441a9c 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetLanguageApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentSetLanguageApiTest.php
@@ -12,83 +12,83 @@ class EntryCommentSetLanguageApiTest extends WebTestCase
{
public function testApiCannotSetCommentLanguageAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de");
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSetCommentLanguageWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('user2');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotSetCommentLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetCommentLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentTrashApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentTrashApiTest.php
index ceaaa5e02..09d8403e5 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentTrashApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/Moderate/EntryCommentTrashApiTest.php
@@ -13,83 +13,83 @@ class EntryCommentTrashApiTest extends WebTestCase
{
public function testApiCannotTrashCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash");
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotTrashCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('user2');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotTrashComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanTrashComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -100,21 +100,19 @@ public function testApiCanTrashComment(): void
public function testApiCannotRestoreCommentAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$comment = $this->createEntryComment('test comment', $entry);
$entryCommentManager = $this->getService(EntryCommentManager::class);
$entryCommentManager->trash($this->getUserByUsername('user'), $comment);
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore");
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRestoreCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
@@ -124,19 +122,18 @@ public function testApiCannotRestoreCommentWithoutScope(): void
$entryCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotRestoreComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$entry = $this->getEntryByTitle('an entry', body: 'test');
@@ -146,43 +143,44 @@ public function testApiNonModCannotRestoreComment(): void
$entryCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRestoreComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$entry = $this->getEntryByTitle('an entry', body: 'test', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry, $user2);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entryCommentManager = $this->getService(EntryCommentManager::class);
$entryCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/Comment/UserEntryCommentRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/Comment/UserEntryCommentRetrieveApiTest.php
index 5611c3ea9..b063f6f3d 100644
--- a/tests/Functional/Controller/Api/Entry/Comment/UserEntryCommentRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Comment/UserEntryCommentRetrieveApiTest.php
@@ -13,16 +13,15 @@ class UserEntryCommentRetrieveApiTest extends WebTestCase
{
public function testApiCanGetUserEntryCommentsAnonymous(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
$comment = $this->createEntryComment('test comment', $entry);
$user = $entry->user;
- $client->request('GET', "/api/users/{$user->getId()}/comments");
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -48,7 +47,6 @@ public function testApiCanGetUserEntryCommentsAnonymous(): void
public function testApiCanGetUserEntryComments(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -56,14 +54,14 @@ public function testApiCanGetUserEntryComments(): void
$user = $entry->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -89,7 +87,6 @@ public function testApiCanGetUserEntryComments(): void
public function testApiCanGetUserEntryCommentsDepth(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -100,14 +97,14 @@ public function testApiCanGetUserEntryCommentsDepth(): void
$user = $entry->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -136,7 +133,6 @@ public function testApiCanGetUserEntryCommentsDepth(): void
public function testApiCanGetUserEntryCommentsNewest(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -154,14 +150,14 @@ public function testApiCanGetUserEntryCommentsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -187,7 +183,6 @@ public function testApiCanGetUserEntryCommentsNewest(): void
public function testApiCanGetUserEntryCommentsOldest(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -205,14 +200,14 @@ public function testApiCanGetUserEntryCommentsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -238,7 +233,6 @@ public function testApiCanGetUserEntryCommentsOldest(): void
public function testApiCanGetUserEntryCommentsActive(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -256,14 +250,14 @@ public function testApiCanGetUserEntryCommentsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -289,7 +283,6 @@ public function testApiCanGetUserEntryCommentsActive(): void
public function testApiCanGetUserEntryCommentsTop(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -302,14 +295,14 @@ public function testApiCanGetUserEntryCommentsTop(): void
$favouriteManager->toggle($this->getUserByUsername('voter1'), $second);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -338,7 +331,6 @@ public function testApiCanGetUserEntryCommentsTop(): void
public function testApiCanGetUserEntryCommentsHot(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('entry', url: 'https://google.com');
$first = $this->createEntryComment('first', $entry);
$second = $this->createEntryComment('second', $entry);
@@ -351,14 +343,14 @@ public function testApiCanGetUserEntryCommentsHot(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -387,7 +379,6 @@ public function testApiCanGetUserEntryCommentsHot(): void
public function testApiCanGetUserEntryCommentsWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
@@ -395,14 +386,14 @@ public function testApiCanGetUserEntryCommentsWithUserVoteStatus(): void
$user = $entry->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -423,9 +414,11 @@ public function testApiCanGetUserEntryCommentsWithUserVoteStatus(): void
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
self::assertIsArray($jsonData['items'][0]['user']);
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['childCount']);
self::assertIsArray($jsonData['items'][0]['children']);
self::assertEmpty($jsonData['items'][0]['children']);
diff --git a/tests/Functional/Controller/Api/Entry/DomainEntryRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/DomainEntryRetrieveApiTest.php
index 91da59d4d..aa9a9c393 100644
--- a/tests/Functional/Controller/Api/Entry/DomainEntryRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/DomainEntryRetrieveApiTest.php
@@ -12,15 +12,14 @@ class DomainEntryRetrieveApiTest extends WebTestCase
{
public function testApiCanGetDomainEntriesAnonymous(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
$domain = $entry->domain;
- $client->request('GET', "/api/domain/{$domain->getId()}/entries");
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -43,21 +42,20 @@ public function testApiCanGetDomainEntriesAnonymous(): void
public function testApiCanGetDomainEntries(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
$domain = $entry->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -80,7 +78,6 @@ public function testApiCanGetDomainEntries(): void
public function testApiCanGetDomainEntriesNewest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', url: 'https://google.com');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -97,14 +94,14 @@ public function testApiCanGetDomainEntriesNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -130,7 +127,6 @@ public function testApiCanGetDomainEntriesNewest(): void
public function testApiCanGetDomainEntriesOldest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', url: 'https://google.com');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -147,14 +143,14 @@ public function testApiCanGetDomainEntriesOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -180,7 +176,6 @@ public function testApiCanGetDomainEntriesOldest(): void
public function testApiCanGetDomainEntriesCommented(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', url: 'https://google.com');
$this->createEntryComment('comment 1', $first);
$this->createEntryComment('comment 2', $first);
@@ -190,14 +185,14 @@ public function testApiCanGetDomainEntriesCommented(): void
$domain = $first->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -226,7 +221,6 @@ public function testApiCanGetDomainEntriesCommented(): void
public function testApiCanGetDomainEntriesActive(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', url: 'https://google.com');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -243,14 +237,14 @@ public function testApiCanGetDomainEntriesActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -276,7 +270,6 @@ public function testApiCanGetDomainEntriesActive(): void
public function testApiCanGetDomainEntriesTop(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', url: 'https://google.com');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -288,14 +281,14 @@ public function testApiCanGetDomainEntriesTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -324,21 +317,20 @@ public function testApiCanGetDomainEntriesTop(): void
public function testApiCanGetDomainEntriesWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
$domain = $entry->domain;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/domain/{$domain->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/domain/{$domain->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -362,9 +354,11 @@ public function testApiCanGetDomainEntriesWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertEquals('https://google.com', $jsonData['items'][0]['url']);
self::assertNull($jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
self::assertSame(0, $jsonData['items'][0]['dv']);
diff --git a/tests/Functional/Controller/Api/Entry/EntryCreateApiTest.php b/tests/Functional/Controller/Api/Entry/EntryCreateApiTest.php
index 8965128d4..225524979 100644
--- a/tests/Functional/Controller/Api/Entry/EntryCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryCreateApiTest.php
@@ -11,7 +11,6 @@ class EntryCreateApiTest extends WebTestCase
{
public function testApiCannotCreateArticleEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'Anonymous Thread',
@@ -22,13 +21,12 @@ public function testApiCannotCreateArticleEntryAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreateArticleEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'No Scope Thread',
@@ -40,18 +38,17 @@ public function testApiCannotCreateArticleEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreateArticleEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
@@ -64,14 +61,14 @@ public function testApiCanCreateArticleEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -113,7 +110,6 @@ public function testApiCanCreateArticleEntry(): void
public function testApiCannotCreateLinkEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'Anonymous Thread',
@@ -125,13 +121,12 @@ public function testApiCannotCreateLinkEntryAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreateLinkEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'No Scope Thread',
@@ -144,18 +139,17 @@ public function testApiCannotCreateLinkEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreateLinkEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
@@ -169,14 +163,14 @@ public function testApiCanCreateLinkEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -192,7 +186,9 @@ public function testApiCanCreateLinkEntry(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['domain']);
self::assertEquals('https://google.com', $jsonData['url']);
self::assertEquals('This is a link', $jsonData['body']);
- self::assertNull($jsonData['image']);
+ if (null !== $jsonData['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['lang']);
self::assertIsArray($jsonData['tags']);
self::assertSame(['test'], $jsonData['tags']);
@@ -218,7 +214,6 @@ public function testApiCanCreateLinkEntry(): void
public function testApiCannotCreateImageEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'Anonymous Thread',
@@ -233,7 +228,7 @@ public function testApiCannotCreateImageEntryAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/image",
parameters: $entryRequest, files: ['uploadImage' => $image],
);
@@ -242,7 +237,6 @@ public function testApiCannotCreateImageEntryAnonymous(): void
public function testApiCannotCreateImageEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'No Scope Thread',
@@ -258,12 +252,12 @@ public function testApiCannotCreateImageEntryWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/image",
parameters: $entryRequest, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -273,7 +267,6 @@ public function testApiCannotCreateImageEntryWithoutScope(): void
public function testApiCanCreateImageEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
@@ -286,22 +279,22 @@ public function testApiCanCreateImageEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/image",
parameters: $entryRequest, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -346,7 +339,6 @@ public function testApiCanCreateImageEntry(): void
public function testApiCannotCreateEntryWithoutMagazine(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$invalidId = $magazine->getId() + 1;
$entryRequest = [
@@ -358,24 +350,23 @@ public function testApiCannotCreateEntryWithoutMagazine(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$invalidId}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$invalidId}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(404);
- $client->jsonRequest('POST', "/api/magazine/{$invalidId}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$invalidId}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(404);
- $client->request('POST', "/api/magazine/{$invalidId}/image", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/magazine/{$invalidId}/image", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(404);
}
public function testApiCannotCreateEntryWithoutUrlBodyOrImage(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entryRequest = [
'title' => 'No Url/Body Thread',
@@ -386,18 +377,18 @@ public function testApiCannotCreateEntryWithoutUrlBodyOrImage(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/article", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/link", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->request('POST', "/api/magazine/{$magazine->getId()}/image", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/magazine/{$magazine->getId()}/image", parameters: $entryRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
}
diff --git a/tests/Functional/Controller/Api/Entry/EntryDeleteApiTest.php b/tests/Functional/Controller/Api/Entry/EntryDeleteApiTest.php
index 78227fc9f..e4587f563 100644
--- a/tests/Functional/Controller/Api/Entry/EntryDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryDeleteApiTest.php
@@ -10,143 +10,133 @@ class EntryDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteArticleEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', magazine: $magazine);
- $client->request('DELETE', "/api/entry/{$entry->getId()}");
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteArticleEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersArticleEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteArticleEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotDeleteLinkEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com');
- $client->request('DELETE', "/api/entry/{$entry->getId()}");
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteLinkEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersLinkEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteLinkEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotDeleteImageEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
$entry = $this->getEntryByTitle('test image', image: $imageDto, magazine: $magazine);
- $client->request('DELETE', "/api/entry/{$entry->getId()}");
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteImageEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
@@ -154,18 +144,17 @@ public function testApiCannotDeleteImageEntryWithoutScope(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteOtherUsersImageEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -174,18 +163,17 @@ public function testApiCanDeleteOtherUsersImageEntry(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteImageEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -193,12 +181,12 @@ public function testApiCanDeleteImageEntry(): void
$entry = $this->getEntryByTitle('test image', image: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
}
diff --git a/tests/Functional/Controller/Api/Entry/EntryFavouriteApiTest.php b/tests/Functional/Controller/Api/Entry/EntryFavouriteApiTest.php
index 32e2084e7..a9c672e4b 100644
--- a/tests/Functional/Controller/Api/Entry/EntryFavouriteApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryFavouriteApiTest.php
@@ -10,47 +10,44 @@ class EntryFavouriteApiTest extends WebTestCase
{
public function testApiCannotFavouriteEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite");
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotFavouriteEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanFavouriteEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -68,7 +65,7 @@ public function testApiCanFavouriteEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/EntryReportApiTest.php b/tests/Functional/Controller/Api/Entry/EntryReportApiTest.php
index c06ead091..7b83320f4 100644
--- a/tests/Functional/Controller/Api/Entry/EntryReportApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryReportApiTest.php
@@ -12,7 +12,6 @@ class EntryReportApiTest extends WebTestCase
{
public function testApiCannotReportEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for report', magazine: $magazine);
@@ -20,13 +19,12 @@ public function testApiCannotReportEntryAnonymous(): void
'reason' => 'Test reporting',
];
- $client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest);
+ $this->client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotReportEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for report', user: $user, magazine: $magazine);
@@ -36,18 +34,17 @@ public function testApiCannotReportEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanReportEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$otherUser = $this->getUserByUsername('somebody');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -60,12 +57,12 @@ public function testApiCanReportEntry(): void
$magazineRepository = $this->getService(MagazineRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/entry/{$entry->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$magazine = $magazineRepository->find($magazine->getId());
diff --git a/tests/Functional/Controller/Api/Entry/EntryRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/EntryRetrieveApiTest.php
index f6fa5175b..b90d19f52 100644
--- a/tests/Functional/Controller/Api/Entry/EntryRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryRetrieveApiTest.php
@@ -14,43 +14,38 @@ class EntryRetrieveApiTest extends WebTestCase
{
public function testApiCannotGetSubscribedEntriesAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/entries/subscribed');
+ $this->client->request('GET', '/api/entries/subscribed');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetSubscribedEntriesWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'write');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'write');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetSubscribedEntries(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag', $user);
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -74,9 +69,11 @@ public function testApiCanGetSubscribedEntries(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertEquals('https://google.com', $jsonData['items'][0]['url']);
self::assertNull($jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
@@ -99,43 +96,38 @@ public function testApiCanGetSubscribedEntries(): void
public function testApiCannotGetModeratedEntriesAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/entries/moderated');
+ $this->client->request('GET', '/api/entries/moderated');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetModeratedEntriesWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetModeratedEntries(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag', $user);
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -159,9 +151,11 @@ public function testApiCanGetModeratedEntries(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertEquals('https://google.com', $jsonData['items'][0]['url']);
self::assertNull($jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
@@ -184,29 +178,24 @@ public function testApiCanGetModeratedEntries(): void
public function testApiCannotGetFavouritedEntriesAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/entries/favourited');
+ $this->client->request('GET', '/api/entries/favourited');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetFavouritedEntriesWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetFavouritedEntries(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('an entry', body: 'test');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -216,14 +205,14 @@ public function testApiCanGetFavouritedEntries(): void
$favouriteManager->toggle($user, $entry);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -246,9 +235,11 @@ public function testApiCanGetFavouritedEntries(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
@@ -271,7 +262,6 @@ public function testApiCanGetFavouritedEntries(): void
public function testApiCanGetEntriesAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -280,9 +270,9 @@ public function testApiCanGetEntriesAnonymous(): void
$entryManager = $this->getService(EntryManager::class);
$entryManager->pin($second, null);
- $client->request('GET', '/api/entries');
+ $this->client->request('GET', '/api/entries');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -305,9 +295,11 @@ public function testApiCanGetEntriesAnonymous(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
@@ -338,21 +330,20 @@ public function testApiCanGetEntriesAnonymous(): void
public function testApiCanGetEntries(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -375,9 +366,11 @@ public function testApiCanGetEntries(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
@@ -409,7 +402,6 @@ public function testApiCanGetEntries(): void
public function testApiCanGetEntriesWithLanguageAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -419,9 +411,9 @@ public function testApiCanGetEntriesWithLanguageAnonymous(): void
$entryManager = $this->getService(EntryManager::class);
$entryManager->pin($second, null);
- $client->request('GET', '/api/entries?lang[]=en&lang[]=de');
+ $this->client->request('GET', '/api/entries?lang[]=en&lang[]=de');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -444,9 +436,11 @@ public function testApiCanGetEntriesWithLanguageAnonymous(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
@@ -478,7 +472,6 @@ public function testApiCanGetEntriesWithLanguageAnonymous(): void
public function testApiCanGetEntriesWithLanguage(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -486,14 +479,14 @@ public function testApiCanGetEntriesWithLanguage(): void
$this->getEntryByTitle('a dutch entry', body: 'some body', magazine: $magazine, lang: 'nl');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?lang[]=en&lang[]=de', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?lang[]=en&lang[]=de', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -516,9 +509,11 @@ public function testApiCanGetEntriesWithLanguage(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
@@ -551,7 +546,6 @@ public function testApiCanGetEntriesWithLanguage(): void
public function testApiCannotGetEntriesByPreferredLangAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -560,13 +554,12 @@ public function testApiCannotGetEntriesByPreferredLangAnonymous(): void
$entryManager = $this->getService(EntryManager::class);
$entryManager->pin($second, null);
- $client->request('GET', '/api/entries?usePreferredLangs=true');
+ $this->client->request('GET', '/api/entries?usePreferredLangs=true');
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetEntriesByPreferredLang(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -580,14 +573,14 @@ public function testApiCanGetEntriesByPreferredLang(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?usePreferredLangs=true', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?usePreferredLangs=true', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -610,9 +603,11 @@ public function testApiCanGetEntriesByPreferredLang(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertIsArray($jsonData['items'][0]['badges']);
self::assertEmpty($jsonData['items'][0]['badges']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
@@ -645,7 +640,6 @@ public function testApiCanGetEntriesByPreferredLang(): void
public function testApiCanGetEntriesNewest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -661,14 +655,14 @@ public function testApiCanGetEntriesNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?sort=newest', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?sort=newest', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -694,7 +688,6 @@ public function testApiCanGetEntriesNewest(): void
public function testApiCanGetEntriesOldest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -710,14 +703,14 @@ public function testApiCanGetEntriesOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?sort=oldest', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?sort=oldest', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -743,7 +736,6 @@ public function testApiCanGetEntriesOldest(): void
public function testApiCanGetEntriesCommented(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$this->createEntryComment('comment 1', $first);
$this->createEntryComment('comment 2', $first);
@@ -752,14 +744,14 @@ public function testApiCanGetEntriesCommented(): void
$third = $this->getEntryByTitle('third', url: 'https://google.com');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?sort=commented', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?sort=commented', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -788,7 +780,6 @@ public function testApiCanGetEntriesCommented(): void
public function testApiCanGetEntriesActive(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -804,14 +795,14 @@ public function testApiCanGetEntriesActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?sort=active', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?sort=active', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -837,7 +828,6 @@ public function testApiCanGetEntriesActive(): void
public function testApiCanGetEntriesTop(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -848,14 +838,14 @@ public function testApiCanGetEntriesTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries?sort=top', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries?sort=top', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -884,21 +874,20 @@ public function testApiCanGetEntriesTop(): void
public function testApiCanGetEntriesWithUserVoteStatus(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/entries', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/entries', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -921,9 +910,11 @@ public function testApiCanGetEntriesWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertNull($jsonData['items'][0]['url']);
self::assertEquals('test', $jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(1, $jsonData['items'][0]['numComments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
self::assertSame(0, $jsonData['items'][0]['dv']);
@@ -952,12 +943,11 @@ public function testApiCanGetEntriesWithUserVoteStatus(): void
public function testApiCanGetEntryByIdAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
- $client->request('GET', "/api/entry/{$entry->getId()}");
+ $this->client->request('GET', "/api/entry/{$entry->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -973,7 +963,7 @@ public function testApiCanGetEntryByIdAnonymous(): void
self::assertEquals('test', $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -995,18 +985,17 @@ public function testApiCanGetEntryByIdAnonymous(): void
public function testApiCanGetEntryById(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -1022,7 +1011,7 @@ public function testApiCanGetEntryById(): void
self::assertEquals('test', $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertSame(0, $jsonData['numComments']);
self::assertSame(0, $jsonData['uv']);
self::assertSame(0, $jsonData['dv']);
@@ -1043,18 +1032,17 @@ public function testApiCanGetEntryById(): void
public function testApiCanGetEntryByIdWithUserVoteStatus(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/entry/{$entry->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -1070,7 +1058,7 @@ public function testApiCanGetEntryByIdWithUserVoteStatus(): void
self::assertEquals('test', $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertSame(0, $jsonData['numComments']);
self::assertSame(0, $jsonData['uv']);
self::assertSame(0, $jsonData['dv']);
diff --git a/tests/Functional/Controller/Api/Entry/EntryUpdateApiTest.php b/tests/Functional/Controller/Api/Entry/EntryUpdateApiTest.php
index dbead8060..f2d077bbb 100644
--- a/tests/Functional/Controller/Api/Entry/EntryUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryUpdateApiTest.php
@@ -10,7 +10,6 @@ class EntryUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateArticleEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for update', magazine: $magazine);
@@ -25,13 +24,12 @@ public function testApiCannotUpdateArticleEntryAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateArticleEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for update', user: $user, magazine: $magazine);
@@ -48,18 +46,17 @@ public function testApiCannotUpdateArticleEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersArticleEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -77,18 +74,17 @@ public function testApiCannotUpdateOtherUsersArticleEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateArticleEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for update', user: $user, magazine: $magazine);
@@ -105,14 +101,14 @@ public function testApiCanUpdateArticleEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -154,7 +150,6 @@ public function testApiCanUpdateArticleEntry(): void
public function testApiCannotUpdateLinkEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', magazine: $magazine);
@@ -169,13 +164,12 @@ public function testApiCannotUpdateLinkEntryAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}");
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateLinkEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
@@ -192,18 +186,17 @@ public function testApiCannotUpdateLinkEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersLinkEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -221,18 +214,17 @@ public function testApiCannotUpdateOtherUsersLinkEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateLinkEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test link', url: 'https://google.com', user: $user, magazine: $magazine);
@@ -249,14 +241,14 @@ public function testApiCanUpdateLinkEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -272,7 +264,9 @@ public function testApiCanUpdateLinkEntry(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['domain']);
self::assertEquals('https://google.com', $jsonData['url']);
self::assertEquals($updateRequest['body'], $jsonData['body']);
- self::assertNull($jsonData['image']);
+ if (null !== $jsonData['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals($updateRequest['lang'], $jsonData['lang']);
self::assertIsArray($jsonData['tags']);
self::assertSame($updateRequest['tags'], $jsonData['tags']);
@@ -298,7 +292,6 @@ public function testApiCanUpdateLinkEntry(): void
public function testApiCannotUpdateImageEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
@@ -315,13 +308,12 @@ public function testApiCannotUpdateImageEntryAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateImageEntryWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
@@ -340,18 +332,17 @@ public function testApiCannotUpdateImageEntryWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateOtherUsersImageEntry(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -371,18 +362,17 @@ public function testApiCanUpdateOtherUsersImageEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateImageEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -401,14 +391,14 @@ public function testApiCanUpdateImageEntry(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Entry/EntryVoteApiTest.php b/tests/Functional/Controller/Api/Entry/EntryVoteApiTest.php
index 4763a3530..252d96ffb 100644
--- a/tests/Functional/Controller/Api/Entry/EntryVoteApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/EntryVoteApiTest.php
@@ -11,47 +11,44 @@ class EntryVoteApiTest extends WebTestCase
{
public function testApiCannotUpvoteEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1");
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpvoteEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpvoteEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -69,7 +66,7 @@ public function testApiCanUpvoteEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -92,47 +89,44 @@ public function testApiCanUpvoteEntry(): void
public function testApiCannotDownvoteEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1");
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDownvoteEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDownvoteEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -150,7 +144,7 @@ public function testApiCanDownvoteEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -173,17 +167,15 @@ public function testApiCanDownvoteEntry(): void
public function testApiCannotClearVoteEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0");
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotClearVoteEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
@@ -192,18 +184,17 @@ public function testApiCannotClearVoteEntryWithoutScope(): void
$voteManager->vote(1, $entry, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanClearVoteEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for upvote', user: $user, magazine: $magazine);
@@ -212,14 +203,14 @@ public function testApiCanClearVoteEntry(): void
$voteManager->vote(1, $entry, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read entry:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read entry:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/entry/{$entry->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -237,7 +228,7 @@ public function testApiCanClearVoteEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/MagazineEntryRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/MagazineEntryRetrieveApiTest.php
index 2f7a3bfda..abe3c88c4 100644
--- a/tests/Functional/Controller/Api/Entry/MagazineEntryRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/MagazineEntryRetrieveApiTest.php
@@ -13,15 +13,14 @@ class MagazineEntryRetrieveApiTest extends WebTestCase
{
public function testApiCanGetMagazineEntriesAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries");
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -44,21 +43,20 @@ public function testApiCanGetMagazineEntriesAnonymous(): void
public function testApiCanGetMagazineEntries(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -81,7 +79,6 @@ public function testApiCanGetMagazineEntries(): void
public function testApiCanGetMagazineEntriesPinnedFirst(): void
{
- $client = self::createClient();
$voteManager = $this->getService(VoteManager::class);
$entryManager = $this->getService(EntryManager::class);
$voter = $this->getUserByUsername('voter');
@@ -96,14 +93,14 @@ public function testApiCanGetMagazineEntriesPinnedFirst(): void
$entryManager->pin($third, null);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -139,7 +136,6 @@ public function testApiCanGetMagazineEntriesPinnedFirst(): void
public function testApiCanGetMagazineEntriesNewest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -156,14 +152,14 @@ public function testApiCanGetMagazineEntriesNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -189,7 +185,6 @@ public function testApiCanGetMagazineEntriesNewest(): void
public function testApiCanGetMagazineEntriesOldest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -206,14 +201,14 @@ public function testApiCanGetMagazineEntriesOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -239,7 +234,6 @@ public function testApiCanGetMagazineEntriesOldest(): void
public function testApiCanGetMagazineEntriesCommented(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$this->createEntryComment('comment 1', $first);
$this->createEntryComment('comment 2', $first);
@@ -249,14 +243,14 @@ public function testApiCanGetMagazineEntriesCommented(): void
$magazine = $first->magazine;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -285,7 +279,6 @@ public function testApiCanGetMagazineEntriesCommented(): void
public function testApiCanGetMagazineEntriesActive(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -302,14 +295,14 @@ public function testApiCanGetMagazineEntriesActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -335,7 +328,6 @@ public function testApiCanGetMagazineEntriesActive(): void
public function testApiCanGetMagazineEntriesTop(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -347,14 +339,14 @@ public function testApiCanGetMagazineEntriesTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -383,21 +375,20 @@ public function testApiCanGetMagazineEntriesTop(): void
public function testApiCanGetMagazineEntriesWithUserVoteStatus(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $first);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -421,9 +412,11 @@ public function testApiCanGetMagazineEntriesWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertEquals('https://google.com', $jsonData['items'][0]['url']);
self::assertNull($jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
self::assertSame(0, $jsonData['items'][0]['dv']);
diff --git a/tests/Functional/Controller/Api/Entry/Moderate/EntryPinApiTest.php b/tests/Functional/Controller/Api/Entry/Moderate/EntryPinApiTest.php
index 6e99a2d01..33f1760b2 100644
--- a/tests/Functional/Controller/Api/Entry/Moderate/EntryPinApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Moderate/EntryPinApiTest.php
@@ -11,64 +11,60 @@ class EntryPinApiTest extends WebTestCase
{
public function testApiCannotPinEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotPinEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotPinEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPinEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -86,7 +82,7 @@ public function testApiCanPinEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -109,20 +105,18 @@ public function testApiCanPinEntry(): void
public function testApiCannotUnpinEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
$entryManager = $this->getService(EntryManager::class);
$entryManager->pin($entry, null);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotUnpinEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -131,18 +125,17 @@ public function testApiNonModeratorCannotUnpinEntry(): void
$entryManager->pin($entry, null);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUnpinEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -151,18 +144,17 @@ public function testApiCannotUnpinEntryWithoutScope(): void
$entryManager->pin($entry, null);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnpinEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -171,14 +163,14 @@ public function testApiCanUnpinEntry(): void
$entryManager->pin($entry, null);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -196,7 +188,7 @@ public function testApiCanUnpinEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/Moderate/EntrySetAdultApiTest.php b/tests/Functional/Controller/Api/Entry/Moderate/EntrySetAdultApiTest.php
index b11da5344..18ec1f5ee 100644
--- a/tests/Functional/Controller/Api/Entry/Moderate/EntrySetAdultApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Moderate/EntrySetAdultApiTest.php
@@ -13,69 +13,67 @@ class EntrySetAdultApiTest extends WebTestCase
{
public function testApiCannotSetEntryAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetEntryAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetEntryAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetEntryAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -93,7 +91,7 @@ public function testApiCanSetEntryAdult(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -117,7 +115,6 @@ public function testApiCanSetEntryAdult(): void
public function testApiCannotSetEntryNotAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
@@ -126,13 +123,12 @@ public function testApiCannotSetEntryNotAdultAnonymous(): void
$entityManager->persist($entry);
$entityManager->flush();
- $client->request('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false");
+ $this->client->request('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetEntryNotAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -143,18 +139,17 @@ public function testApiNonModeratorCannotSetEntryNotAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetEntryNotAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -165,25 +160,26 @@ public function testApiCannotSetEntryNotAdultWithoutScope(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetEntryNotAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -192,14 +188,14 @@ public function testApiCanSetEntryNotAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -217,7 +213,7 @@ public function testApiCanSetEntryNotAdult(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/Moderate/EntrySetLanguageApiTest.php b/tests/Functional/Controller/Api/Entry/Moderate/EntrySetLanguageApiTest.php
index 23d732834..d2165501c 100644
--- a/tests/Functional/Controller/Api/Entry/Moderate/EntrySetLanguageApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Moderate/EntrySetLanguageApiTest.php
@@ -12,100 +12,99 @@ class EntrySetLanguageApiTest extends WebTestCase
{
public function testApiCannotSetEntryLanguageAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetEntryLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetEntryLanguageWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetEntryLanguageInvalid(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/fake", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/fake", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/ac", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/ac", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/aaa", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/aaa", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/a", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/a", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
public function testApiCanSetEntryLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -123,7 +122,7 @@ public function testApiCanSetEntryLanguage(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('de', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -147,25 +146,26 @@ public function testApiCanSetEntryLanguage(): void
public function testApiCanSetEntryLanguage3Letter(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/elx", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/elx", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -183,7 +183,7 @@ public function testApiCanSetEntryLanguage3Letter(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('elx', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/Moderate/EntryTrashApiTest.php b/tests/Functional/Controller/Api/Entry/Moderate/EntryTrashApiTest.php
index 9a69c5621..18453210d 100644
--- a/tests/Functional/Controller/Api/Entry/Moderate/EntryTrashApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/Moderate/EntryTrashApiTest.php
@@ -13,69 +13,67 @@ class EntryTrashApiTest extends WebTestCase
{
public function testApiCannotTrashEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotTrashEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotTrashEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanTrashEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -93,7 +91,7 @@ public function testApiCanTrashEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
@@ -117,7 +115,6 @@ public function testApiCanTrashEntry(): void
public function testApiCannotRestoreEntryAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', magazine: $magazine);
@@ -125,13 +122,12 @@ public function testApiCannotRestoreEntryAnonymous(): void
$entryManager = $this->getService(EntryManager::class);
$entryManager->trash($user, $entry);
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore");
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotRestoreEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -140,18 +136,17 @@ public function testApiNonModeratorCannotRestoreEntry(): void
$entryManager->trash($user, $entry);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRestoreEntryWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
@@ -160,39 +155,40 @@ public function testApiCannotRestoreEntryWithoutScope(): void
$entryManager->trash($user, $entry);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRestoreEntry(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$entry = $this->getEntryByTitle('test article', body: 'test for favourite', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entryManager = $this->getService(EntryManager::class);
$entryManager->trash($user, $entry);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:entry:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:entry:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/entry/{$entry->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData);
@@ -210,7 +206,7 @@ public function testApiCanRestoreEntry(): void
self::assertEquals($entry->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($entry->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertIsArray($jsonData['badges']);
self::assertEmpty($jsonData['badges']);
self::assertSame(0, $jsonData['numComments']);
diff --git a/tests/Functional/Controller/Api/Entry/UserEntryRetrieveApiTest.php b/tests/Functional/Controller/Api/Entry/UserEntryRetrieveApiTest.php
index 47d117430..c78f01c77 100644
--- a/tests/Functional/Controller/Api/Entry/UserEntryRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Entry/UserEntryRetrieveApiTest.php
@@ -12,16 +12,15 @@ class UserEntryRetrieveApiTest extends WebTestCase
{
public function testApiCanGetUserEntriesAnonymous(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$otherUser = $this->getUserByUsername('somebody');
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine, user: $otherUser);
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries");
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -47,7 +46,6 @@ public function testApiCanGetUserEntriesAnonymous(): void
public function testApiCanGetUserEntries(): void
{
- $client = self::createClient();
$entry = $this->getEntryByTitle('an entry', body: 'test');
$this->createEntryComment('up the ranking', $entry);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -55,14 +53,14 @@ public function testApiCanGetUserEntries(): void
$this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine, user: $otherUser);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -88,7 +86,6 @@ public function testApiCanGetUserEntries(): void
public function testApiCanGetUserEntriesNewest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -105,14 +102,14 @@ public function testApiCanGetUserEntriesNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -138,7 +135,6 @@ public function testApiCanGetUserEntriesNewest(): void
public function testApiCanGetUserEntriesOldest(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -155,14 +151,14 @@ public function testApiCanGetUserEntriesOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -188,7 +184,6 @@ public function testApiCanGetUserEntriesOldest(): void
public function testApiCanGetUserEntriesCommented(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$this->createEntryComment('comment 1', $first);
$this->createEntryComment('comment 2', $first);
@@ -198,14 +193,14 @@ public function testApiCanGetUserEntriesCommented(): void
$otherUser = $first->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -234,7 +229,6 @@ public function testApiCanGetUserEntriesCommented(): void
public function testApiCanGetUserEntriesActive(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -251,14 +245,14 @@ public function testApiCanGetUserEntriesActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -284,7 +278,6 @@ public function testApiCanGetUserEntriesActive(): void
public function testApiCanGetUserEntriesTop(): void
{
- $client = self::createClient();
$first = $this->getEntryByTitle('first', body: 'test');
$second = $this->getEntryByTitle('second', url: 'https://google.com');
$third = $this->getEntryByTitle('third', url: 'https://google.com');
@@ -296,14 +289,14 @@ public function testApiCanGetUserEntriesTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -332,21 +325,20 @@ public function testApiCanGetUserEntriesTop(): void
public function testApiCanGetUserEntriesWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->getEntryByTitle('an entry', body: 'test');
$otherUser = $this->getUserByUsername('somebody');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$entry = $this->getEntryByTitle('another entry', url: 'https://google.com', magazine: $magazine, user: $otherUser);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/entries", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -371,9 +363,11 @@ public function testApiCanGetUserEntriesWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::DOMAIN_RESPONSE_KEYS, $jsonData['items'][0]['domain']);
self::assertEquals('https://google.com', $jsonData['items'][0]['url']);
self::assertNull($jsonData['items'][0]['body']);
- self::assertNull($jsonData['items'][0]['image']);
+ if (null !== $jsonData['items'][0]['image']) {
+ self::assertStringContainsString('google.com', parse_url($jsonData['items'][0]['image']['sourceUrl'], PHP_URL_HOST));
+ }
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['numComments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
self::assertSame(0, $jsonData['items'][0]['dv']);
diff --git a/tests/Functional/Controller/Api/Instance/Admin/InstanceFederationUpdateApiTest.php b/tests/Functional/Controller/Api/Instance/Admin/InstanceFederationUpdateApiTest.php
index ec720dc09..ed01f73fb 100644
--- a/tests/Functional/Controller/Api/Instance/Admin/InstanceFederationUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/Admin/InstanceFederationUpdateApiTest.php
@@ -11,60 +11,52 @@ class InstanceFederationUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateInstanceFederationAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/defederated');
+ $this->client->request('PUT', '/api/defederated');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceFederationWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceFederationWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceFederation(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:federation:update');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:federation:update');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/defederated', ['instances' => ['bad-instance.com']], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/defederated', ['instances' => ['bad-instance.com']], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(['instances'], $jsonData);
self::assertSame(['bad-instance.com'], $jsonData['instances']);
@@ -72,22 +64,20 @@ public function testApiCanUpdateInstanceFederation(): void
public function testApiCanClearInstanceFederation(): void
{
- $client = self::createClient();
-
$manager = $this->getService(SettingsManager::class);
$manager->set('KBIN_BANNED_INSTANCES', ['defederated.social', 'evil.social']);
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:federation:update');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:federation:update');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/defederated', ['instances' => []], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/defederated', ['instances' => []], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(['instances'], $jsonData);
self::assertEmpty($jsonData['instances']);
diff --git a/tests/Functional/Controller/Api/Instance/Admin/InstancePagesUpdateApiTest.php b/tests/Functional/Controller/Api/Instance/Admin/InstancePagesUpdateApiTest.php
index e8dd8f620..5b3d31f3a 100644
--- a/tests/Functional/Controller/Api/Instance/Admin/InstancePagesUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/Admin/InstancePagesUpdateApiTest.php
@@ -11,60 +11,52 @@ class InstancePagesUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateInstanceAboutPageAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/about');
+ $this->client->request('PUT', '/api/instance/about');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceAboutPageWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/about', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/about', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceAboutPageWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/about', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/about', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceAboutPage(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:information:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:information:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/instance/about', ['body' => 'about page'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/about', ['body' => 'about page'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(InstanceDetailsApiTest::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals('about page', $jsonData['about']);
@@ -72,60 +64,52 @@ public function testApiCanUpdateInstanceAboutPage(): void
public function testApiCannotUpdateInstanceContactPageAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/contact');
+ $this->client->request('PUT', '/api/instance/contact');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceContactPageWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/contact', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/contact', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceContactPageWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/contact', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/contact', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceContactPage(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:information:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:information:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/instance/contact', ['body' => 'contact page'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/contact', ['body' => 'contact page'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(InstanceDetailsApiTest::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals('contact page', $jsonData['contact']);
@@ -133,60 +117,52 @@ public function testApiCanUpdateInstanceContactPage(): void
public function testApiCannotUpdateInstanceFAQPageAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/faq');
+ $this->client->request('PUT', '/api/instance/faq');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceFAQPageWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/faq', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/faq', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceFAQPageWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/faq', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/faq', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceFAQPage(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:information:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:information:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/instance/faq', ['body' => 'faq page'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/faq', ['body' => 'faq page'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(InstanceDetailsApiTest::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals('faq page', $jsonData['faq']);
@@ -194,60 +170,52 @@ public function testApiCanUpdateInstanceFAQPage(): void
public function testApiCannotUpdateInstancePrivacyPolicyPageAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/privacyPolicy');
+ $this->client->request('PUT', '/api/instance/privacyPolicy');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstancePrivacyPolicyPageWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/privacyPolicy', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/privacyPolicy', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstancePrivacyPolicyPageWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/privacyPolicy', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/privacyPolicy', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstancePrivacyPolicyPage(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:information:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:information:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/instance/privacyPolicy', ['body' => 'privacyPolicy page'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/privacyPolicy', ['body' => 'privacyPolicy page'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(InstanceDetailsApiTest::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals('privacyPolicy page', $jsonData['privacyPolicy']);
@@ -255,60 +223,52 @@ public function testApiCanUpdateInstancePrivacyPolicyPage(): void
public function testApiCannotUpdateInstanceTermsPageAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/terms');
+ $this->client->request('PUT', '/api/instance/terms');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceTermsPageWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/terms', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/terms', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceTermsPageWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/terms', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/terms', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceTermsPage(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:information:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:information:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', '/api/instance/terms', ['body' => 'terms page'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/terms', ['body' => 'terms page'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(InstanceDetailsApiTest::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals('terms page', $jsonData['terms']);
diff --git a/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsRetrieveApiTest.php b/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsRetrieveApiTest.php
index cf8c44987..8a0dd605b 100644
--- a/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsRetrieveApiTest.php
@@ -33,64 +33,59 @@ class InstanceSettingsRetrieveApiTest extends WebTestCase
'MBIN_SSO_REGISTRATIONS_ENABLED',
'MBIN_RESTRICT_MAGAZINE_CREATION',
'MBIN_DOWNVOTES_MODE',
+ 'MBIN_SSO_ONLY_MODE',
+ 'MBIN_SSO_SHOW_FIRST',
+ 'MAX_IMAGE_BYTES',
];
public function testApiCannotRetrieveInstanceSettingsAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/instance/settings');
+ $this->client->request('GET', '/api/instance/settings');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveInstanceSettingsWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveInstanceSettingsWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveInstanceSettings(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:settings:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:settings:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_SETTINGS_RESPONSE_KEYS, $jsonData);
foreach ($jsonData as $key => $value) {
diff --git a/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsUpdateApiTest.php b/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsUpdateApiTest.php
index 8e8552051..f421e9f18 100644
--- a/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/Admin/InstanceSettingsUpdateApiTest.php
@@ -34,58 +34,53 @@ class InstanceSettingsUpdateApiTest extends WebTestCase
'MBIN_SSO_REGISTRATIONS_ENABLED',
'MBIN_RESTRICT_MAGAZINE_CREATION',
'MBIN_DOWNVOTES_MODE',
+ 'MBIN_SSO_ONLY_MODE',
+ 'MBIN_SSO_SHOW_FIRST',
+ 'MAX_IMAGE_BYTES',
];
public function testApiCannotUpdateInstanceSettingsAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('PUT', '/api/instance/settings');
+ $this->client->request('PUT', '/api/instance/settings');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateInstanceSettingsWithoutAdmin(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateInstanceSettingsWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/instance/settings', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateInstanceSettings(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe', isAdmin: true);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:instance:settings:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:instance:settings:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
$settings = [
@@ -112,13 +107,16 @@ public function testApiCanUpdateInstanceSettings(): void
'MBIN_SIDEBAR_SECTIONS_LOCAL_ONLY' => false,
'MBIN_SSO_REGISTRATIONS_ENABLED' => true,
'MBIN_RESTRICT_MAGAZINE_CREATION' => false,
- 'MBIN_DOWNVOTES_MODE' => DownvotesMode::Enabled,
+ 'MBIN_DOWNVOTES_MODE' => DownvotesMode::Enabled->value,
+ 'MBIN_SSO_ONLY_MODE' => false,
+ 'MBIN_SSO_SHOW_FIRST' => false,
+ 'MAX_IMAGE_BYTES' => 10000,
];
- $client->jsonRequest('PUT', '/api/instance/settings', $settings, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/settings', $settings, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_SETTINGS_RESPONSE_KEYS, $jsonData);
foreach ($jsonData as $key => $value) {
@@ -149,11 +147,60 @@ public function testApiCanUpdateInstanceSettings(): void
'MBIN_SIDEBAR_SECTIONS_LOCAL_ONLY' => true,
'MBIN_SSO_REGISTRATIONS_ENABLED' => false,
'MBIN_RESTRICT_MAGAZINE_CREATION' => true,
- 'MBIN_DOWNVOTES_MODE' => DownvotesMode::Hidden,
+ 'MBIN_DOWNVOTES_MODE' => DownvotesMode::Hidden->value,
+ 'MBIN_SSO_ONLY_MODE' => true,
+ 'MBIN_SSO_SHOW_FIRST' => true,
+ 'MAX_IMAGE_BYTES' => 30000,
+ ];
+
+ $this->client->jsonRequest('PUT', '/api/instance/settings', $settings, server: ['HTTP_AUTHORIZATION' => $token]);
+
+ self::assertResponseIsSuccessful();
+ $jsonData = self::getJsonResponse($this->client);
+
+ self::assertArrayKeysMatch(self::INSTANCE_SETTINGS_RESPONSE_KEYS, $jsonData);
+ foreach ($jsonData as $key => $value) {
+ self::assertEquals($settings[$key], $value, "$key did not match!");
+ }
+
+ $settings = [
+ 'KBIN_DOMAIN' => 'kbin.test',
+ 'KBIN_TITLE' => 'updated title',
+ 'KBIN_META_TITLE' => 'meta title',
+ 'KBIN_META_KEYWORDS' => 'this, is, a, test',
+ 'KBIN_META_DESCRIPTION' => 'Testing out the API',
+ 'KBIN_DEFAULT_LANG' => 'de',
+ 'KBIN_CONTACT_EMAIL' => 'test@kbinupdated.test',
+ 'KBIN_SENDER_EMAIL' => 'noreply@kbinupdated.test',
+ 'MBIN_DEFAULT_THEME' => 'dark',
+ 'KBIN_JS_ENABLED' => true,
+ 'KBIN_FEDERATION_ENABLED' => true,
+ 'KBIN_REGISTRATIONS_ENABLED' => true,
+ 'KBIN_BANNED_INSTANCES' => [],
+ 'KBIN_HEADER_LOGO' => true,
+ 'KBIN_CAPTCHA_ENABLED' => false,
+ 'KBIN_MERCURE_ENABLED' => false,
+ 'KBIN_FEDERATION_PAGE_ENABLED' => false,
+ 'KBIN_ADMIN_ONLY_OAUTH_CLIENTS' => false,
+ 'MBIN_PRIVATE_INSTANCE' => false,
+ 'KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN' => false,
+ 'MBIN_SIDEBAR_SECTIONS_LOCAL_ONLY' => false,
+ 'MBIN_SSO_REGISTRATIONS_ENABLED' => true,
+ 'MBIN_RESTRICT_MAGAZINE_CREATION' => false,
+ 'MBIN_DOWNVOTES_MODE' => DownvotesMode::Enabled->value,
+ 'MBIN_SSO_ONLY_MODE' => false,
+ 'MBIN_SSO_SHOW_FIRST' => false,
+ 'MAX_IMAGE_BYTES' => 10000,
];
- $client->jsonRequest('PUT', '/api/instance/settings', $settings, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', '/api/instance/settings', $settings, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
+ $jsonData = self::getJsonResponse($this->client);
+
+ self::assertArrayKeysMatch(self::INSTANCE_SETTINGS_RESPONSE_KEYS, $jsonData);
+ foreach ($jsonData as $key => $value) {
+ self::assertEquals($settings[$key], $value, "$key did not match!");
+ }
}
}
diff --git a/tests/Functional/Controller/Api/Instance/InstanceDetailsApiTest.php b/tests/Functional/Controller/Api/Instance/InstanceDetailsApiTest.php
index 0e771c505..14593cc45 100644
--- a/tests/Functional/Controller/Api/Instance/InstanceDetailsApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/InstanceDetailsApiTest.php
@@ -12,13 +12,12 @@ class InstanceDetailsApiTest extends WebTestCase
public function testApiCanRetrieveInstanceDetailsAnonymous(): void
{
- $client = self::createClient();
$site = $this->createInstancePages();
- $client->request('GET', '/api/instance');
+ $this->client->request('GET', '/api/instance');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals($site->about, $jsonData['about']);
@@ -30,20 +29,19 @@ public function testApiCanRetrieveInstanceDetailsAnonymous(): void
public function testApiCanRetrieveInstanceDetails(): void
{
- $client = self::createClient();
$site = $this->createInstancePages();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/instance', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/instance', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_PAGE_RESPONSE_KEYS, $jsonData);
self::assertEquals($site->about, $jsonData['about']);
diff --git a/tests/Functional/Controller/Api/Instance/InstanceFederationApiTest.php b/tests/Functional/Controller/Api/Instance/InstanceFederationApiTest.php
index 191b054f2..cd25a4776 100644
--- a/tests/Functional/Controller/Api/Instance/InstanceFederationApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/InstanceFederationApiTest.php
@@ -13,21 +13,20 @@ class InstanceFederationApiTest extends WebTestCase
public function testApiCanRetrieveEmptyInstanceDefederation(): void
{
- $client = self::createClient();
$settings = $this->getService(SettingsManager::class);
$settings->set('KBIN_BANNED_INSTANCES', []);
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_DEFEDERATED_RESPONSE_KEYS, $jsonData);
self::assertSame([], $jsonData['instances']);
@@ -35,14 +34,13 @@ public function testApiCanRetrieveEmptyInstanceDefederation(): void
public function testApiCanRetrieveInstanceDefederationAnonymous(): void
{
- $client = self::createClient();
$settings = $this->getService(SettingsManager::class);
$settings->set('KBIN_BANNED_INSTANCES', ['defederated.social']);
- $client->request('GET', '/api/defederated');
+ $this->client->request('GET', '/api/defederated');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_DEFEDERATED_RESPONSE_KEYS, $jsonData);
self::assertSame(['defederated.social'], $jsonData['instances']);
@@ -50,21 +48,20 @@ public function testApiCanRetrieveInstanceDefederationAnonymous(): void
public function testApiCanRetrieveInstanceDefederation(): void
{
- $client = self::createClient();
$settings = $this->getService(SettingsManager::class);
$settings->set('KBIN_BANNED_INSTANCES', ['defederated.social', 'evil.social']);
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/defederated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::INSTANCE_DEFEDERATED_RESPONSE_KEYS, $jsonData);
self::assertSame(['defederated.social', 'evil.social'], $jsonData['instances']);
diff --git a/tests/Functional/Controller/Api/Instance/InstanceModlogApiTest.php b/tests/Functional/Controller/Api/Instance/InstanceModlogApiTest.php
index 74ebad09a..08813eb59 100644
--- a/tests/Functional/Controller/Api/Instance/InstanceModlogApiTest.php
+++ b/tests/Functional/Controller/Api/Instance/InstanceModlogApiTest.php
@@ -10,13 +10,12 @@ class InstanceModlogApiTest extends WebTestCase
{
public function testApiCanRetrieveModlogAnonymous(): void
{
- $client = self::createClient();
$this->createModlogMessages();
- $client->request('GET', '/api/modlog');
+ $this->client->request('GET', '/api/modlog');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -34,20 +33,19 @@ public function testApiCanRetrieveModlogAnonymous(): void
public function testApiCanRetrieveModlog(): void
{
- $client = self::createClient();
$this->createModlogMessages();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/modlog', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/modlog', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineBadgesApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineBadgesApiTest.php
index b633172ca..02982f774 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineBadgesApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineBadgesApiTest.php
@@ -17,122 +17,119 @@ class MagazineBadgesApiTest extends WebTestCase
public function testApiCannotAddBadgesToMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test']);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test']);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRemoveBadgesFromMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$badgeManager = $this->getService(BadgeManager::class);
$badge = $badgeManager->create(BadgeDto::create($magazine, 'test'));
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotAddBadgesToMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRemoveBadgesFromMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$badgeManager = $this->getService(BadgeManager::class);
$badge = $badgeManager->create(BadgeDto::create($magazine, 'test'));
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotAddBadgesMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:badges');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:badges');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotRemoveBadgesMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
$badgeManager = $this->getService(BadgeManager::class);
$badge = $badgeManager->create(BadgeDto::create($magazine, 'test'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:badges');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:badges');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiOwnerCanAddBadgesMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:badges');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:badges');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/badge", parameters: ['name' => 'test'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -144,22 +141,21 @@ public function testApiOwnerCanAddBadgesMagazine(): void
public function testApiOwnerCanRemoveBadgesMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$badgeManager = $this->getService(BadgeManager::class);
$badge = $badgeManager->create(BadgeDto::create($magazine, 'test'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:badges');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:badges');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/badge/{$badge->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineCreateApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineCreateApiTest.php
index 123eaa976..2971dd435 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineCreateApiTest.php
@@ -11,34 +11,31 @@ class MagazineCreateApiTest extends WebTestCase
{
public function testApiCannotCreateMagazineAnonymous(): void
{
- $client = self::createClient();
- $client->request('POST', '/api/moderate/magazine/new');
+ $this->client->request('POST', '/api/moderate/magazine/new');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreateMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', '/api/moderate/magazine/new', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', '/api/moderate/magazine/new', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreateMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:create');
$token = $codes['token_type'].' '.$codes['access_token'];
$name = 'test';
@@ -46,7 +43,7 @@ public function testApiCanCreateMagazine(): void
$description = 'A description';
$rules = 'Some rules';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -59,7 +56,7 @@ public function testApiCanCreateMagazine(): void
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -72,19 +69,18 @@ public function testApiCanCreateMagazine(): void
public function testApiCannotCreateInvalidMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:create');
$token = $codes['token_type'].' '.$codes['access_token'];
$title = 'No name';
$description = 'A description';
$rules = 'Some rules';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => null,
@@ -101,7 +97,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'a';
$title = 'Too short name';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -117,7 +113,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'long_name_that_exceeds_the_limit';
$title = 'Too long name';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -133,7 +129,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'invalidch@racters!';
$title = 'Invalid Characters in name';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -149,7 +145,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'nulltitle';
$title = null;
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -165,7 +161,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'shorttitle';
$title = 'as';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -181,7 +177,7 @@ public function testApiCannotCreateInvalidMagazine(): void
$name = 'longtitle';
$title = 'Way too long of a title. This can only be 50 characters!';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', '/api/moderate/magazine/new',
parameters: [
'name' => $name,
@@ -194,37 +190,5 @@ public function testApiCannotCreateInvalidMagazine(): void
);
self::assertResponseStatusCodeSame(400);
-
- $name = 'shortrules';
- $title = 'This has too short rules';
- $client->jsonRequest(
- 'POST', '/api/moderate/magazine/new',
- parameters: [
- 'name' => $name,
- 'title' => $title,
- 'description' => $description,
- 'rules' => 'ru',
- 'isAdult' => false,
- ],
- server: ['HTTP_AUTHORIZATION' => $token]
- );
-
- self::assertResponseStatusCodeSame(400);
-
- $name = 'shortdescription';
- $title = 'This has too short of a description';
- $client->jsonRequest(
- 'POST', '/api/moderate/magazine/new',
- parameters: [
- 'name' => $name,
- 'title' => $title,
- 'description' => 'de',
- 'rules' => $rules,
- 'isAdult' => false,
- ],
- server: ['HTTP_AUTHORIZATION' => $token]
- );
-
- self::assertResponseStatusCodeSame(400);
}
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteApiTest.php
index f9b42d9d1..1941f5289 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteApiTest.php
@@ -12,82 +12,79 @@ class MagazineDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiUserCannotDeleteUnownedMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotDeleteUnownedMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteIconApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteIconApiTest.php
index 01596b8a5..3e225ab84 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteIconApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineDeleteIconApiTest.php
@@ -22,56 +22,54 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testApiCannotDeleteMagazineIconAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteMagazineIconWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotDeleteMagazineIcon(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteMagazineIcon(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -88,13 +86,13 @@ public function testApiCanDeleteMagazineIcon(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:theme');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:theme');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
self::assertIsArray($jsonData['icon']);
self::assertArrayKeysMatch(self::IMAGE_KEYS, $jsonData['icon']);
@@ -102,10 +100,10 @@ public function testApiCanDeleteMagazineIcon(): void
self::assertSame(96, $jsonData['icon']['height']);
self::assertEquals('a8/1c/a81cc2fea35eeb232cd28fcb109b3eb5a4e52c71bce95af6650d71876c1bcbb7.png', $jsonData['icon']['filePath']);
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/icon", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineUpdateThemeApiTest::MAGAZINE_THEME_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineModeratorsApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineModeratorsApiTest.php
index ad2dd4625..1657eda07 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineModeratorsApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineModeratorsApiTest.php
@@ -13,73 +13,72 @@ class MagazineModeratorsApiTest extends WebTestCase
{
public function testApiCannotAddModeratorsToMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('notamod');
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRemoveModeratorsFromMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('yesamod');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $user;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotAddModeratorsToMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('notamod');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRemoveModeratorsFromMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('yesamod');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $user;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotAddModeratorsMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
$user = $this->getUserByUsername('notamod');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -87,22 +86,22 @@ public function testApiModCannotAddModeratorsMagazine(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:moderators');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:moderators');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotRemoveModeratorsMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
$user = $this->getUserByUsername('yesamod');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -110,36 +109,37 @@ public function testApiModCannotRemoveModeratorsMagazine(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
$dto = new ModeratorDto($magazine);
$dto->user = $user;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:moderators');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:moderators');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiOwnerCanAddModeratorsMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
$moderator = $this->getUserByUsername('willbeamod');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:moderators');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:moderators');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$moderator->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/mod/{$moderator->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -151,25 +151,26 @@ public function testApiOwnerCanAddModeratorsMagazine(): void
public function testApiOwnerCanRemoveModeratorsMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$moderator = $this->getUserByUsername('yesamod');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $admin;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:moderators');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:moderators');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -178,10 +179,10 @@ public function testApiOwnerCanRemoveModeratorsMagazine(): void
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MODERATOR_RESPONSE_KEYS, $jsonData['moderators'][1]);
self::assertSame($moderator->getId(), $jsonData['moderators'][1]['userId']);
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$moderator->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/mod/{$moderator->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazinePurgeApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazinePurgeApiTest.php
index c20338636..9b02accdd 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazinePurgeApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazinePurgeApiTest.php
@@ -12,52 +12,48 @@ class MagazinePurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminUserCannotPurgeMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write admin:magazine:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write admin:magazine:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotPurgeMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -65,47 +61,46 @@ public function testApiModCannotPurgeMagazine(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write admin:magazine:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write admin:magazine:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiOwnerCannotPurgeMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write admin:magazine:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write admin:magazine:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiAdminCanPurgeMagazine(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('JohnDoe', isAdmin: true);
$owner = $this->getUserByUsername('JaneDoe');
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $owner);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write admin:magazine:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write admin:magazine:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/magazine/{$magazine->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApiTest.php
index bf34d47d1..090b0f46f 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineRetrieveStatsApiTest.php
@@ -25,63 +25,61 @@ class MagazineRetrieveStatsApiTest extends WebTestCase
public function testApiCannotRetrieveMagazineStatsAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes");
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes");
self::assertResponseStatusCodeSame(401);
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content");
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineStatsWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveMagazineStatsIfNotOwner(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
+ $owner = $this->getUserByUsername('JaneDoe');
+ $magazine = $this->getMagazineByName('test', $owner);
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $this->getUserByUsername('JohnDoe');
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:stats');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:stats');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineStats(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
$user2 = $this->getUserByUsername('JohnDoe2');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -103,15 +101,15 @@ public function testApiCanRetrieveMagazineStats(): void
$entityManager->persist($vote);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:stats');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:stats');
$token = $codes['token_type'].' '.$codes['access_token'];
// Start a day ago to avoid timezone issues when testing on machines with non-UTC timezones
- $startString = rawurlencode($entry->getCreatedAt()->add(\DateInterval::createFromDateString('-1 day'))->format(\DateTimeImmutable::ATOM));
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes?resolution=hour&start=$startString", server: ['HTTP_AUTHORIZATION' => $token]);
+ $startString = rawurlencode($entry->getCreatedAt()->add(\DateInterval::createFromDateString('-1 minute'))->format(\DateTimeImmutable::ATOM));
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/votes?resolution=hour&start=$startString", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::STATS_BY_CONTENT_TYPE_KEYS, $jsonData);
@@ -124,34 +122,21 @@ public function testApiCanRetrieveMagazineStats(): void
self::assertIsArray($jsonData['post_comment']);
self::assertEmpty($jsonData['post_comment']);
self::assertArrayKeysMatch(self::VOTE_ITEM_KEYS, $jsonData['entry'][0]);
- $voteTimestamp = (new \DateTimeImmutable($jsonData['entry'][0]['datetime']))->getTimestamp();
- if ($nowTimestamp !== $voteTimestamp) {
- self::assertEquals(abs($nowTimestamp - $voteTimestamp), 3600);
- }
self::assertSame(1, $jsonData['entry'][0]['up']);
self::assertSame(0, $jsonData['entry'][0]['down']);
self::assertSame(1, $jsonData['entry'][0]['boost']);
- $client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content?resolution=hour&start=$startString", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/stats/magazine/{$magazine->getId()}/content?resolution=hour&start=$startString", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::STATS_BY_CONTENT_TYPE_KEYS, $jsonData);
- self::assertIsArray($jsonData['entry']);
- self::assertCount(1, $jsonData['entry']);
- self::assertIsArray($jsonData['entry_comment']);
- self::assertEmpty($jsonData['entry_comment']);
- self::assertIsArray($jsonData['post']);
- self::assertEmpty($jsonData['post']);
- self::assertIsArray($jsonData['post_comment']);
- self::assertEmpty($jsonData['post_comment']);
- self::assertArrayKeysMatch(self::COUNT_ITEM_KEYS, $jsonData['entry'][0]);
- $contentTimestamp = (new \DateTimeImmutable($jsonData['entry'][0]['datetime']))->getTimestamp();
- if ($nowTimestamp !== $contentTimestamp) {
- self::assertEquals(abs($nowTimestamp - $contentTimestamp), 3600);
- }
- self::assertSame(1, $jsonData['entry'][0]['count']);
+ self::assertIsInt($jsonData['entry']);
+ self::assertIsInt($jsonData['entry_comment']);
+ self::assertIsInt($jsonData['post']);
+ self::assertIsInt($jsonData['post_comment']);
+ self::assertSame(1, $jsonData['entry']);
}
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineTagsApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineTagsApiTest.php
index 726e32cb3..885729268 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineTagsApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineTagsApiTest.php
@@ -14,47 +14,43 @@ class MagazineTagsApiTest extends WebTestCase
{
public function testApiCannotAddTagsToMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRemoveTagsFromMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$magazine->tags = ['test'];
$entityManager = $this->getService(EntityManagerInterface::class);
$entityManager->persist($magazine);
$entityManager->flush();
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotAddTagsToMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRemoveTagsFromMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -63,19 +59,18 @@ public function testApiCannotRemoveTagsFromMagazineWithoutScope(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotAddTagsMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -83,21 +78,21 @@ public function testApiModCannotAddTagsMagazine(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:tags');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:tags');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiModCannotRemoveTagsMagazine(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -105,6 +100,7 @@ public function testApiModCannotRemoveTagsMagazine(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
$magazine->tags = ['test'];
@@ -112,30 +108,29 @@ public function testApiModCannotRemoveTagsMagazine(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:tags');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:tags');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiOwnerCanAddTagsMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:tags');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:tags');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -146,26 +141,24 @@ public function testApiOwnerCanAddTagsMagazine(): void
public function testApiOwnerCannotAddWeirdTagsMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:tags');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:tags');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test%20Weird", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/tag/test%20Weird", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
public function testApiOwnerCanRemoveTagsMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -174,13 +167,13 @@ public function testApiOwnerCanRemoveTagsMagazine(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:tags');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:tags');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -188,13 +181,13 @@ public function testApiOwnerCanRemoveTagsMagazine(): void
self::assertCount(1, $jsonData['tags']);
self::assertEquals('test', $jsonData['tags'][0]);
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/tag/test", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
}
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateApiTest.php
index dd6845daf..9cbd8bc8e 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateApiTest.php
@@ -11,39 +11,36 @@ class MagazineUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateMagazineAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('PUT', "/api/moderate/magazine/{$magazine->getId()}");
+ $this->client->request('PUT', "/api/moderate/magazine/{$magazine->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateMagazineWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/moderate/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:update');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:update');
$token = $codes['token_type'].' '.$codes['access_token'];
$name = 'test';
@@ -51,7 +48,7 @@ public function testApiCanUpdateMagazine(): void
$description = 'A description';
$rules = 'Some rules';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', "/api/moderate/magazine/{$magazine->getId()}",
parameters: [
'name' => $name,
@@ -64,7 +61,7 @@ public function testApiCanUpdateMagazine(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -77,14 +74,13 @@ public function testApiCanUpdateMagazine(): void
public function testApiCannotUpdateMagazineWithInvalidParams(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:update');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:update');
$token = $codes['token_type'].' '.$codes['access_token'];
$name = 'someothername';
@@ -92,7 +88,7 @@ public function testApiCannotUpdateMagazineWithInvalidParams(): void
$description = 'A description';
$rules = 'Some rules';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', "/api/moderate/magazine/{$magazine->getId()}",
parameters: [
'name' => $name,
@@ -108,7 +104,7 @@ public function testApiCannotUpdateMagazineWithInvalidParams(): void
$description = 'short title';
$title = 'as';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', "/api/moderate/magazine/{$magazine->getId()}",
parameters: [
'title' => $title,
@@ -123,7 +119,7 @@ public function testApiCannotUpdateMagazineWithInvalidParams(): void
$description = 'long title';
$title = 'Way too long of a title. This can only be 50 characters!';
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', "/api/moderate/magazine/{$magazine->getId()}",
parameters: [
'title' => $title,
@@ -135,35 +131,5 @@ public function testApiCannotUpdateMagazineWithInvalidParams(): void
);
self::assertResponseStatusCodeSame(400);
-
- $description = 'short rules';
- $title = 'This has too short rules';
- $client->jsonRequest(
- 'PUT', "/api/moderate/magazine/{$magazine->getId()}",
- parameters: [
- 'title' => $title,
- 'description' => $description,
- 'rules' => 'ru',
- 'isAdult' => false,
- ],
- server: ['HTTP_AUTHORIZATION' => $token]
- );
-
- self::assertResponseStatusCodeSame(400);
-
- $rules = 'short description';
- $title = 'This has too short of a description';
- $client->jsonRequest(
- 'PUT', "/api/moderate/magazine/{$magazine->getId()}",
- parameters: [
- 'title' => $title,
- 'description' => 'de',
- 'rules' => $rules,
- 'isAdult' => false,
- ],
- server: ['HTTP_AUTHORIZATION' => $token]
- );
-
- self::assertResponseStatusCodeSame(400);
}
}
diff --git a/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateThemeApiTest.php b/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateThemeApiTest.php
index 4bd1639d3..87c441900 100644
--- a/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateThemeApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Admin/MagazineUpdateThemeApiTest.php
@@ -22,18 +22,16 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testApiCannotUpdateMagazineThemeAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme");
self::assertResponseStatusCodeSame(401);
}
public function testApiModCannotUpdateMagazineTheme(): void
{
- $client = self::createClient();
$moderator = $this->getUserByUsername('JohnDoe');
- $client->loginUser($moderator);
+ $this->client->loginUser($moderator);
$owner = $this->getUserByUsername('JaneDoe');
self::createOAuth2AuthCodeClient();
@@ -41,42 +39,41 @@ public function testApiModCannotUpdateMagazineTheme(): void
$magazineManager = $this->getService(MagazineManager::class);
$dto = new ModeratorDto($magazine);
$dto->user = $moderator;
+ $dto->addedBy = $owner;
$magazineManager->addModerator($dto);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:theme');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:theme');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateMagazineThemeWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/theme", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateMagazineThemeWithCustomCss(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:theme');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:theme');
$token = $codes['token_type'].' '.$codes['access_token'];
// Uploading a file appears to delete the file at the given path, so make a copy before upload
@@ -85,7 +82,7 @@ public function testApiCanUpdateMagazineThemeWithCustomCss(): void
$customCss = 'a {background: red;}';
- $client->request(
+ $this->client->request(
'POST', "/api/moderate/magazine/{$magazine->getId()}/theme",
parameters: [
'customCss' => $customCss,
@@ -95,7 +92,7 @@ public function testApiCanUpdateMagazineThemeWithCustomCss(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_THEME_RESPONSE_KEYS, $jsonData);
@@ -111,14 +108,13 @@ public function testApiCanUpdateMagazineThemeWithCustomCss(): void
public function testApiCanUpdateMagazineThemeWithBackgroundImage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine_admin:theme');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine_admin:theme');
$token = $codes['token_type'].' '.$codes['access_token'];
// Uploading a file appears to delete the file at the given path, so make a copy before upload
@@ -127,7 +123,7 @@ public function testApiCanUpdateMagazineThemeWithBackgroundImage(): void
$backgroundImage = 'shape1';
- $client->request(
+ $this->client->request(
'POST', "/api/moderate/magazine/{$magazine->getId()}/theme",
parameters: [
'backgroundImage' => $backgroundImage,
@@ -137,7 +133,7 @@ public function testApiCanUpdateMagazineThemeWithBackgroundImage(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_THEME_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/MagazineBlockApiTest.php b/tests/Functional/Controller/Api/Magazine/MagazineBlockApiTest.php
index d553bba7d..1d422b82f 100644
--- a/tests/Functional/Controller/Api/Magazine/MagazineBlockApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/MagazineBlockApiTest.php
@@ -11,48 +11,44 @@ class MagazineBlockApiTest extends WebTestCase
{
public function testApiCannotBlockMagazineAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block');
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotBlockMagazineWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanBlockMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/block', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -61,10 +57,10 @@ public function testApiCanBlockMagazine(): void
self::assertNull($jsonData['isUserSubscribed']);
self::assertTrue($jsonData['isBlockedByUser']);
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -76,50 +72,46 @@ public function testApiCanBlockMagazine(): void
public function testApiCannotUnblockMagazineAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock');
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnblockMagazineWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnblockMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$manager = $this->getService(MagazineManager::class);
$manager->block($magazine, $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -128,10 +120,10 @@ public function testApiCanUnblockMagazine(): void
self::assertNull($jsonData['isUserSubscribed']);
self::assertFalse($jsonData['isBlockedByUser']);
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/MagazineModlogApiTest.php b/tests/Functional/Controller/Api/Magazine/MagazineModlogApiTest.php
index 4f87ed88a..75f3eb6fe 100644
--- a/tests/Functional/Controller/Api/Magazine/MagazineModlogApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/MagazineModlogApiTest.php
@@ -11,14 +11,12 @@ class MagazineModlogApiTest extends WebTestCase
{
public function testApiCanRetrieveModlogByMagazineIdAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log');
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -28,19 +26,18 @@ public function testApiCanRetrieveModlogByMagazineIdAnonymously(): void
public function testApiCanRetrieveMagazineById(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -50,8 +47,6 @@ public function testApiCanRetrieveMagazineById(): void
public function testApiModlogReflectsModerationActionsTaken(): void
{
- $client = self::createClient();
-
$this->createModlogMessages();
$magazine = $this->getMagazineByName('acme');
$moderator = $magazine->getOwner();
@@ -59,10 +54,10 @@ public function testApiModlogReflectsModerationActionsTaken(): void
$entityManager = $this->getService(EntityManagerInterface::class);
$entityManager->refresh($magazine);
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log');
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/log');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/MagazineRetrieveApiTest.php b/tests/Functional/Controller/Api/Magazine/MagazineRetrieveApiTest.php
index 0471c48d8..7c00a69b5 100644
--- a/tests/Functional/Controller/Api/Magazine/MagazineRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/MagazineRetrieveApiTest.php
@@ -22,14 +22,12 @@ class MagazineRetrieveApiTest extends WebTestCase
public function testApiCanRetrieveMagazineByIdAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('GET', "/api/magazine/{$magazine->getId()}");
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -38,7 +36,7 @@ public function testApiCanRetrieveMagazineByIdAnonymously(): void
self::assertArrayKeysMatch(self::MODERATOR_RESPONSE_KEYS, $jsonData['owner']);
self::assertSame($magazine->getOwner()->getId(), $jsonData['owner']['userId']);
self::assertNull($jsonData['icon']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertEquals('test', $jsonData['name']);
self::assertIsArray($jsonData['badges']);
self::assertIsArray($jsonData['moderators']);
@@ -55,19 +53,18 @@ public function testApiCanRetrieveMagazineByIdAnonymously(): void
public function testApiCanRetrieveMagazineById(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -76,7 +73,7 @@ public function testApiCanRetrieveMagazineById(): void
self::assertArrayKeysMatch(self::MODERATOR_RESPONSE_KEYS, $jsonData['owner']);
self::assertSame($magazine->getOwner()->getId(), $jsonData['owner']['userId']);
self::assertNull($jsonData['icon']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertEquals('test', $jsonData['name']);
self::assertIsArray($jsonData['badges']);
self::assertIsArray($jsonData['moderators']);
@@ -93,14 +90,12 @@ public function testApiCanRetrieveMagazineById(): void
public function testApiCanRetrieveMagazineByNameAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('GET', '/api/magazine/name/test');
+ $this->client->request('GET', '/api/magazine/name/test');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -109,7 +104,7 @@ public function testApiCanRetrieveMagazineByNameAnonymously(): void
self::assertArrayKeysMatch(self::MODERATOR_RESPONSE_KEYS, $jsonData['owner']);
self::assertSame($magazine->getOwner()->getId(), $jsonData['owner']['userId']);
self::assertNull($jsonData['icon']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertEquals('test', $jsonData['name']);
self::assertIsArray($jsonData['badges']);
self::assertIsArray($jsonData['moderators']);
@@ -126,19 +121,18 @@ public function testApiCanRetrieveMagazineByNameAnonymously(): void
public function testApiCanRetrieveMagazineByName(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazine/name/test', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/name/test', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -147,7 +141,7 @@ public function testApiCanRetrieveMagazineByName(): void
self::assertArrayKeysMatch(self::MODERATOR_RESPONSE_KEYS, $jsonData['owner']);
self::assertSame($magazine->getOwner()->getId(), $jsonData['owner']['userId']);
self::assertNull($jsonData['icon']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertEquals('test', $jsonData['name']);
self::assertIsArray($jsonData['badges']);
self::assertIsArray($jsonData['moderators']);
@@ -164,20 +158,19 @@ public function testApiCanRetrieveMagazineByName(): void
public function testApiMagazineSubscribeAndBlockFlags(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -192,22 +185,21 @@ public function testApiMagazineSubscribeAndBlockFlags(): void
// were made, these tests could be rolled into testApiMagazineSubscribeAndBlockFlags above
public function testApiMagazineSubscribeFlagIsTrueWhenSubscribed(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$manager = $this->getService(MagazineManager::class);
$manager->subscribe($magazine, $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -219,9 +211,8 @@ public function testApiMagazineSubscribeFlagIsTrueWhenSubscribed(): void
public function testApiMagazineBlockFlagIsTrueWhenBlocked(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -231,13 +222,13 @@ public function testApiMagazineBlockFlagIsTrueWhenBlocked(): void
$entityManager->persist($user);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -249,14 +240,12 @@ public function testApiMagazineBlockFlagIsTrueWhenBlocked(): void
public function testApiCanRetrieveMagazineCollectionAnonymous(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('GET', '/api/magazines');
+ $this->client->request('GET', '/api/magazines');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -271,19 +260,18 @@ public function testApiCanRetrieveMagazineCollectionAnonymous(): void
public function testApiCanRetrieveMagazineCollection(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -301,8 +289,7 @@ public function testApiCanRetrieveMagazineCollection(): void
public function testApiCanRetrieveMagazineCollectionMultiplePages(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazines = [];
@@ -311,13 +298,13 @@ public function testApiCanRetrieveMagazineCollectionMultiplePages(): void
}
$perPage = max((int) ceil(self::MAGAZINE_COUNT / 2), 1);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazines?perPage={$perPage}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazines?perPage={$perPage}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -335,42 +322,39 @@ public function testApiCanRetrieveMagazineCollectionMultiplePages(): void
public function testApiCannotRetrieveMagazineSubscriptionsAnonymous(): void
{
- $client = self::createClient();
- $client->request('GET', '/api/magazines/subscribed');
+ $this->client->request('GET', '/api/magazines/subscribed');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineSubscriptionsWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineSubscriptions(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$notSubbedMag = $this->getMagazineByName('someother', $this->getUserByUsername('JaneDoe'));
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -388,32 +372,29 @@ public function testApiCanRetrieveMagazineSubscriptions(): void
public function testApiCannotRetrieveUserMagazineSubscriptionsAnonymous(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testUser');
- $client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions");
+ $this->client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveUserMagazineSubscriptionsWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
$user = $this->getUserByUsername('testUser');
- $client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveUserMagazineSubscriptions(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('testUser');
@@ -425,13 +406,13 @@ public function testApiCanRetrieveUserMagazineSubscriptions(): void
$notSubbedMag = $this->getMagazineByName('someother', $this->getUserByUsername('JaneDoe'));
$magazine = $this->getMagazineByName('test', $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -449,8 +430,7 @@ public function testApiCanRetrieveUserMagazineSubscriptions(): void
public function testApiCannotRetrieveUserMagazineSubscriptionsIfSettingTurnedOff(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('testUser');
@@ -459,52 +439,49 @@ public function testApiCannotRetrieveUserMagazineSubscriptionsIfSettingTurnedOff
$entityManager->persist($user);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/magazines/subscriptions", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveModeratedMagazinesAnonymous(): void
{
- $client = self::createClient();
- $client->request('GET', '/api/magazines/moderated');
+ $this->client->request('GET', '/api/magazines/moderated');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveModeratedMagazinesWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveModeratedMagazines(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$notModdedMag = $this->getMagazineByName('someother', $this->getUserByUsername('JaneDoe'));
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:list');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:list');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -522,30 +499,27 @@ public function testApiCanRetrieveModeratedMagazines(): void
public function testApiCannotRetrieveBlockedMagazinesAnonymous(): void
{
- $client = self::createClient();
- $client->request('GET', '/api/magazines/blocked');
+ $this->client->request('GET', '/api/magazines/blocked');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveBlockedMagazinesWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveBlockedMagazines(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$notBlockedMag = $this->getMagazineByName('someother', $this->getUserByUsername('JaneDoe'));
@@ -554,13 +528,13 @@ public function testApiCanRetrieveBlockedMagazines(): void
$manager = $this->getService(MagazineManager::class);
$manager->block($magazine, $this->getUserByUsername('JohnDoe'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazines/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazines/blocked', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/MagazineRetrieveThemeApiTest.php b/tests/Functional/Controller/Api/Magazine/MagazineRetrieveThemeApiTest.php
index 02aabdfea..dfbb311ea 100644
--- a/tests/Functional/Controller/Api/Magazine/MagazineRetrieveThemeApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/MagazineRetrieveThemeApiTest.php
@@ -13,8 +13,6 @@ class MagazineRetrieveThemeApiTest extends WebTestCase
public function testApiCanRetrieveMagazineThemeByIdAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
$magazine->customCss = '.test {}';
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -22,10 +20,10 @@ public function testApiCanRetrieveMagazineThemeByIdAnonymously(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/theme');
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/theme');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_THEME_RESPONSE_KEYS, $jsonData);
@@ -37,8 +35,7 @@ public function testApiCanRetrieveMagazineThemeByIdAnonymously(): void
public function testApiCanRetrieveMagazineThemeById(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -48,13 +45,13 @@ public function testApiCanRetrieveMagazineThemeById(): void
$entityManager->persist($magazine);
$entityManager->flush();
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/theme', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId().'/theme', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MAGAZINE_THEME_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/MagazineSubscribeApiTest.php b/tests/Functional/Controller/Api/Magazine/MagazineSubscribeApiTest.php
index 2bcda8859..ac16ec3db 100644
--- a/tests/Functional/Controller/Api/Magazine/MagazineSubscribeApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/MagazineSubscribeApiTest.php
@@ -11,48 +11,44 @@ class MagazineSubscribeApiTest extends WebTestCase
{
public function testApiCannotSubscribeToMagazineAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe');
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSubscribeToMagazineWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSubscribeToMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/subscribe', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -61,10 +57,10 @@ public function testApiCanSubscribeToMagazine(): void
self::assertTrue($jsonData['isUserSubscribed']);
self::assertFalse($jsonData['isBlockedByUser']);
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -76,50 +72,46 @@ public function testApiCanSubscribeToMagazine(): void
public function testApiCannotUnsubscribeFromMagazineAnonymously(): void
{
- $client = self::createClient();
-
$magazine = $this->getMagazineByName('test');
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe');
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnsubscribeFromMagazineWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:block');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:block');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnsubscribeFromMagazine(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('testuser');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$manager = $this->getService(MagazineManager::class);
$manager->subscribe($magazine, $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write magazine:subscribe');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write magazine:subscribe');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/magazine/'.(string) $magazine->getId().'/unsubscribe', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
@@ -128,10 +120,10 @@ public function testApiCanUnsubscribeFromMagazine(): void
self::assertFalse($jsonData['isUserSubscribed']);
self::assertNull($jsonData['isBlockedByUser']);
- $client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/magazine/'.(string) $magazine->getId(), server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveApiTest::MAGAZINE_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineActionReportsApiTest.php b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineActionReportsApiTest.php
index 16034b4d0..783d71346 100644
--- a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineActionReportsApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineActionReportsApiTest.php
@@ -13,7 +13,6 @@ class MagazineActionReportsApiTest extends WebTestCase
{
public function testApiCannotAcceptReportAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('JohnDoe');
$reportedUser = $this->getUserByUsername('testuser');
@@ -21,14 +20,13 @@ public function testApiCannotAcceptReportAnonymous(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRejectReportAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('JohnDoe');
$reportedUser = $this->getUserByUsername('testuser');
@@ -36,16 +34,15 @@ public function testApiCannotRejectReportAnonymous(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotAcceptReportWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('testuser');
@@ -54,19 +51,18 @@ public function testApiCannotAcceptReportWithoutScope(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRejectReportWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('testuser');
@@ -75,19 +71,18 @@ public function testApiCannotRejectReportWithoutScope(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotAcceptReportIfNotMod(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
$reportedUser = $this->getUserByUsername('testuser');
@@ -96,19 +91,18 @@ public function testApiCannotAcceptReportIfNotMod(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:action');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:action');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRejectReportIfNotMod(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
$reportedUser = $this->getUserByUsername('testuser');
@@ -117,19 +111,18 @@ public function testApiCannotRejectReportIfNotMod(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:action');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:action');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanAcceptReport(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('testuser');
@@ -138,14 +131,14 @@ public function testApiCanAcceptReport(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:action');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:action');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/accept", server: ['HTTP_AUTHORIZATION' => $token]);
$consideredAt = new \DateTimeImmutable();
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveReportsApiTest::REPORT_RESPONSE_KEYS, $jsonData);
@@ -172,9 +165,8 @@ public function testApiCanAcceptReport(): void
public function testApiCanRejectReport(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('testuser');
@@ -183,14 +175,14 @@ public function testApiCanRejectReport(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:action');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:action');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}/reject", server: ['HTTP_AUTHORIZATION' => $token]);
$consideredAt = new \DateTimeImmutable();
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveReportsApiTest::REPORT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineBanApiTest.php b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineBanApiTest.php
index f716960d7..03408a1ad 100644
--- a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineBanApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineBanApiTest.php
@@ -13,63 +13,59 @@ class MagazineBanApiTest extends WebTestCase
{
public function testApiCannotCreateMagazineBanAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('testuser');
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}");
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreateMagazineBanWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('testuser');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotCreateMagazineBanIfNotMod(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
$user = $this->getUserByUsername('testuser');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreateMagazineBan(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$bannedUser = $this->getUserByUsername('hapless_fool');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:create');
$token = $codes['token_type'].' '.$codes['access_token'];
$reason = 'you got banned through the API, how does that make you feel?';
$expiredAt = (new \DateTimeImmutable('+1 hour'))->format(\DateTimeImmutable::ATOM);
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/moderate/magazine/{$magazine->getId()}/ban/{$bannedUser->getId()}",
parameters: [
'reason' => $reason,
@@ -79,7 +75,7 @@ public function testApiCanCreateMagazineBan(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveBansApiTest::BAN_RESPONSE_KEYS, $jsonData);
@@ -96,51 +92,47 @@ public function testApiCanCreateMagazineBan(): void
public function testApiCannotDeleteMagazineBanAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('testuser');
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}");
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteMagazineBanWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$user = $this->getUserByUsername('testuser');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteMagazineBanIfNotMod(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
$user = $this->getUserByUsername('testuser');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$user->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteMagazineBan(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$bannedUser = $this->getUserByUsername('hapless_fool');
@@ -149,15 +141,15 @@ public function testApiCanDeleteMagazineBan(): void
$ban = MagazineBanDto::create('test ban <3');
$magazineManager->ban($magazine, $bannedUser, $user, $ban);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
$expiredAt = (new \DateTimeImmutable('+10 seconds'));
- $client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$bannedUser->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/moderate/magazine/{$magazine->getId()}/ban/{$bannedUser->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MagazineRetrieveBansApiTest::BAN_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveBansApiTest.php b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveBansApiTest.php
index 424b52b8f..f8a4226f9 100644
--- a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveBansApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveBansApiTest.php
@@ -15,48 +15,44 @@ class MagazineRetrieveBansApiTest extends WebTestCase
public function testApiCannotRetrieveMagazineBansAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans");
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineBansWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveMagazineBansIfNotMod(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:read');
$token = $codes['token_type'].' '.$codes['access_token'];
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineBans(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -65,13 +61,13 @@ public function testApiCanRetrieveMagazineBans(): void
$ban = MagazineBanDto::create('test ban :)');
$magazineManager->ban($magazine, $bannedUser, $user, $ban);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:ban:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:ban:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/bans", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveReportsApiTest.php b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveReportsApiTest.php
index cd401b1f2..8dd12304d 100644
--- a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveReportsApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveReportsApiTest.php
@@ -15,7 +15,6 @@ class MagazineRetrieveReportsApiTest extends WebTestCase
public function testApiCannotRetrieveMagazineReportByIdAnonymous(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('hapless_fool');
@@ -23,16 +22,15 @@ public function testApiCannotRetrieveMagazineReportByIdAnonymous(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}");
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineReportByIdWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('hapless_fool');
@@ -41,19 +39,18 @@ public function testApiCannotRetrieveMagazineReportByIdWithoutScope(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveMagazineReportByIdIfNotMod(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
$reportedUser = $this->getUserByUsername('hapless_fool');
@@ -62,19 +59,18 @@ public function testApiCannotRetrieveMagazineReportByIdIfNotMod(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineReportById(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
$reportedUser = $this->getUserByUsername('hapless_fool');
@@ -83,13 +79,13 @@ public function testApiCanRetrieveMagazineReportById(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports/{$report->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::REPORT_RESPONSE_KEYS, $jsonData);
@@ -112,48 +108,44 @@ public function testApiCanRetrieveMagazineReportById(): void
public function testApiCannotRetrieveMagazineReportsAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports");
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineReportsWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveMagazineReportsIfNotMod(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:read');
$token = $codes['token_type'].' '.$codes['access_token'];
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineReports(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -163,13 +155,13 @@ public function testApiCanRetrieveMagazineReports(): void
$reportManager = $this->getService(ReportManager::class);
$report = $reportManager->report(ReportDto::create($entry, 'I don\'t like it'), $user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:reports:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:reports:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/reports", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveTrashApiTest.php b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveTrashApiTest.php
index 5c7c7ba82..36e69f9fd 100644
--- a/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveTrashApiTest.php
+++ b/tests/Functional/Controller/Api/Magazine/Moderate/MagazineRetrieveTrashApiTest.php
@@ -13,48 +13,44 @@ class MagazineRetrieveTrashApiTest extends WebTestCase
{
public function testApiCannotRetrieveMagazineTrashAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByName('test');
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash");
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRetrieveMagazineTrashWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
- $codes = self::getAuthorizationCodeTokenResponse($client);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client);
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveMagazineTrashIfNotMod(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:trash:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:trash:read');
$token = $codes['token_type'].' '.$codes['access_token'];
$magazine = $this->getMagazineByName('test', $this->getUserByUsername('JaneDoe'));
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveMagazineTrash(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
self::createOAuth2AuthCodeClient();
$magazine = $this->getMagazineByName('test');
@@ -64,13 +60,13 @@ public function testApiCanRetrieveMagazineTrash(): void
$entryManager = $this->getService(EntryManager::class);
$entryManager->delete($user, $entry);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read write moderate:magazine:trash:read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read write moderate:magazine:trash:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/moderate/magazine/{$magazine->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Message/MessageReadApiTest.php b/tests/Functional/Controller/Api/Message/MessageReadApiTest.php
index 3fd97f6b2..eaf4ff4eb 100644
--- a/tests/Functional/Controller/Api/Message/MessageReadApiTest.php
+++ b/tests/Functional/Controller/Api/Message/MessageReadApiTest.php
@@ -12,31 +12,28 @@ class MessageReadApiTest extends WebTestCase
{
public function testApiCannotMarkMessagesReadAnonymous(): void
{
- $client = self::createClient();
$message = $this->createMessage($this->getUserByUsername('JohnDoe'), $this->getUserByUsername('JaneDoe'), 'test message');
- $client->request('PUT', "/api/messages/{$message->getId()}/read");
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/read");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotMarkMessagesReadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$message = $this->createMessage($this->getUserByUsername('JohnDoe'), $this->getUserByUsername('JaneDoe'), 'test message');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotMarkOtherUsersMessagesRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -44,17 +41,16 @@ public function testApiCannotMarkOtherUsersMessagesRead(): void
$message = $this->createMessage($messagedUser, $messagingUser, 'test message');
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanMarkMessagesRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -63,13 +59,13 @@ public function testApiCanMarkMessagesRead(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MESSAGE_RESPONSE_KEYS, $jsonData);
@@ -84,31 +80,28 @@ public function testApiCanMarkMessagesRead(): void
public function testApiCannotMarkMessagesUnreadAnonymous(): void
{
- $client = self::createClient();
$message = $this->createMessage($this->getUserByUsername('JohnDoe'), $this->getUserByUsername('JaneDoe'), 'test message');
- $client->request('PUT', "/api/messages/{$message->getId()}/unread");
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/unread");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotMarkMessagesUnreadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$message = $this->createMessage($this->getUserByUsername('JohnDoe'), $this->getUserByUsername('JaneDoe'), 'test message');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotMarkOtherUsersMessagesUnread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -116,17 +109,16 @@ public function testApiCannotMarkOtherUsersMessagesUnread(): void
$message = $this->createMessage($messagedUser, $messagingUser, 'test message');
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanMarkMessagesUnread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -137,13 +129,13 @@ public function testApiCanMarkMessagesUnread(): void
$messageManager = $this->getService(MessageManager::class);
$messageManager->readMessage($message, $user, flush: true);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/messages/{$message->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MESSAGE_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Message/MessageRetrieveApiTest.php b/tests/Functional/Controller/Api/Message/MessageRetrieveApiTest.php
index ca1a05bb1..9ac284e0b 100644
--- a/tests/Functional/Controller/Api/Message/MessageRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Message/MessageRetrieveApiTest.php
@@ -15,29 +15,25 @@ class MessageRetrieveApiTest extends WebTestCase
public function testApiCannotGetMessagesAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/messages');
+ $this->client->request('GET', '/api/messages');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetMessagesWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/messages', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/messages', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetMessages(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -49,13 +45,13 @@ public function testApiCanGetMessages(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/messages', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/messages', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -82,29 +78,25 @@ public function testApiCanGetMessages(): void
public function testApiCannotGetMessageByIdAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/messages/1');
+ $this->client->request('GET', '/api/messages/1');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetMessageByIdWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/messages/1', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/messages/1', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotGetOtherUsersMessageById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -117,17 +109,16 @@ public function testApiCannotGetOtherUsersMessageById(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/messages/{$message->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/messages/{$message->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetMessageById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -139,13 +130,13 @@ public function testApiCanGetMessageById(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/messages/{$message->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/messages/{$message->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::MESSAGE_RESPONSE_KEYS, $jsonData);
@@ -160,7 +151,6 @@ public function testApiCanGetMessageById(): void
public function testApiCannotGetMessageThreadByIdAnonymous(): void
{
- $client = self::createClient();
$messagingUser = $this->getUserByUsername('JaneDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
@@ -169,34 +159,32 @@ public function testApiCannotGetMessageThreadByIdAnonymous(): void
$dto->body = 'test message';
$thread = $messageManager->toThread($dto, $messagingUser, $messagedUser);
- $client->request('GET', "/api/messages/thread/{$thread->getId()}");
+ $this->client->request('GET', "/api/messages/thread/{$thread->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetMessageThreadByIdWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$messageManager = $this->getService(MessageManager::class);
$dto = new MessageDto();
$dto->body = 'test message';
$thread = $messageManager->toThread($dto, $messagingUser, $messagedUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotGetOtherUsersMessageThreadById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -207,17 +195,16 @@ public function testApiCannotGetOtherUsersMessageThreadById(): void
$dto->body = 'test message';
$thread = $messageManager->toThread($dto, $messagingUser, $messagedUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetMessageThreadById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -229,13 +216,13 @@ public function testApiCanGetMessageThreadById(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/messages/thread/{$thread->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(array_merge(self::PAGINATED_KEYS, ['participants']), $jsonData);
diff --git a/tests/Functional/Controller/Api/Message/MessageThreadCreateApiTest.php b/tests/Functional/Controller/Api/Message/MessageThreadCreateApiTest.php
index 8ee969154..2f1fdc1b0 100644
--- a/tests/Functional/Controller/Api/Message/MessageThreadCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Message/MessageThreadCreateApiTest.php
@@ -11,43 +11,40 @@ class MessageThreadCreateApiTest extends WebTestCase
{
public function testApiCannotCreateThreadAnonymous(): void
{
- $client = self::createClient();
$messagedUser = $this->getUserByUsername('JohnDoe');
- $client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message']);
+ $this->client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message']);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreateThreadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$messagedUser = $this->getUserByUsername('JaneDoe');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreateThread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagedUser = $this->getUserByUsername('JaneDoe');
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:create');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/users/{$messagedUser->getId()}/message", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MessageRetrieveApiTest::MESSAGE_THREAD_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Message/MessageThreadReplyApiTest.php b/tests/Functional/Controller/Api/Message/MessageThreadReplyApiTest.php
index 3faff9ef4..ad29d050f 100644
--- a/tests/Functional/Controller/Api/Message/MessageThreadReplyApiTest.php
+++ b/tests/Functional/Controller/Api/Message/MessageThreadReplyApiTest.php
@@ -12,35 +12,32 @@ class MessageThreadReplyApiTest extends WebTestCase
{
public function testApiCannotReplyToThreadAnonymous(): void
{
- $client = self::createClient();
$to = $this->getUserByUsername('JohnDoe');
$from = $this->getUserByUsername('JaneDoe');
$thread = $this->createMessageThread($to, $from, 'starting a thread');
- $client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message']);
+ $this->client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message']);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotReplyToThreadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$from = $this->getUserByUsername('JaneDoe');
$thread = $this->createMessageThread($user, $from, 'starting a thread');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanReplyToThread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
@@ -52,13 +49,13 @@ public function testApiCanReplyToThread(): void
$entityManager->persist($thread);
$entityManager->flush();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:message:create');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:message:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/messages/thread/{$thread->getId()}/reply", parameters: ['body' => 'test message'], server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(MessageRetrieveApiTest::MESSAGE_THREAD_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Notification/NotificationDeleteApiTest.php b/tests/Functional/Controller/Api/Notification/NotificationDeleteApiTest.php
index 740295f02..8a5496a26 100644
--- a/tests/Functional/Controller/Api/Notification/NotificationDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Notification/NotificationDeleteApiTest.php
@@ -11,56 +11,52 @@ class NotificationDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteNotificationByIdAnonymous(): void
{
- $client = self::createClient();
$notification = $this->createMessageNotification();
- $client->request('DELETE', "/api/notifications/{$notification->getId()}");
+ $this->client->request('DELETE', "/api/notifications/{$notification->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteNotificationByIdWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersNotificationById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
$notification = $this->createMessageNotification($messagedUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:delete');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteNotificationById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:delete');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/notifications/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$notificationRepository = $this->getService(NotificationRepository::class);
@@ -70,43 +66,39 @@ public function testApiCanDeleteNotificationById(): void
public function testApiCannotDeleteAllNotificationsAnonymous(): void
{
- $client = self::createClient();
-
$this->createMessageNotification();
- $client->request('DELETE', '/api/notifications');
+ $this->client->request('DELETE', '/api/notifications');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteAllNotificationsWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$this->createMessageNotification();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', '/api/notifications', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', '/api/notifications', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteAllNotifications(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:delete');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', '/api/notifications', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', '/api/notifications', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$notificationRepository = $this->getService(NotificationRepository::class);
diff --git a/tests/Functional/Controller/Api/Notification/NotificationReadApiTest.php b/tests/Functional/Controller/Api/Notification/NotificationReadApiTest.php
index 6febcec34..fac91ad13 100644
--- a/tests/Functional/Controller/Api/Notification/NotificationReadApiTest.php
+++ b/tests/Functional/Controller/Api/Notification/NotificationReadApiTest.php
@@ -13,58 +13,54 @@ class NotificationReadApiTest extends WebTestCase
{
public function testApiCannotMarkNotificationReadAnonymous(): void
{
- $client = self::createClient();
$notification = $this->createMessageNotification();
- $client->request('PUT', "/api/notifications/{$notification->getId()}/read");
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/read");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotMarkNotificationReadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotMarkOtherUsersNotificationRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
$notification = $this->createMessageNotification($messagedUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanMarkNotificationRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/read", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(NotificationRetrieveApiTest::NOTIFICATION_RESPONSE_KEYS, $jsonData);
@@ -83,47 +79,43 @@ public function testApiCanMarkNotificationRead(): void
public function testApiCannotMarkNotificationUnreadAnonymous(): void
{
- $client = self::createClient();
$notification = $this->createMessageNotification();
- $client->request('PUT', "/api/notifications/{$notification->getId()}/unread");
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/unread");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotMarkNotificationUnreadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotMarkOtherUsersNotificationUnread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
$notification = $this->createMessageNotification($messagedUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanMarkNotificationUnread(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
@@ -132,13 +124,13 @@ public function testApiCanMarkNotificationUnread(): void
$entityManager->persist($notification);
$entityManager->flush();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/notifications/{$notification->getId()}/unread", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(NotificationRetrieveApiTest::NOTIFICATION_RESPONSE_KEYS, $jsonData);
@@ -157,43 +149,39 @@ public function testApiCanMarkNotificationUnread(): void
public function testApiCannotMarkAllNotificationsReadAnonymous(): void
{
- $client = self::createClient();
-
$this->createMessageNotification();
- $client->request('PUT', '/api/notifications/read');
+ $this->client->request('PUT', '/api/notifications/read');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotMarkAllNotificationsReadWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$this->createMessageNotification();
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanMarkAllNotificationsRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$notificationRepository = $this->getService(NotificationRepository::class);
diff --git a/tests/Functional/Controller/Api/Notification/NotificationRetrieveApiTest.php b/tests/Functional/Controller/Api/Notification/NotificationRetrieveApiTest.php
index 29e0b5293..ca82ede09 100644
--- a/tests/Functional/Controller/Api/Notification/NotificationRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Notification/NotificationRetrieveApiTest.php
@@ -16,29 +16,25 @@ class NotificationRetrieveApiTest extends WebTestCase
public function testApiCannotGetNotificationsByStatusAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/notifications/all');
+ $this->client->request('GET', '/api/notifications/all');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetNotificationsByStatusWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetNotificationsByStatusMessagesRedactedWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -54,13 +50,13 @@ public function testApiCanGetNotificationsByStatusMessagesRedactedWithoutScope()
// Create unread notification
$thread = $messageManager->toThread($dto, $messagingUser, $user);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -88,7 +84,6 @@ public function testApiCanGetNotificationsByStatusMessagesRedactedWithoutScope()
public function testApiCanGetNotificationsByStatusAll(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -100,13 +95,13 @@ public function testApiCanGetNotificationsByStatusAll(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -133,7 +128,6 @@ public function testApiCanGetNotificationsByStatusAll(): void
public function testApiCanGetNotificationsFromThreads(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -146,13 +140,13 @@ public function testApiCanGetNotificationsFromThreads(): void
$reply = $this->createEntryComment('Test reply comment', $entry, $messagingUser, $parent);
$this->createEntryComment('Test not notified comment', $entry, $messagingUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -190,7 +184,6 @@ public function testApiCanGetNotificationsFromThreads(): void
public function testApiCanGetNotificationsFromPosts(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -203,13 +196,13 @@ public function testApiCanGetNotificationsFromPosts(): void
$reply = $this->createPostCommentReply('Test reply comment', $post, $messagingUser, $parent);
$this->createPostComment('Test not notified comment', $post, $messagingUser);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read user:message:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read user:message:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/all', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -247,7 +240,6 @@ public function testApiCanGetNotificationsFromPosts(): void
public function testApiCanGetNotificationsByStatusRead(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -263,13 +255,13 @@ public function testApiCanGetNotificationsByStatusRead(): void
// Create unread notification
$thread = $messageManager->toThread($dto, $messagingUser, $user);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/read', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -294,7 +286,6 @@ public function testApiCanGetNotificationsByStatusRead(): void
public function testApiCanGetNotificationsByStatusNew(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -310,13 +301,13 @@ public function testApiCanGetNotificationsByStatusNew(): void
// Create unread notification
$thread = $messageManager->toThread($dto, $messagingUser, $user);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/new', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/new', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -341,7 +332,6 @@ public function testApiCanGetNotificationsByStatusNew(): void
public function testApiCannotGetNotificationsByInvalidStatus(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -357,39 +347,35 @@ public function testApiCannotGetNotificationsByInvalidStatus(): void
// Create unread notification
$thread = $messageManager->toThread($dto, $messagingUser, $user);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/invalid', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/invalid', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
public function testApiCannotGetNotificationCountAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/notifications/count');
+ $this->client->request('GET', '/api/notifications/count');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetNotificationCountWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/count', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/count', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetNotificationCount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagingUser = $this->getUserByUsername('JaneDoe');
@@ -404,13 +390,13 @@ public function testApiCanGetNotificationCount(): void
/** @var Message $message */
$message = $thread->messages->get(0);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/notifications/count', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/notifications/count', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(['count'], $jsonData);
@@ -419,35 +405,31 @@ public function testApiCanGetNotificationCount(): void
public function testApiCannotGetNotificationByIdAnonymous(): void
{
- $client = self::createClient();
-
$notification = $this->createMessageNotification();
self::assertNotNull($notification);
- $client->request('GET', "/api/notification/{$notification->getId()}");
+ $this->client->request('GET', "/api/notification/{$notification->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetNotificationByIdWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$notification = $this->createMessageNotification();
self::assertNotNull($notification);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotGetOtherUsersNotificationById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$messagedUser = $this->getUserByUsername('JamesDoe');
@@ -455,30 +437,29 @@ public function testApiCannotGetOtherUsersNotificationById(): void
$notification = $this->createMessageNotification($messagedUser);
self::assertNotNull($notification);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetNotificationById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('JohnDoe');
$notification = $this->createMessageNotification();
self::assertNotNull($notification);
- $client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:notification:read');
+ $this->client->loginUser($user);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:notification:read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/notification/{$notification->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::NOTIFICATION_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/OAuth2/OAuth2ClientApiTest.php b/tests/Functional/Controller/Api/OAuth2/OAuth2ClientApiTest.php
index a87916f6f..49317d589 100644
--- a/tests/Functional/Controller/Api/OAuth2/OAuth2ClientApiTest.php
+++ b/tests/Functional/Controller/Api/OAuth2/OAuth2ClientApiTest.php
@@ -24,8 +24,6 @@ class OAuth2ClientApiTest extends WebTestCase
public function testApiCanCreateWorkingClient(): void
{
- $client = self::createClient();
-
$requestData = [
'name' => '/kbin API Created Test Client',
'description' => 'An OAuth2 client for testing purposes, created via the API',
@@ -44,34 +42,34 @@ public function testApiCanCreateWorkingClient(): void
],
];
- $client->jsonRequest('POST', '/api/client', $requestData);
+ $this->client->jsonRequest('POST', '/api/client', $requestData);
self::assertResponseIsSuccessful();
- $clientData = self::getJsonResponse($client);
- self::assertIsArray($clientData);
- self::assertArrayKeysMatch(self::CLIENT_RESPONSE_KEYS, $clientData);
- self::assertNotNull($clientData['identifier']);
- self::assertNotNull($clientData['secret']);
- self::assertEquals($requestData['name'], $clientData['name']);
- self::assertEquals($requestData['contactEmail'], $clientData['contactEmail']);
- self::assertEquals($requestData['description'], $clientData['description']);
- self::assertNull($clientData['user']);
- self::assertIsArray($clientData['redirectUris']);
- self::assertEquals($requestData['redirectUris'], $clientData['redirectUris']);
- self::assertIsArray($clientData['grants']);
- self::assertEquals($requestData['grants'], $clientData['grants']);
- self::assertIsArray($clientData['scopes']);
- self::assertEquals($requestData['scopes'], $clientData['scopes']);
- self::assertNull($clientData['image']);
-
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->clientData = self::getJsonResponse($this->client);
+ self::assertIsArray($this->clientData);
+ self::assertArrayKeysMatch(self::CLIENT_RESPONSE_KEYS, $this->clientData);
+ self::assertNotNull($this->clientData['identifier']);
+ self::assertNotNull($this->clientData['secret']);
+ self::assertEquals($requestData['name'], $this->clientData['name']);
+ self::assertEquals($requestData['contactEmail'], $this->clientData['contactEmail']);
+ self::assertEquals($requestData['description'], $this->clientData['description']);
+ self::assertNull($this->clientData['user']);
+ self::assertIsArray($this->clientData['redirectUris']);
+ self::assertEquals($requestData['redirectUris'], $this->clientData['redirectUris']);
+ self::assertIsArray($this->clientData['grants']);
+ self::assertEquals($requestData['grants'], $this->clientData['grants']);
+ self::assertIsArray($this->clientData['scopes']);
+ self::assertEquals($requestData['scopes'], $this->clientData['scopes']);
+ self::assertNull($this->clientData['image']);
+
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$jsonData = self::getAuthorizationCodeTokenResponse(
- $client,
- clientId: $clientData['identifier'],
- clientSecret: $clientData['secret'],
- redirectUri: $clientData['redirectUris'][0],
+ $this->client,
+ clientId: $this->clientData['identifier'],
+ clientSecret: $this->clientData['secret'],
+ redirectUri: $this->clientData['redirectUris'][0],
);
self::assertResponseIsSuccessful();
@@ -80,15 +78,13 @@ public function testApiCanCreateWorkingClient(): void
public function testApiCanCreateWorkingPublicClient(): void
{
- $client = self::createClient();
-
$requestData = [
'name' => '/kbin API Created Test Client',
'description' => 'An OAuth2 client for testing purposes, created via the API',
'contactEmail' => 'test@kbin.test',
- 'public' => 'true',
+ 'public' => true,
'redirectUris' => [
- 'https://localhost:3002',
+ 'https://localhost:3001',
],
'grants' => [
'authorization_code',
@@ -101,11 +97,11 @@ public function testApiCanCreateWorkingPublicClient(): void
],
];
- $client->jsonRequest('POST', '/api/client', $requestData);
+ $this->client->jsonRequest('POST', '/api/client', $requestData);
self::assertResponseIsSuccessful();
- $clientData = self::getJsonResponse($client);
+ $clientData = self::getJsonResponse($this->client);
self::assertIsArray($clientData);
self::assertArrayKeysMatch(self::CLIENT_RESPONSE_KEYS, $clientData);
self::assertNotNull($clientData['identifier']);
@@ -122,10 +118,10 @@ public function testApiCanCreateWorkingPublicClient(): void
self::assertEquals($requestData['scopes'], $clientData['scopes']);
self::assertNull($clientData['image']);
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$jsonData = self::getPublicAuthorizationCodeTokenResponse(
- $client,
+ $this->client,
clientId: $clientData['identifier'],
redirectUri: $clientData['redirectUris'][0],
);
@@ -136,8 +132,6 @@ public function testApiCanCreateWorkingPublicClient(): void
public function testApiCanCreateWorkingClientWithImage(): void
{
- $client = self::createClient();
-
$requestData = [
'name' => '/kbin API Created Test Client',
'description' => 'An OAuth2 client for testing purposes, created via the API',
@@ -160,11 +154,11 @@ public function testApiCanCreateWorkingClientWithImage(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request('POST', '/api/client-with-logo', $requestData, files: ['uploadImage' => $image]);
+ $this->client->request('POST', '/api/client-with-logo', $requestData, files: ['uploadImage' => $image]);
self::assertResponseIsSuccessful();
- $clientData = self::getJsonResponse($client);
+ $clientData = self::getJsonResponse($this->client);
self::assertIsArray($clientData);
self::assertArrayKeysMatch(self::CLIENT_RESPONSE_KEYS, $clientData);
self::assertNotNull($clientData['identifier']);
@@ -182,17 +176,17 @@ public function testApiCanCreateWorkingClientWithImage(): void
self::assertisArray($clientData['image']);
self::assertArrayKeysMatch(self::IMAGE_KEYS, $clientData['image']);
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- self::runAuthorizationCodeFlowToConsentPage($client, 'read write', 'oauth2state', $clientData['identifier'], $clientData['redirectUris'][0]);
+ self::runAuthorizationCodeFlowToConsentPage($this->client, 'read write', 'oauth2state', $clientData['identifier'], $clientData['redirectUris'][0]);
self::assertSelectorExists('img.oauth-client-logo');
- $logo = $client->getCrawler()->filter('img.oauth-client-logo')->first();
+ $logo = $this->client->getCrawler()->filter('img.oauth-client-logo')->first();
self::assertStringContainsString($clientData['image']['filePath'], $logo->attr('src'));
- self::runAuthorizationCodeFlowToRedirectUri($client, 'read write', 'yes', 'oauth2state', $clientData['identifier'], $clientData['redirectUris'][0]);
+ self::runAuthorizationCodeFlowToRedirectUri($this->client, 'read write', 'yes', 'oauth2state', $clientData['identifier'], $clientData['redirectUris'][0]);
- $jsonData = self::runAuthorizationCodeTokenFlow($client, $clientData['identifier'], $clientData['secret'], $clientData['redirectUris'][0]);
+ $jsonData = self::runAuthorizationCodeTokenFlow($this->client, $clientData['identifier'], $clientData['secret'], $clientData['redirectUris'][0]);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -200,8 +194,7 @@ public function testApiCanCreateWorkingClientWithImage(): void
public function testApiCanDeletePrivateClient(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$query = http_build_query([
@@ -209,11 +202,11 @@ public function testApiCanDeletePrivateClient(): void
'client_secret' => 'testsecret',
]);
- $client->request('DELETE', '/api/client?'.$query);
+ $this->client->request('DELETE', '/api/client?'.$query);
self::assertResponseStatusCodeSame(204);
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseStatusCodeSame(401);
@@ -226,11 +219,10 @@ public function testApiCanDeletePrivateClient(): void
public function testAdminApiCanAccessClientStats(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client, scopes: 'admin:oauth_clients:read');
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'admin:oauth_clients:read');
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -242,11 +234,11 @@ public function testAdminApiCanAccessClientStats(): void
'resolution' => 'day',
]);
- $client->request('GET', '/api/clients/stats?'.$query, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/stats?'.$query, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('data', $jsonData);
@@ -268,11 +260,10 @@ public function testAdminApiCanAccessClientStats(): void
public function testAdminApiCannotAccessClientStatsWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -284,11 +275,11 @@ public function testAdminApiCannotAccessClientStatsWithoutScope(): void
'resolution' => 'day',
]);
- $client->request('GET', '/api/clients/stats?'.$query, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/stats?'.$query, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('type', $jsonData);
self::assertEquals('https://tools.ietf.org/html/rfc2616#section-10', $jsonData['type']);
@@ -301,11 +292,10 @@ public function testAdminApiCannotAccessClientStatsWithoutScope(): void
public function testAdminApiCanAccessClientList(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client, scopes: 'admin:oauth_clients:read');
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'admin:oauth_clients:read');
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -313,11 +303,11 @@ public function testAdminApiCanAccessClientList(): void
$token = 'Bearer '.$jsonData['access_token'];
- $client->request('GET', '/api/clients', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('items', $jsonData);
@@ -363,11 +353,10 @@ public function testAdminApiCanAccessClientList(): void
public function testAdminApiCannotAccessClientListWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -375,11 +364,11 @@ public function testAdminApiCannotAccessClientListWithoutScope(): void
$token = 'Bearer '.$jsonData['access_token'];
- $client->request('GET', '/api/clients', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('type', $jsonData);
@@ -393,11 +382,10 @@ public function testAdminApiCannotAccessClientListWithoutScope(): void
public function testAdminApiCanAccessClientByIdentifier(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client, scopes: 'admin:oauth_clients:read');
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'admin:oauth_clients:read');
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -405,11 +393,11 @@ public function testAdminApiCanAccessClientByIdentifier(): void
$token = 'Bearer '.$jsonData['access_token'];
- $client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('identifier', $jsonData);
@@ -439,11 +427,10 @@ public function testAdminApiCanAccessClientByIdentifier(): void
public function testApiCanRevokeTokens(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $tokenData = self::getAuthorizationCodeTokenResponse($client, scopes: 'admin:oauth_clients:read');
+ $tokenData = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'admin:oauth_clients:read');
self::assertResponseIsSuccessful();
self::assertIsArray($tokenData);
@@ -452,18 +439,18 @@ public function testApiCanRevokeTokens(): void
$token = 'Bearer '.$tokenData['access_token'];
- $client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $client->request('POST', '/api/revoke', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', '/api/revoke', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
- $client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(401);
- $jsonData = self::getRefreshTokenResponse($client, $tokenData['refresh_token']);
+ $jsonData = self::getRefreshTokenResponse($this->client, $tokenData['refresh_token']);
self::assertResponseStatusCodeSame(401);
@@ -480,11 +467,10 @@ public function testApiCanRevokeTokens(): void
public function testAdminApiCannotAccessClientByIdentifierWithoutScope(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', isAdmin: true));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -492,11 +478,11 @@ public function testAdminApiCannotAccessClientByIdentifierWithoutScope(): void
$token = 'Bearer '.$jsonData['access_token'];
- $client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/clients/testclient', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('type', $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Admin/PostPurgeApiTest.php b/tests/Functional/Controller/Api/Post/Admin/PostPurgeApiTest.php
index 4c4021761..24c7b139e 100644
--- a/tests/Functional/Controller/Api/Post/Admin/PostPurgeApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Admin/PostPurgeApiTest.php
@@ -10,82 +10,76 @@ class PostPurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeArticlePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeArticlePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminCannotPurgeArticlePost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPurgeArticlePost(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotPurgeImagePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
$post = $this->createPost('test image', imageDto: $imageDto, magazine: $magazine);
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotPurgeImagePostWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user', isAdmin: true);
@@ -93,18 +87,17 @@ public function testApiCannotPurgeImagePostWithoutScope(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonAdminCannotPurgeImagePost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -113,18 +106,17 @@ public function testApiNonAdminCannotPurgeImagePost(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPurgeImagePost(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -133,12 +125,12 @@ public function testApiCanPurgeImagePost(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post/{$post->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
}
diff --git a/tests/Functional/Controller/Api/Post/Comment/Admin/PostCommentPurgeApiTest.php b/tests/Functional/Controller/Api/Post/Comment/Admin/PostCommentPurgeApiTest.php
index b1fa5fdc9..3047b01bc 100644
--- a/tests/Functional/Controller/Api/Post/Comment/Admin/PostCommentPurgeApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/Admin/PostCommentPurgeApiTest.php
@@ -11,14 +11,13 @@ class PostCommentPurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeCommentAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
$comment = $this->createPostComment('test comment', $post);
$commentRepository = $this->getService(PostCommentRepository::class);
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge");
self::assertResponseStatusCodeSame(401);
$comment = $commentRepository->find($comment->getId());
@@ -27,7 +26,6 @@ public function testApiCannotPurgeCommentAnonymous(): void
public function testApiCannotPurgeCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -36,12 +34,12 @@ public function testApiCannotPurgeCommentWithoutScope(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -50,7 +48,6 @@ public function testApiCannotPurgeCommentWithoutScope(): void
public function testApiNonAdminCannotPurgeComment(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -60,12 +57,12 @@ public function testApiNonAdminCannotPurgeComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -74,7 +71,6 @@ public function testApiNonAdminCannotPurgeComment(): void
public function testApiCanPurgeComment(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -84,12 +80,12 @@ public function testApiCanPurgeComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
@@ -98,7 +94,6 @@ public function testApiCanPurgeComment(): void
public function testApiCannotPurgeImageCommentAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
@@ -107,7 +102,7 @@ public function testApiCannotPurgeImageCommentAnonymous(): void
$commentRepository = $this->getService(PostCommentRepository::class);
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge");
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge");
self::assertResponseStatusCodeSame(401);
$comment = $commentRepository->find($comment->getId());
@@ -116,7 +111,6 @@ public function testApiCannotPurgeImageCommentAnonymous(): void
public function testApiCannotPurgeImageCommentWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user', isAdmin: true);
@@ -127,12 +121,12 @@ public function testApiCannotPurgeImageCommentWithoutScope(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -141,7 +135,6 @@ public function testApiCannotPurgeImageCommentWithoutScope(): void
public function testApiNonAdminCannotPurgeImageComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -152,12 +145,12 @@ public function testApiNonAdminCannotPurgeImageComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
$comment = $commentRepository->find($comment->getId());
@@ -166,7 +159,6 @@ public function testApiNonAdminCannotPurgeImageComment(): void
public function testApiCanPurgeImageComment(): void
{
- $client = self::createClient();
$admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -177,12 +169,12 @@ public function testApiCanPurgeImageComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:post_comment:purge');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:post_comment:purge');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/admin/post-comment/{$comment->getId()}/purge", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
diff --git a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetAdultApiTest.php b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetAdultApiTest.php
index d62a2c49e..699dbe1bb 100644
--- a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetAdultApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetAdultApiTest.php
@@ -14,20 +14,19 @@ class PostCommentSetAdultApiTest extends WebTestCase
{
public function testApiCannotSetCommentAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('a post', $magazine);
$comment = $this->createPostComment('test comment', $post);
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true");
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSetCommentAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('user2');
$post = $this->createPost('a post', magazine: $magazine);
@@ -36,22 +35,22 @@ public function testApiCannotSetCommentAdultWithoutScope(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotSetCommentAdult(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
@@ -59,20 +58,20 @@ public function testApiNonModCannotSetCommentAdult(): void
$comment = $this->createPostComment('test comment', $post, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post', magazine: $magazine);
@@ -81,18 +80,19 @@ public function testApiCanSetCommentAdult(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -101,7 +101,6 @@ public function testApiCanSetCommentAdult(): void
public function testApiCannotUnsetCommentAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('a post', $magazine);
$comment = $this->createPostComment('test comment', $post);
@@ -111,15 +110,15 @@ public function testApiCannotUnsetCommentAdultAnonymous(): void
$entityManager->persist($comment);
$entityManager->flush();
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false");
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUnsetCommentAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('user2');
$post = $this->createPost('a post', magazine: $magazine);
@@ -128,6 +127,7 @@ public function testApiCannotUnsetCommentAdultWithoutScope(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -136,19 +136,18 @@ public function testApiCannotUnsetCommentAdultWithoutScope(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotUnsetCommentAdult(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
@@ -161,20 +160,20 @@ public function testApiNonModCannotUnsetCommentAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnsetCommentAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post', magazine: $magazine);
@@ -183,6 +182,7 @@ public function testApiCanUnsetCommentAdult(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -193,15 +193,15 @@ public function testApiCanUnsetCommentAdult(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetLanguageApiTest.php b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetLanguageApiTest.php
index 71611096b..5780563e5 100644
--- a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetLanguageApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentSetLanguageApiTest.php
@@ -12,19 +12,18 @@ class PostCommentSetLanguageApiTest extends WebTestCase
{
public function testApiCannotSetCommentLanguageAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de");
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotSetCommentLanguageWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('user2');
$post = $this->createPost('a post', magazine: $magazine);
@@ -33,42 +32,42 @@ public function testApiCannotSetCommentLanguageWithoutScope(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotSetCommentLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetCommentLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post', magazine: $magazine);
@@ -77,18 +76,19 @@ public function testApiCanSetCommentLanguage(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentTrashApiTest.php b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentTrashApiTest.php
index 980d2519f..4623d156a 100644
--- a/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentTrashApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/Moderate/PostCommentTrashApiTest.php
@@ -13,20 +13,19 @@ class PostCommentTrashApiTest extends WebTestCase
{
public function testApiCannotTrashCommentAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('a post', $magazine);
$comment = $this->createPostComment('test comment', $post);
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash");
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotTrashCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('user2');
$post = $this->createPost('a post', magazine: $magazine);
@@ -35,22 +34,22 @@ public function testApiCannotTrashCommentWithoutScope(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotTrashComment(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
@@ -58,20 +57,20 @@ public function testApiNonModCannotTrashComment(): void
$comment = $this->createPostComment('test comment', $post, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanTrashComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByName('acme');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post', magazine: $magazine);
@@ -80,18 +79,19 @@ public function testApiCanTrashComment(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -102,7 +102,6 @@ public function testApiCanTrashComment(): void
public function testApiCannotRestoreCommentAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('a post', $magazine);
$comment = $this->createPostComment('test comment', $post);
@@ -110,14 +109,13 @@ public function testApiCannotRestoreCommentAnonymous(): void
$postCommentManager = $this->getService(PostCommentManager::class);
$postCommentManager->trash($this->getUserByUsername('user'), $comment);
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore");
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRestoreCommentWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
@@ -128,19 +126,18 @@ public function testApiCannotRestoreCommentWithoutScope(): void
$postCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiNonModCannotRestoreComment(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('user2');
@@ -151,20 +148,20 @@ public function testApiNonModCannotRestoreComment(): void
$postCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRestoreComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post', magazine: $magazine);
@@ -173,21 +170,22 @@ public function testApiCanRestoreComment(): void
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$postCommentManager = $this->getService(PostCommentManager::class);
$postCommentManager->trash($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post_comment:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post_comment:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post-comment/{$comment->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentCreateApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentCreateApiTest.php
index ab823a4d1..fb12eee9b 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentCreateApiTest.php
@@ -11,7 +11,6 @@ class PostCommentCreateApiTest extends WebTestCase
{
public function testApiCannotCreateCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -20,7 +19,7 @@ public function testApiCannotCreateCommentAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments",
parameters: $comment
);
@@ -30,7 +29,6 @@ public function testApiCannotCreateCommentAnonymous(): void
public function testApiCannotCreateCommentWithoutScope(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -40,12 +38,12 @@ public function testApiCannotCreateCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
@@ -55,7 +53,6 @@ public function testApiCannotCreateCommentWithoutScope(): void
public function testApiCanCreateComment(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -66,18 +63,18 @@ public function testApiCanCreateComment(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -97,7 +94,6 @@ public function testApiCanCreateComment(): void
public function testApiCannotCreateCommentReplyAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -107,7 +103,7 @@ public function testApiCannotCreateCommentReplyAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply",
parameters: $comment
);
@@ -117,7 +113,6 @@ public function testApiCannotCreateCommentReplyAnonymous(): void
public function testApiCannotCreateCommentReplyWithoutScope(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -128,12 +123,12 @@ public function testApiCannotCreateCommentReplyWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
@@ -143,7 +138,6 @@ public function testApiCannotCreateCommentReplyWithoutScope(): void
public function testApiCanCreateCommentReply(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -155,18 +149,18 @@ public function testApiCanCreateCommentReply(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest(
+ $this->client->jsonRequest(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply",
parameters: $comment, server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -186,7 +180,6 @@ public function testApiCanCreateCommentReply(): void
public function testApiCannotCreateImageCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -200,7 +193,7 @@ public function testApiCannotCreateImageCommentAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image]
);
@@ -210,7 +203,6 @@ public function testApiCannotCreateImageCommentAnonymous(): void
public function testApiCannotCreateImageCommentWithoutScope(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -225,12 +217,12 @@ public function testApiCannotCreateImageCommentWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -241,7 +233,6 @@ public function testApiCannotCreateImageCommentWithoutScope(): void
public function testApiCanCreateImageComment(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = [
@@ -257,19 +248,19 @@ public function testApiCanCreateImageComment(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -289,7 +280,6 @@ public function testApiCanCreateImageComment(): void
public function testApiCannotCreateImageCommentReplyAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -304,7 +294,7 @@ public function testApiCannotCreateImageCommentReplyAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image]
);
@@ -314,7 +304,6 @@ public function testApiCannotCreateImageCommentReplyAnonymous(): void
public function testApiCannotCreateImageCommentReplyWithoutScope(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -329,12 +318,12 @@ public function testApiCannotCreateImageCommentReplyWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -345,7 +334,6 @@ public function testApiCannotCreateImageCommentReplyWithoutScope(): void
public function testApiCanCreateImageCommentReply(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$postComment = $this->createPostComment('a comment', $post);
@@ -362,19 +350,19 @@ public function testApiCanCreateImageCommentReply(): void
self::createOAuth2AuthCodeClient();
$user = $this->getUserByUsername('user');
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/posts/{$post->getId()}/comments/{$postComment->getId()}/reply/image",
parameters: $comment, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentDeleteApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentDeleteApiTest.php
index afecb94ce..557547e7a 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentDeleteApiTest.php
@@ -11,55 +11,51 @@ class PostCommentDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
- $client->request('DELETE', "/api/post-comments/{$comment->getId()}");
+ $this->client->request('DELETE', "/api/post-comments/{$comment->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user2);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -67,12 +63,12 @@ public function testApiCanDeleteComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
@@ -81,7 +77,6 @@ public function testApiCanDeleteComment(): void
public function testApiCanSoftDeleteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -90,12 +85,12 @@ public function testApiCanSoftDeleteComment(): void
$commentRepository = $this->getService(PostCommentRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$comment = $commentRepository->find($comment->getId());
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentReportApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentReportApiTest.php
index 2bb4daa61..7b5ed603c 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentReportApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentReportApiTest.php
@@ -11,7 +11,6 @@ class PostCommentReportApiTest extends WebTestCase
{
public function testApiCannotReportCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
@@ -19,14 +18,13 @@ public function testApiCannotReportCommentAnonymous(): void
'reason' => 'This comment breaks the rules!',
];
- $client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report);
+ $this->client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotReportCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -36,19 +34,18 @@ public function testApiCannotReportCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanReportOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post');
@@ -61,12 +58,12 @@ public function testApiCanReportOtherUsersComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$report = $reportRepository->findBySubject($comment);
@@ -77,7 +74,6 @@ public function testApiCanReportOtherUsersComment(): void
public function testApiCanReportOwnComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -89,12 +85,12 @@ public function testApiCanReportOwnComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/post-comments/{$comment->getId()}/report", $report, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$report = $reportRepository->findBySubject($comment);
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentRetrieveApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentRetrieveApiTest.php
index a483e4b2b..849e2613f 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentRetrieveApiTest.php
@@ -12,15 +12,14 @@ class PostCommentRetrieveApiTest extends WebTestCase
{
public function testApiCanGetPostCommentsAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$this->createPostComment("test parent comment {$i}", $post);
}
- $client->request('GET', "/api/posts/{$post->getId()}/comments");
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -56,7 +55,7 @@ public function testApiCanGetPostCommentsAnonymous(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -65,19 +64,17 @@ public function testApiCanGetPostCommentsAnonymous(): void
public function testApiCannotGetPostCommentsByPreferredLangAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$this->createPostComment("test parent comment {$i}", $post);
}
- $client->request('GET', "/api/posts/{$post->getId()}/comments?usePreferredLangs=true");
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?usePreferredLangs=true");
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetPostCommentsByPreferredLang(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$this->createPostComment("test parent comment {$i}", $post);
@@ -93,14 +90,14 @@ public function testApiCanGetPostCommentsByPreferredLang(): void
$entityManager->persist($user);
$entityManager->flush();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?usePreferredLangs=true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?usePreferredLangs=true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -137,7 +134,7 @@ public function testApiCanGetPostCommentsByPreferredLang(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -146,7 +143,6 @@ public function testApiCanGetPostCommentsByPreferredLang(): void
public function testApiCanGetPostCommentsWithLanguageAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$this->createPostComment("test parent comment {$i}", $post);
@@ -154,9 +150,9 @@ public function testApiCanGetPostCommentsWithLanguageAnonymous(): void
$this->createPostComment("test dutch comment {$i}", $post, lang: 'nl');
}
- $client->request('GET', "/api/posts/{$post->getId()}/comments?lang[]=en&lang[]=de");
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?lang[]=en&lang[]=de");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -192,7 +188,7 @@ public function testApiCanGetPostCommentsWithLanguageAnonymous(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -201,7 +197,6 @@ public function testApiCanGetPostCommentsWithLanguageAnonymous(): void
public function testApiCanGetPostCommentsWithLanguage(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$this->createPostComment("test parent comment {$i}", $post);
@@ -210,14 +205,14 @@ public function testApiCanGetPostCommentsWithLanguage(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?lang[]=en&lang[]=de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?lang[]=en&lang[]=de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -254,7 +249,7 @@ public function testApiCanGetPostCommentsWithLanguage(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -263,7 +258,6 @@ public function testApiCanGetPostCommentsWithLanguage(): void
public function testApiCanGetPostComments(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
@@ -271,14 +265,14 @@ public function testApiCanGetPostComments(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -325,7 +319,6 @@ public function testApiCanGetPostComments(): void
public function testApiCanGetPostCommentsWithChildren(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 5; ++$i) {
$comment = $this->createPostComment("test parent comment {$i}", $post);
@@ -333,14 +326,14 @@ public function testApiCanGetPostCommentsWithChildren(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -380,7 +373,7 @@ public function testApiCanGetPostCommentsWithChildren(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -389,7 +382,6 @@ public function testApiCanGetPostCommentsWithChildren(): void
public function testApiCanGetPostCommentsLimitedDepth(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
for ($i = 0; $i < 2; ++$i) {
$comment = $this->createPostComment("test parent comment {$i}", $post);
@@ -400,14 +392,14 @@ public function testApiCanGetPostCommentsLimitedDepth(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?d=3", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?d=3", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -455,7 +447,7 @@ public function testApiCanGetPostCommentsLimitedDepth(): void
self::assertNull($comment['isFavourited']);
self::assertNull($comment['userVote']);
self::assertNull($comment['apId']);
- self::assertNull($comment['tags']);
+ self::assertEmpty($comment['tags']);
self::assertNull($comment['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $comment['lastActive'], 'lastActive date format invalid');
@@ -464,7 +456,6 @@ public function testApiCanGetPostCommentsLimitedDepth(): void
public function testApiCanGetPostCommentsNewest(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -481,14 +472,14 @@ public function testApiCanGetPostCommentsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -514,7 +505,6 @@ public function testApiCanGetPostCommentsNewest(): void
public function testApiCanGetPostCommentsOldest(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -531,14 +521,14 @@ public function testApiCanGetPostCommentsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -564,7 +554,6 @@ public function testApiCanGetPostCommentsOldest(): void
public function testApiCanGetPostCommentsActive(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -581,14 +570,14 @@ public function testApiCanGetPostCommentsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -614,7 +603,6 @@ public function testApiCanGetPostCommentsActive(): void
public function testApiCanGetPostCommentsHot(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -626,14 +614,14 @@ public function testApiCanGetPostCommentsHot(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/posts/{$post->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/posts/{$post->getId()}/comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -662,13 +650,12 @@ public function testApiCanGetPostCommentsHot(): void
public function testApiCanGetPostCommentByIdAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
$comment = $this->createPostComment('test parent comment', $post);
- $client->request('GET', "/api/post-comments/{$comment->getId()}");
+ $this->client->request('GET', "/api/post-comments/{$comment->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -694,7 +681,7 @@ public function testApiCanGetPostCommentByIdAnonymous(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
@@ -702,19 +689,18 @@ public function testApiCanGetPostCommentByIdAnonymous(): void
public function testApiCanGetPostCommentById(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
$comment = $this->createPostComment('test parent comment', $post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/post-comments/{$comment->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -741,7 +727,7 @@ public function testApiCanGetPostCommentById(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
@@ -749,7 +735,6 @@ public function testApiCanGetPostCommentById(): void
public function testApiCanGetPostCommentByIdWithDepth(): void
{
- $client = self::createClient();
$post = $this->createPost('test post');
$comment = $this->createPostComment('test parent comment', $post);
$parent = $comment;
@@ -758,14 +743,14 @@ public function testApiCanGetPostCommentByIdWithDepth(): void
}
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/post-comments/{$comment->getId()}?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/post-comments/{$comment->getId()}?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -792,7 +777,7 @@ public function testApiCanGetPostCommentByIdWithDepth(): void
self::assertNull($jsonData['isFavourited']);
self::assertNull($jsonData['userVote']);
self::assertNull($jsonData['apId']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['editedAt']);
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentUpdateApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentUpdateApiTest.php
index a6ad1b91b..4da412062 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentUpdateApiTest.php
@@ -10,7 +10,6 @@ class PostCommentUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
@@ -20,14 +19,13 @@ public function testApiCannotUpdateCommentAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update);
+ $this->client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -39,19 +37,18 @@ public function testApiCannotUpdateCommentWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$user2 = $this->getUserByUsername('other');
$post = $this->createPost('a post');
@@ -64,19 +61,18 @@ public function testApiCannotUpdateOtherUsersComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -92,15 +88,15 @@ public function testApiCanUpdateComment(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}?d=2", $update, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post-comments/{$comment->getId()}?d=2", $update, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/PostCommentVoteApiTest.php b/tests/Functional/Controller/Api/Post/Comment/PostCommentVoteApiTest.php
index 8daaed846..7dce41690 100644
--- a/tests/Functional/Controller/Api/Post/Comment/PostCommentVoteApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/PostCommentVoteApiTest.php
@@ -12,50 +12,47 @@ class PostCommentVoteApiTest extends WebTestCase
{
public function testApiCannotUpvoteCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1");
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpvoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpvoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -68,77 +65,63 @@ public function testApiCanUpvoteComment(): void
public function testApiCannotDownvoteCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1");
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDownvoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
- public function testApiCanDownvoteComment(): void
+ public function testApiCannotDownvoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
- self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
-
- self::assertIsArray($jsonData);
- self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
- self::assertSame(0, $jsonData['uv']);
- self::assertSame(1, $jsonData['dv']);
- self::assertSame(0, $jsonData['favourites']);
- self::assertSame(-1, $jsonData['userVote']);
- self::assertFalse($jsonData['isFavourited']);
+ self::assertResponseStatusCodeSame(400);
}
public function testApiCannotRemoveVoteCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
$voteManager = $this->getService(VoteManager::class);
$voteManager->vote(1, $comment, $this->getUserByUsername('user'), rateLimit: false);
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0");
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotRemoveVoteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -147,19 +130,18 @@ public function testApiCannotRemoveVoteCommentWithoutScope(): void
$voteManager->vote(1, $comment, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRemoveVoteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -168,15 +150,15 @@ public function testApiCanRemoveVoteComment(): void
$voteManager->vote(1, $comment, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -189,50 +171,47 @@ public function testApiCanRemoveVoteComment(): void
public function testApiCannotFavouriteCommentAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post);
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite");
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotFavouriteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanFavouriteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
@@ -245,7 +224,6 @@ public function testApiCanFavouriteComment(): void
public function testApiCannotUnfavouriteCommentWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -254,19 +232,18 @@ public function testApiCannotUnfavouriteCommentWithoutScope(): void
$favouriteManager->toggle($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnfavouriteComment(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$comment = $this->createPostComment('test comment', $post, $user);
@@ -275,15 +252,15 @@ public function testApiCanUnfavouriteComment(): void
$favouriteManager->toggle($user, $comment);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post_comment:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post_comment:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('PUT', "/api/post-comments/{$comment->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_COMMENT_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/Comment/UserPostCommentRetrieveApiTest.php b/tests/Functional/Controller/Api/Post/Comment/UserPostCommentRetrieveApiTest.php
index cbd266e6e..01e67dee6 100644
--- a/tests/Functional/Controller/Api/Post/Comment/UserPostCommentRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Comment/UserPostCommentRetrieveApiTest.php
@@ -12,16 +12,15 @@ class UserPostCommentRetrieveApiTest extends WebTestCase
{
public function testApiCanGetUserPostCommentsAnonymous(): void
{
- $client = self::createClient();
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine);
$comment = $this->createPostComment('test comment', $post);
$user = $post->user;
- $client->request('GET', "/api/users/{$user->getId()}/post-comments");
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -47,7 +46,6 @@ public function testApiCanGetUserPostCommentsAnonymous(): void
public function testApiCanGetUserPostComments(): void
{
- $client = self::createClient();
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine);
@@ -55,14 +53,14 @@ public function testApiCanGetUserPostComments(): void
$user = $post->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -88,7 +86,6 @@ public function testApiCanGetUserPostComments(): void
public function testApiCanGetUserPostCommentsDepth(): void
{
- $client = self::createClient();
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine);
@@ -99,14 +96,14 @@ public function testApiCanGetUserPostCommentsDepth(): void
$user = $post->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments?d=2", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -135,7 +132,6 @@ public function testApiCanGetUserPostCommentsDepth(): void
public function testApiCanGetUserPostCommentsNewest(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -153,14 +149,14 @@ public function testApiCanGetUserPostCommentsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -186,7 +182,6 @@ public function testApiCanGetUserPostCommentsNewest(): void
public function testApiCanGetUserPostCommentsOldest(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -204,14 +199,14 @@ public function testApiCanGetUserPostCommentsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -237,7 +232,6 @@ public function testApiCanGetUserPostCommentsOldest(): void
public function testApiCanGetUserPostCommentsActive(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -255,14 +249,14 @@ public function testApiCanGetUserPostCommentsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -288,7 +282,6 @@ public function testApiCanGetUserPostCommentsActive(): void
public function testApiCanGetUserPostCommentsHot(): void
{
- $client = self::createClient();
$post = $this->createPost('post');
$first = $this->createPostComment('first', $post);
$second = $this->createPostComment('second', $post);
@@ -301,14 +294,14 @@ public function testApiCanGetUserPostCommentsHot(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments?sort=hot", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -337,7 +330,6 @@ public function testApiCanGetUserPostCommentsHot(): void
public function testApiCanGetUserPostCommentsWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine);
@@ -345,14 +337,14 @@ public function testApiCanGetUserPostCommentsWithUserVoteStatus(): void
$user = $post->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$user->getId()}/post-comments", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$user->getId()}/post-comments", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -375,7 +367,7 @@ public function testApiCanGetUserPostCommentsWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(0, $jsonData['items'][0]['childCount']);
self::assertIsArray($jsonData['items'][0]['children']);
self::assertEmpty($jsonData['items'][0]['children']);
diff --git a/tests/Functional/Controller/Api/Post/MagazinePostRetrieveApiTest.php b/tests/Functional/Controller/Api/Post/MagazinePostRetrieveApiTest.php
index 46d7e5bab..5ae962a3d 100644
--- a/tests/Functional/Controller/Api/Post/MagazinePostRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Post/MagazinePostRetrieveApiTest.php
@@ -13,15 +13,14 @@ class MagazinePostRetrieveApiTest extends WebTestCase
{
public function testApiCanGetMagazinePostsAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->createPost('another post', magazine: $magazine);
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts");
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -44,21 +43,20 @@ public function testApiCanGetMagazinePostsAnonymous(): void
public function testApiCanGetMagazinePosts(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -80,7 +78,6 @@ public function testApiCanGetMagazinePosts(): void
public function testApiCanGetMagazinePostsPinnedFirst(): void
{
- $client = self::createClient();
$voteManager = $this->getService(VoteManager::class);
$postManager = $this->getService(PostManager::class);
$voter = $this->getUserByUsername('voter');
@@ -95,14 +92,14 @@ public function testApiCanGetMagazinePostsPinnedFirst(): void
$postManager->pin($third);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -137,7 +134,6 @@ public function testApiCanGetMagazinePostsPinnedFirst(): void
public function testApiCanGetMagazinePostsNewest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -154,14 +150,14 @@ public function testApiCanGetMagazinePostsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -187,7 +183,6 @@ public function testApiCanGetMagazinePostsNewest(): void
public function testApiCanGetMagazinePostsOldest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -204,14 +199,14 @@ public function testApiCanGetMagazinePostsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -237,7 +232,6 @@ public function testApiCanGetMagazinePostsOldest(): void
public function testApiCanGetMagazinePostsCommented(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$this->createPostComment('comment 1', $first);
$this->createPostComment('comment 2', $first);
@@ -247,14 +241,14 @@ public function testApiCanGetMagazinePostsCommented(): void
$magazine = $first->magazine;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -283,7 +277,6 @@ public function testApiCanGetMagazinePostsCommented(): void
public function testApiCanGetMagazinePostsActive(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -300,14 +293,14 @@ public function testApiCanGetMagazinePostsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -333,7 +326,6 @@ public function testApiCanGetMagazinePostsActive(): void
public function testApiCanGetMagazinePostsTop(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -345,14 +337,14 @@ public function testApiCanGetMagazinePostsTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -381,21 +373,20 @@ public function testApiCanGetMagazinePostsTop(): void
public function testApiCanGetMagazinePostsWithUserVoteStatus(): void
{
- $client = self::createClient();
$first = $this->createPost('an post');
$this->createPostComment('up the ranking', $first);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/magazine/{$magazine->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -417,7 +408,7 @@ public function testApiCanGetMagazinePostsWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(0, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
diff --git a/tests/Functional/Controller/Api/Post/Moderate/PostPinApiTest.php b/tests/Functional/Controller/Api/Post/Moderate/PostPinApiTest.php
index 287145973..35e00b431 100644
--- a/tests/Functional/Controller/Api/Post/Moderate/PostPinApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Moderate/PostPinApiTest.php
@@ -11,64 +11,60 @@ class PostPinApiTest extends WebTestCase
{
public function testApiCannotPinPostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotPinPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotPinPostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanPinPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -82,7 +78,7 @@ public function testApiCanPinPost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -102,20 +98,18 @@ public function testApiCanPinPost(): void
public function testApiCannotUnpinPostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
$postManager = $this->getService(PostManager::class);
$postManager->pin($post);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotUnpinPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -124,18 +118,17 @@ public function testApiNonModeratorCannotUnpinPost(): void
$postManager->pin($post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUnpinPostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -144,18 +137,17 @@ public function testApiCannotUnpinPostWithoutScope(): void
$postManager->pin($post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUnpinPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -164,14 +156,14 @@ public function testApiCanUnpinPost(): void
$postManager->pin($post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:pin');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:pin');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/pin", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -185,7 +177,7 @@ public function testApiCanUnpinPost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/Moderate/PostSetAdultApiTest.php b/tests/Functional/Controller/Api/Post/Moderate/PostSetAdultApiTest.php
index d3a958519..76ba12565 100644
--- a/tests/Functional/Controller/Api/Post/Moderate/PostSetAdultApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Moderate/PostSetAdultApiTest.php
@@ -13,69 +13,67 @@ class PostSetAdultApiTest extends WebTestCase
{
public function testApiCannotSetPostAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetPostAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetPostAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetPostAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/true", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -89,7 +87,7 @@ public function testApiCanSetPostAdult(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -110,7 +108,6 @@ public function testApiCanSetPostAdult(): void
public function testApiCannotSetPostNotAdultAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
@@ -119,13 +116,12 @@ public function testApiCannotSetPostNotAdultAnonymous(): void
$entityManager->persist($post);
$entityManager->flush();
- $client->request('PUT', "/api/moderate/post/{$post->getId()}/adult/false");
+ $this->client->request('PUT', "/api/moderate/post/{$post->getId()}/adult/false");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetPostNotAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -136,18 +132,17 @@ public function testApiNonModeratorCannotSetPostNotAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetPostNotAdultWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -158,25 +153,26 @@ public function testApiCannotSetPostNotAdultWithoutScope(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanSetPostNotAdult(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$entityManager = $this->getService(EntityManagerInterface::class);
@@ -185,14 +181,14 @@ public function testApiCanSetPostNotAdult(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:set_adult');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:set_adult');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/adult/false", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -206,7 +202,7 @@ public function testApiCanSetPostNotAdult(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/Moderate/PostSetLanguageApiTest.php b/tests/Functional/Controller/Api/Post/Moderate/PostSetLanguageApiTest.php
index c428c42b7..c0e0739b6 100644
--- a/tests/Functional/Controller/Api/Post/Moderate/PostSetLanguageApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Moderate/PostSetLanguageApiTest.php
@@ -12,100 +12,99 @@ class PostSetLanguageApiTest extends WebTestCase
{
public function testApiCannotSetPostLanguageAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotSetPostLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetPostLanguageWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotSetPostLanguageInvalid(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/fake", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/fake", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/ac", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/ac", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/aaa", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/aaa", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/a", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/a", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
public function testApiCanSetPostLanguage(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/de", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -119,7 +118,7 @@ public function testApiCanSetPostLanguage(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('de', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -140,25 +139,26 @@ public function testApiCanSetPostLanguage(): void
public function testApiCanSetPostLanguage3Letter(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:language');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:language');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/elx", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/elx", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -172,7 +172,7 @@ public function testApiCanSetPostLanguage3Letter(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals('elx', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/Moderate/PostTrashApiTest.php b/tests/Functional/Controller/Api/Post/Moderate/PostTrashApiTest.php
index e0399e570..76b028325 100644
--- a/tests/Functional/Controller/Api/Post/Moderate/PostTrashApiTest.php
+++ b/tests/Functional/Controller/Api/Post/Moderate/PostTrashApiTest.php
@@ -13,69 +13,67 @@ class PostTrashApiTest extends WebTestCase
{
public function testApiCannotTrashPostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotTrashPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotTrashPostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanTrashPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/trash", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -89,7 +87,7 @@ public function testApiCanTrashPost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -110,7 +108,6 @@ public function testApiCanTrashPost(): void
public function testApiCannotRestorePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
$post = $this->createPost('test post', magazine: $magazine);
@@ -118,13 +115,12 @@ public function testApiCannotRestorePostAnonymous(): void
$postManager = $this->getService(PostManager::class);
$postManager->trash($user, $post);
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore");
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore");
self::assertResponseStatusCodeSame(401);
}
public function testApiNonModeratorCannotRestorePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
@@ -133,18 +129,17 @@ public function testApiNonModeratorCannotRestorePost(): void
$postManager->trash($user, $post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRestorePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme', $user);
$post = $this->createPost('test post', user: $user, magazine: $magazine);
@@ -153,39 +148,40 @@ public function testApiCannotRestorePostWithoutScope(): void
$postManager->trash($user, $post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRestorePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
$magazineManager = $this->getService(MagazineManager::class);
$moderator = new ModeratorDto($magazine);
$moderator->user = $user;
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
$postManager = $this->getService(PostManager::class);
$postManager->trash($user, $post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post:trash');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post:trash');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/moderate/post/{$post->getId()}/restore", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -199,7 +195,7 @@ public function testApiCanRestorePost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/PostCreateApiTest.php b/tests/Functional/Controller/Api/Post/PostCreateApiTest.php
index a52dbd81d..28d8058f6 100644
--- a/tests/Functional/Controller/Api/Post/PostCreateApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostCreateApiTest.php
@@ -11,7 +11,6 @@ class PostCreateApiTest extends WebTestCase
{
public function testApiCannotCreatePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
'body' => 'This is a microblog',
@@ -19,13 +18,12 @@ public function testApiCannotCreatePostAnonymous(): void
'isAdult' => false,
];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotCreatePostWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
'body' => 'No scope post',
@@ -34,18 +32,17 @@ public function testApiCannotCreatePostWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanCreatePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
@@ -55,14 +52,14 @@ public function testApiCanCreatePost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -98,7 +95,6 @@ public function testApiCanCreatePost(): void
public function testApiCannotCreateImagePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
'alt' => 'It\'s kibby!',
@@ -110,7 +106,7 @@ public function testApiCannotCreateImagePostAnonymous(): void
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/posts/image",
parameters: $postRequest, files: ['uploadImage' => $image],
);
@@ -119,7 +115,6 @@ public function testApiCannotCreateImagePostAnonymous(): void
public function testApiCannotCreateImagePostWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
'alt' => 'It\'s kibby!',
@@ -132,12 +127,12 @@ public function testApiCannotCreateImagePostWithoutScope(): void
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/posts/image",
parameters: $postRequest, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
@@ -147,7 +142,6 @@ public function testApiCannotCreateImagePostWithoutScope(): void
public function testApiCanCreateImagePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
@@ -157,22 +151,22 @@ public function testApiCanCreateImagePost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request(
+ $this->client->request(
'POST', "/api/magazine/{$magazine->getId()}/posts/image",
parameters: $postRequest, files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $token]
);
self::assertResponseStatusCodeSame(201);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
self::assertNotNull($jsonData['postId']);
@@ -188,7 +182,7 @@ public function testApiCanCreateImagePost(): void
self::assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $jsonData['image']['filePath']);
self::assertEquals('It\'s kibby!', $jsonData['image']['altText']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -208,7 +202,6 @@ public function testApiCanCreateImagePost(): void
public function testApiCannotCreatePostWithoutMagazine(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$invalidId = $magazine->getId() + 1;
$postRequest = [
@@ -217,21 +210,20 @@ public function testApiCannotCreatePostWithoutMagazine(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$invalidId}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$invalidId}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(404);
- $client->request('POST', "/api/magazine/{$invalidId}/posts/image", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/magazine/{$invalidId}/posts/image", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(404);
}
public function testApiCannotCreatePostWithoutBodyOrImage(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$postRequest = [
'lang' => 'en',
@@ -239,15 +231,15 @@ public function testApiCannotCreatePostWithoutBodyOrImage(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:create');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:create');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/magazine/{$magazine->getId()}/posts", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
- $client->request('POST', "/api/magazine/{$magazine->getId()}/posts/image", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('POST', "/api/magazine/{$magazine->getId()}/posts/image", parameters: $postRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(400);
}
}
diff --git a/tests/Functional/Controller/Api/Post/PostDeleteApiTest.php b/tests/Functional/Controller/Api/Post/PostDeleteApiTest.php
index f17540eb5..e03454b67 100644
--- a/tests/Functional/Controller/Api/Post/PostDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostDeleteApiTest.php
@@ -10,81 +10,75 @@ class PostDeleteApiTest extends WebTestCase
{
public function testApiCannotDeletePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost(body: 'test for deletion', magazine: $magazine);
- $client->request('DELETE', "/api/post/{$post->getId()}");
+ $this->client->request('DELETE', "/api/post/{$post->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeletePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost(body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersPost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost(body: 'test for deletion', user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeletePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost(body: 'test for deletion', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
public function testApiCannotDeleteImagePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
$post = $this->createPost('test image', imageDto: $imageDto, magazine: $magazine);
- $client->request('DELETE', "/api/post/{$post->getId()}");
+ $this->client->request('DELETE', "/api/post/{$post->getId()}");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDeleteImagePostWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
@@ -92,18 +86,17 @@ public function testApiCannotDeleteImagePostWithoutScope(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteOtherUsersImagePost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -112,18 +105,17 @@ public function testApiCannotDeleteOtherUsersImagePost(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $otherUser, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanDeleteImagePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -131,12 +123,12 @@ public function testApiCanDeleteImagePost(): void
$post = $this->createPost('test image', imageDto: $imageDto, user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:delete');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:delete');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('DELETE', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
}
}
diff --git a/tests/Functional/Controller/Api/Post/PostFavouriteApiTest.php b/tests/Functional/Controller/Api/Post/PostFavouriteApiTest.php
index 8e94dce34..443dc9399 100644
--- a/tests/Functional/Controller/Api/Post/PostFavouriteApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostFavouriteApiTest.php
@@ -10,47 +10,44 @@ class PostFavouriteApiTest extends WebTestCase
{
public function testApiCannotFavouritePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test for favourite', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite");
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotFavouritePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanFavouritePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test for favourite', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/favourite", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -64,7 +61,7 @@ public function testApiCanFavouritePost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/PostReportApiTest.php b/tests/Functional/Controller/Api/Post/PostReportApiTest.php
index 638a60ebb..78d5ff11f 100644
--- a/tests/Functional/Controller/Api/Post/PostReportApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostReportApiTest.php
@@ -12,7 +12,6 @@ class PostReportApiTest extends WebTestCase
{
public function testApiCannotReportPostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test for report', magazine: $magazine);
@@ -20,13 +19,12 @@ public function testApiCannotReportPostAnonymous(): void
'reason' => 'Test reporting',
];
- $client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest);
+ $this->client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotReportPostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test for report', user: $user, magazine: $magazine);
@@ -36,18 +34,17 @@ public function testApiCannotReportPostWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanReportPost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$otherUser = $this->getUserByUsername('somebody');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -60,12 +57,12 @@ public function testApiCanReportPost(): void
$magazineRepository = $this->getService(MagazineRepository::class);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:report');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:report');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('POST', "/api/post/{$post->getId()}/report", $reportRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(204);
$magazine = $magazineRepository->find($magazine->getId());
diff --git a/tests/Functional/Controller/Api/Post/PostRetrieveApiTest.php b/tests/Functional/Controller/Api/Post/PostRetrieveApiTest.php
index 9b603175c..2d3872927 100644
--- a/tests/Functional/Controller/Api/Post/PostRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostRetrieveApiTest.php
@@ -14,43 +14,38 @@ class PostRetrieveApiTest extends WebTestCase
{
public function testApiCannotGetSubscribedPostsAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/posts/subscribed');
+ $this->client->request('GET', '/api/posts/subscribed');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetSubscribedPostsWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'write');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'write');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetSubscribedPosts(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag', $user);
$post = $this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/subscribed', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -72,7 +67,7 @@ public function testApiCanGetSubscribedPosts(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(0, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -92,43 +87,38 @@ public function testApiCanGetSubscribedPosts(): void
public function testApiCannotGetModeratedPostsAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/posts/moderated');
+ $this->client->request('GET', '/api/posts/moderated');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetModeratedPostsWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetModeratedPosts(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag', $user);
$post = $this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read moderate:post');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read moderate:post');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/moderated', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -150,7 +140,7 @@ public function testApiCanGetModeratedPosts(): void
self::assertEquals('another post', $jsonData['items'][0]['body']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(0, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -170,29 +160,24 @@ public function testApiCanGetModeratedPosts(): void
public function testApiCannotGetFavouritedPostsAnonymous(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/posts/favourited');
+ $this->client->request('GET', '/api/posts/favourited');
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotGetFavouritedPostsWithoutScope(): void
{
- $client = self::createClient();
-
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetFavouritedPosts(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$post = $this->createPost('a post');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -202,14 +187,14 @@ public function testApiCanGetFavouritedPosts(): void
$favouriteManager->toggle($user, $post);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts/favourited', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -230,7 +215,7 @@ public function testApiCanGetFavouritedPosts(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(0, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -250,7 +235,6 @@ public function testApiCanGetFavouritedPosts(): void
public function testApiCanGetPostsAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -259,9 +243,9 @@ public function testApiCanGetPostsAnonymous(): void
$postManager = $this->getService(PostManager::class);
$postManager->pin($second);
- $client->request('GET', '/api/posts');
+ $this->client->request('GET', '/api/posts');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -282,7 +266,7 @@ public function testApiCanGetPostsAnonymous(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -309,21 +293,20 @@ public function testApiCanGetPostsAnonymous(): void
public function testApiCanGetPosts(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -344,7 +327,7 @@ public function testApiCanGetPosts(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -372,7 +355,6 @@ public function testApiCanGetPosts(): void
public function testApiCanGetPostsWithLanguageAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -382,9 +364,9 @@ public function testApiCanGetPostsWithLanguageAnonymous(): void
$postManager = $this->getService(PostManager::class);
$postManager->pin($second);
- $client->request('GET', '/api/posts?lang[]=en&lang[]=de');
+ $this->client->request('GET', '/api/posts?lang[]=en&lang[]=de');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -405,7 +387,7 @@ public function testApiCanGetPostsWithLanguageAnonymous(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -433,7 +415,6 @@ public function testApiCanGetPostsWithLanguageAnonymous(): void
public function testApiCanGetPostsWithLanguage(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -441,14 +422,14 @@ public function testApiCanGetPostsWithLanguage(): void
$this->createPost('a dutch post', magazine: $magazine, lang: 'nl');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?lang[]=en&lang[]=de', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?lang[]=en&lang[]=de', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -469,7 +450,7 @@ public function testApiCanGetPostsWithLanguage(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -498,7 +479,6 @@ public function testApiCanGetPostsWithLanguage(): void
public function testApiCannotGetPostsByPreferredLangAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -507,13 +487,12 @@ public function testApiCannotGetPostsByPreferredLangAnonymous(): void
$postManager = $this->getService(PostManager::class);
$postManager->pin($second);
- $client->request('GET', '/api/posts?usePreferredLangs=true');
+ $this->client->request('GET', '/api/posts?usePreferredLangs=true');
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetPostsByPreferredLang(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -527,14 +506,14 @@ public function testApiCanGetPostsByPreferredLang(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?usePreferredLangs=true', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?usePreferredLangs=true', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -555,7 +534,7 @@ public function testApiCanGetPostsByPreferredLang(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
@@ -584,7 +563,6 @@ public function testApiCanGetPostsByPreferredLang(): void
public function testApiCanGetPostsNewest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -600,14 +578,14 @@ public function testApiCanGetPostsNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?sort=newest', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?sort=newest', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -633,7 +611,6 @@ public function testApiCanGetPostsNewest(): void
public function testApiCanGetPostsOldest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -649,14 +626,14 @@ public function testApiCanGetPostsOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?sort=oldest', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?sort=oldest', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -682,7 +659,6 @@ public function testApiCanGetPostsOldest(): void
public function testApiCanGetPostsCommented(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$this->createPostComment('comment 1', $first);
$this->createPostComment('comment 2', $first);
@@ -691,14 +667,14 @@ public function testApiCanGetPostsCommented(): void
$third = $this->createPost('third');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?sort=commented', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?sort=commented', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -727,7 +703,6 @@ public function testApiCanGetPostsCommented(): void
public function testApiCanGetPostsActive(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -743,14 +718,14 @@ public function testApiCanGetPostsActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?sort=active', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?sort=active', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -776,7 +751,6 @@ public function testApiCanGetPostsActive(): void
public function testApiCanGetPostsTop(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -787,14 +761,14 @@ public function testApiCanGetPostsTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts?sort=top', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts?sort=top', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -823,21 +797,20 @@ public function testApiCanGetPostsTop(): void
public function testApiCanGetPostsWithUserVoteStatus(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$this->createPost('another post', magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', '/api/posts', server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', '/api/posts', server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -858,7 +831,7 @@ public function testApiCanGetPostsWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['items'][0]['user']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertSame(1, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
self::assertSame(0, $jsonData['items'][0]['dv']);
@@ -884,12 +857,11 @@ public function testApiCanGetPostsWithUserVoteStatus(): void
public function testApiCanGetPostByIdAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
- $client->request('GET', "/api/post/{$post->getId()}");
+ $this->client->request('GET', "/api/post/{$post->getId()}");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -901,7 +873,7 @@ public function testApiCanGetPostByIdAnonymous(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['user']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
@@ -920,18 +892,17 @@ public function testApiCanGetPostByIdAnonymous(): void
public function testApiCanGetPostById(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -943,7 +914,7 @@ public function testApiCanGetPostById(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['user']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
self::assertSame(0, $jsonData['dv']);
@@ -962,18 +933,17 @@ public function testApiCanGetPostById(): void
public function testApiCanGetPostByIdWithUserVoteStatus(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/post/{$post->getId()}", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -985,7 +955,7 @@ public function testApiCanGetPostByIdWithUserVoteStatus(): void
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['user']);
self::assertNull($jsonData['image']);
self::assertEquals('en', $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
self::assertSame(0, $jsonData['dv']);
diff --git a/tests/Functional/Controller/Api/Post/PostUpdateApiTest.php b/tests/Functional/Controller/Api/Post/PostUpdateApiTest.php
index b6361cc70..db0c6231a 100644
--- a/tests/Functional/Controller/Api/Post/PostUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostUpdateApiTest.php
@@ -10,7 +10,6 @@ class PostUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdatePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', magazine: $magazine);
@@ -20,13 +19,12 @@ public function testApiCannotUpdatePostAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdatePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -38,18 +36,17 @@ public function testApiCannotUpdatePostWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersPost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -62,18 +59,17 @@ public function testApiCannotUpdateOtherUsersPost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdatePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test article', user: $user, magazine: $magazine);
@@ -85,14 +81,14 @@ public function testApiCanUpdatePost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -128,7 +124,6 @@ public function testApiCanUpdatePost(): void
public function testApiCannotUpdateImagePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$imageDto = $this->getKibbyImageDto();
@@ -140,13 +135,12 @@ public function testApiCannotUpdateImagePostAnonymous(): void
'isAdult' => true,
];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest);
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpdateImagePostWithoutScope(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$user = $this->getUserByUsername('user');
@@ -160,18 +154,17 @@ public function testApiCannotUpdateImagePostWithoutScope(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUpdateOtherUsersImagePost(): void
{
- $client = self::createClient();
$otherUser = $this->getUserByUsername('somebody');
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -186,18 +179,17 @@ public function testApiCannotUpdateOtherUsersImagePost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateImagePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
@@ -211,14 +203,14 @@ public function testApiCanUpdateImagePost(): void
];
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:edit');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:edit');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}", $updateRequest, server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/Post/PostVoteApiTest.php b/tests/Functional/Controller/Api/Post/PostVoteApiTest.php
index 2ed18e843..9806d740c 100644
--- a/tests/Functional/Controller/Api/Post/PostVoteApiTest.php
+++ b/tests/Functional/Controller/Api/Post/PostVoteApiTest.php
@@ -11,47 +11,44 @@ class PostVoteApiTest extends WebTestCase
{
public function testApiCannotUpvotePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1");
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotUpvotePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpvotePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -65,7 +62,7 @@ public function testApiCanUpvotePost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(1, $jsonData['uv']);
@@ -85,91 +82,56 @@ public function testApiCanUpvotePost(): void
public function testApiCannotDownvotePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1");
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotDownvotePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
- public function testApiCanDownvotePost(): void
+ public function testApiCannotDownvotePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
- self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
-
- self::assertIsArray($jsonData);
- self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
- self::assertSame($post->getId(), $jsonData['postId']);
- self::assertIsArray($jsonData['magazine']);
- self::assertArrayKeysMatch(self::MAGAZINE_SMALL_RESPONSE_KEYS, $jsonData['magazine']);
- self::assertSame($magazine->getId(), $jsonData['magazine']['magazineId']);
- self::assertIsArray($jsonData['user']);
- self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['user']);
- self::assertSame($user->getId(), $jsonData['user']['userId']);
- self::assertEquals($post->body, $jsonData['body']);
- self::assertNull($jsonData['image']);
- self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
- self::assertNull($jsonData['mentions']);
- self::assertSame(0, $jsonData['comments']);
- self::assertSame(0, $jsonData['uv']);
- self::assertSame(1, $jsonData['dv']);
- self::assertSame(0, $jsonData['favourites']);
- // No scope for seeing votes granted
- self::assertFalse($jsonData['isFavourited']);
- self::assertSame(-1, $jsonData['userVote']);
- self::assertFalse($jsonData['isAdult']);
- self::assertFalse($jsonData['isPinned']);
- self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['createdAt'], 'createdAt date format invalid');
- self::assertNull($jsonData['editedAt']);
- self::assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i:00', $jsonData['lastActive'], 'lastActive date format invalid');
- self::assertEquals('test-post', $jsonData['slug']);
- self::assertNull($jsonData['apId']);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/-1", server: ['HTTP_AUTHORIZATION' => $token]);
+ self::assertResponseStatusCodeSame(400);
}
public function testApiCannotClearVotePostAnonymous(): void
{
- $client = self::createClient();
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', magazine: $magazine);
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0");
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0");
self::assertResponseStatusCodeSame(401);
}
public function testApiCannotClearVotePostWithoutScope(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
@@ -178,18 +140,17 @@ public function testApiCannotClearVotePostWithoutScope(): void
$voteManager->vote(1, $post, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanClearVotePost(): void
{
- $client = self::createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByNameNoRSAKey('acme');
$post = $this->createPost('test post', user: $user, magazine: $magazine);
@@ -198,14 +159,14 @@ public function testApiCanClearVotePost(): void
$voteManager->vote(1, $post, $user, rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read post:vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read post:vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->jsonRequest('PUT', "/api/post/{$post->getId()}/vote/0", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::POST_RESPONSE_KEYS, $jsonData);
@@ -219,7 +180,7 @@ public function testApiCanClearVotePost(): void
self::assertEquals($post->body, $jsonData['body']);
self::assertNull($jsonData['image']);
self::assertEquals($post->lang, $jsonData['lang']);
- self::assertNull($jsonData['tags']);
+ self::assertEmpty($jsonData['tags']);
self::assertNull($jsonData['mentions']);
self::assertSame(0, $jsonData['comments']);
self::assertSame(0, $jsonData['uv']);
diff --git a/tests/Functional/Controller/Api/Post/UserPostRetrieveApiTest.php b/tests/Functional/Controller/Api/Post/UserPostRetrieveApiTest.php
index 9818cb3a5..93a411622 100644
--- a/tests/Functional/Controller/Api/Post/UserPostRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/Post/UserPostRetrieveApiTest.php
@@ -12,16 +12,15 @@ class UserPostRetrieveApiTest extends WebTestCase
{
public function testApiCanGetUserEntriesAnonymous(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$otherUser = $this->getUserByUsername('somebody');
$this->createPost('another post', magazine: $magazine, user: $otherUser);
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts");
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -46,7 +45,6 @@ public function testApiCanGetUserEntriesAnonymous(): void
public function testApiCanGetUserEntries(): void
{
- $client = self::createClient();
$post = $this->createPost('a post');
$this->createPostComment('up the ranking', $post);
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
@@ -54,14 +52,14 @@ public function testApiCanGetUserEntries(): void
$this->createPost('another post', magazine: $magazine, user: $otherUser);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -86,7 +84,6 @@ public function testApiCanGetUserEntries(): void
public function testApiCanGetUserEntriesNewest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -103,14 +100,14 @@ public function testApiCanGetUserEntriesNewest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=newest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -136,7 +133,6 @@ public function testApiCanGetUserEntriesNewest(): void
public function testApiCanGetUserEntriesOldest(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -153,14 +149,14 @@ public function testApiCanGetUserEntriesOldest(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=oldest", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -186,7 +182,6 @@ public function testApiCanGetUserEntriesOldest(): void
public function testApiCanGetUserEntriesCommented(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$this->createPostComment('comment 1', $first);
$this->createPostComment('comment 2', $first);
@@ -196,14 +191,14 @@ public function testApiCanGetUserEntriesCommented(): void
$otherUser = $first->user;
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=commented", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -232,7 +227,6 @@ public function testApiCanGetUserEntriesCommented(): void
public function testApiCanGetUserEntriesActive(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -249,14 +243,14 @@ public function testApiCanGetUserEntriesActive(): void
$entityManager->flush();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=active", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -282,7 +276,6 @@ public function testApiCanGetUserEntriesActive(): void
public function testApiCanGetUserEntriesTop(): void
{
- $client = self::createClient();
$first = $this->createPost('first');
$second = $this->createPost('second');
$third = $this->createPost('third');
@@ -294,14 +287,14 @@ public function testApiCanGetUserEntriesTop(): void
$voteManager->vote(1, $second, $this->getUserByUsername('voter1'), rateLimit: false);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts?sort=top", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -330,21 +323,20 @@ public function testApiCanGetUserEntriesTop(): void
public function testApiCanGetUserEntriesWithUserVoteStatus(): void
{
- $client = self::createClient();
$this->createPost('a post');
$otherUser = $this->getUserByUsername('somebody');
$magazine = $this->getMagazineByNameNoRSAKey('somemag');
$post = $this->createPost('another post', magazine: $magazine, user: $otherUser);
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read vote');
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read vote');
$token = $codes['token_type'].' '.$codes['access_token'];
- $client->request('GET', "/api/users/{$otherUser->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
+ $this->client->request('GET', "/api/users/{$otherUser->getId()}/posts", server: ['HTTP_AUTHORIZATION' => $token]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -367,7 +359,7 @@ public function testApiCanGetUserEntriesWithUserVoteStatus(): void
self::assertSame($otherUser->getId(), $jsonData['items'][0]['user']['userId']);
self::assertNull($jsonData['items'][0]['image']);
self::assertEquals('en', $jsonData['items'][0]['lang']);
- self::assertNull($jsonData['items'][0]['tags']);
+ self::assertEmpty($jsonData['items'][0]['tags']);
self::assertNull($jsonData['items'][0]['mentions']);
self::assertSame(0, $jsonData['items'][0]['comments']);
self::assertSame(0, $jsonData['items'][0]['uv']);
diff --git a/tests/Functional/Controller/Api/Search/SearchApiTest.php b/tests/Functional/Controller/Api/Search/SearchApiTest.php
index 1d3d005b3..2d6251127 100644
--- a/tests/Functional/Controller/Api/Search/SearchApiTest.php
+++ b/tests/Functional/Controller/Api/Search/SearchApiTest.php
@@ -6,10 +6,12 @@
use App\Factory\ActivityPub\GroupFactory;
use App\Factory\ActivityPub\PersonFactory;
+use App\Factory\ActivityPub\TombstoneFactory;
use App\Repository\MagazineRepository;
use App\Repository\SiteRepository;
use App\Repository\UserRepository;
use App\Service\ActivityPub\ApHttpClient;
+use App\Service\ProjectInfoService;
use App\Service\SettingsManager;
use App\Tests\WebTestCase;
use phpseclib3\Crypt\RSA;
@@ -33,24 +35,20 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testApiCannotSearchWithNoQuery(): void
{
- $client = self::createClient();
-
- $client->request('GET', '/api/search');
+ $this->client->request('GET', '/api/search');
self::assertResponseStatusCodeSame(400);
}
public function testApiCanFindEntryByTitleAnonymous(): void
{
- $client = self::createClient();
-
$entry = $this->getEntryByTitle('A test title to search for');
$this->getEntryByTitle('Cannot find this');
- $client->request('GET', '/api/search?q=title');
+ $this->client->request('GET', '/api/search?q=title');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -71,17 +69,15 @@ public function testApiCanFindEntryByTitleAnonymous(): void
public function testApiCanFindContentByBodyAnonymous(): void
{
- $client = self::createClient();
-
$entry = $this->getEntryByTitle('A test title to search for', body: 'This is the body we\'re finding');
$this->getEntryByTitle('Cannot find this', body: 'No keywords here!');
$post = $this->createPost('Lets get a post with its body in there too!');
$this->createPost('But not this one.');
- $client->request('GET', '/api/search?q=body');
+ $this->client->request('GET', '/api/search?q=body');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -121,17 +117,15 @@ public function testApiCanFindContentByBodyAnonymous(): void
public function testApiCanFindCommentsByBodyAnonymous(): void
{
- $client = self::createClient();
-
$entry = $this->getEntryByTitle('Cannot find this', body: 'No keywords here!');
$post = $this->createPost('But not this one.');
$entryComment = $this->createEntryComment('Some comment on a thread', $entry);
$postComment = $this->createPostComment('Some comment on a post', $post);
- $client->request('GET', '/api/search?q=comment');
+ $this->client->request('GET', '/api/search?q=comment');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -171,16 +165,14 @@ public function testApiCanFindCommentsByBodyAnonymous(): void
public function testApiCannotFindRemoteUserAnonymousWhenOptionSet(): void
{
- $client = self::createClient();
-
$settingsManager = $this->getService(SettingsManager::class);
$value = $settingsManager->get('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN');
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', true);
- $client->request('GET', '/api/search?q=ernest@kbin.social');
+ $this->client->request('GET', '/api/search?q=ernest@kbin.social');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -199,16 +191,14 @@ public function testApiCannotFindRemoteUserAnonymousWhenOptionSet(): void
public function testApiCannotFindRemoteMagazineAnonymousWhenOptionSet(): void
{
- $client = self::createClient();
-
$settingsManager = $this->getService(SettingsManager::class);
$value = $settingsManager->get('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN');
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', true);
- $client->request('GET', '/api/search?q=kbinMeta@kbin.social');
+ $this->client->request('GET', '/api/search?q=kbinMeta@kbin.social');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -225,22 +215,21 @@ public function testApiCannotFindRemoteMagazineAnonymousWhenOptionSet(): void
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', $value);
}
+ /*
+ * These tests do work, but we should not do requests to a remote server when running tests
public function testApiCanFindRemoteUserAnonymousWhenOptionUnset(): void
{
- $client = self::createClient();
-
$settingsManager = $this->getService(SettingsManager::class);
$value = $settingsManager->get('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN');
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', false);
$domain = $settingsManager->get('KBIN_DOMAIN');
+ $this->getUserByUsername('test');
$this->setCacheKeysForApHttpClient($domain);
- // TODO: This test should not rely on kbin.social. A more guaranteed option
- // would be to spin up a second instance on the same machine.
- $client->request('GET', '/api/search?q=ernest@kbin.social');
+ $this->client->request('GET', "/api/search?q=@eugen@mastodon.social");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -258,16 +247,14 @@ public function testApiCanFindRemoteUserAnonymousWhenOptionUnset(): void
self::assertSame('user', $jsonData['apActors'][0]['type']);
self::assertIsArray($jsonData['apActors'][0]['object']);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData['apActors'][0]['object']);
- self::assertSame('ernest@kbin.social', $jsonData['apActors'][0]['object']['apId']);
+ self::assertSame('eugen@mastodon.social', $jsonData['apActors'][0]['object']['apId']);
// Seems like settings can persist in the test environment? Might only be for bare metal setups
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', $value);
}
public function testApiCanFindRemoteMagazineAnonymousWhenOptionUnset(): void
- {
- $client = self::createClient();
- // Admin user must exist to retrieve a remote magazine since remote mods aren't federated (yet)
+ { // Admin user must exist to retrieve a remote magazine since remote mods aren't federated (yet)
$this->getUserByUsername('admin', isAdmin: true);
$settingsManager = $this->getService(SettingsManager::class);
@@ -276,13 +263,12 @@ public function testApiCanFindRemoteMagazineAnonymousWhenOptionUnset(): void
$domain = $settingsManager->get('KBIN_DOMAIN');
$logger = $this->getService(LoggerInterface::class);
$this->setCacheKeysForApHttpClient($domain, $logger);
+ $this->getMagazineByName('testMag');
- // TODO: This test should not rely on kbin.social. A more guaranteed option
- // would be to spin up a second instance on the same machine.
- $client->request('GET', '/api/search?q=kbinMeta@kbin.social');
+ $this->client->request('GET', "/api/search?q=!technology@lemmy.world");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -300,8 +286,7 @@ public function testApiCanFindRemoteMagazineAnonymousWhenOptionUnset(): void
self::assertSame('magazine', $jsonData['apActors'][0]['type']);
self::assertIsArray($jsonData['apActors'][0]['object']);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData['apActors'][0]['object']);
- self::assertSame('kbinMeta@kbin.social', $jsonData['apActors'][0]['object']['apId']);
- self::assertSame('admin', $jsonData['apActors'][0]['object']['owner']['username']);
+ self::assertSame('technology@lemmy.world', $jsonData['apActors'][0]['object']['apId']);
// Seems like settings can persist in the test environment? Might only be for bare metal setups
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', $value);
@@ -309,22 +294,19 @@ public function testApiCanFindRemoteMagazineAnonymousWhenOptionUnset(): void
public function testApiCanFindRemoteUser(): void
{
- $client = self::createClient();
-
$settingsManager = $this->getService(SettingsManager::class);
$value = $settingsManager->get('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN');
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', true);
$domain = $settingsManager->get('KBIN_DOMAIN');
$this->setCacheKeysForApHttpClient($domain);
+ $this->getUserByUsername('test');
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- // TODO: This test should not rely on kbin.social. A more guaranteed option
- // would be to spin up a second instance on the same machine.
- $client->request('GET', '/api/search?q=ernest@kbin.social');
+ $this->client->request('GET', "/api/search?q=@eugen@mastodon.social");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -342,7 +324,7 @@ public function testApiCanFindRemoteUser(): void
self::assertSame('user', $jsonData['apActors'][0]['type']);
self::assertIsArray($jsonData['apActors'][0]['object']);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData['apActors'][0]['object']);
- self::assertSame('ernest@kbin.social', $jsonData['apActors'][0]['object']['apId']);
+ self::assertSame('eugen@mastodon.social', $jsonData['apActors'][0]['object']['apId']);
// Seems like settings can persist in the test environment? Might only be for bare metal setups
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', $value);
@@ -350,7 +332,6 @@ public function testApiCanFindRemoteUser(): void
public function testApiCanFindRemoteMagazine(): void
{
- $client = self::createClient();
$this->getUserByUsername('admin', isAdmin: true);
$settingsManager = $this->getService(SettingsManager::class);
@@ -359,14 +340,13 @@ public function testApiCanFindRemoteMagazine(): void
$domain = $settingsManager->get('KBIN_DOMAIN');
$this->setCacheKeysForApHttpClient($domain);
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
+ $this->getMagazineByName('testMag');
- // TODO: This test should not rely on kbin.social. A more guaranteed option
- // would be to spin up a second instance on the same machine.
- $client->request('GET', '/api/search?q=kbinMeta@kbin.social');
+ $this->client->request('GET', "/api/search?q=!technology@lemmy.world");
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::SEARCH_PAGINATED_KEYS, $jsonData);
@@ -384,12 +364,12 @@ public function testApiCanFindRemoteMagazine(): void
self::assertSame('magazine', $jsonData['apActors'][0]['type']);
self::assertIsArray($jsonData['apActors'][0]['object']);
self::assertArrayKeysMatch(self::MAGAZINE_RESPONSE_KEYS, $jsonData['apActors'][0]['object']);
- self::assertSame('kbinMeta@kbin.social', $jsonData['apActors'][0]['object']['apId']);
- self::assertSame('admin', $jsonData['apActors'][0]['object']['owner']['username']);
+ self::assertSame('technology@lemmy.world', $jsonData['apActors'][0]['object']['apId']);
// Seems like settings can persist in the test environment? Might only be for bare metal setups
$settingsManager->set('KBIN_FEDERATED_SEARCH_ONLY_LOGGEDIN', $value);
}
+ */
private function setCacheKeysForApHttpClient(string $domain, ?LoggerInterface $logger = null): void
{
@@ -412,6 +392,7 @@ private function setCacheKeysForApHttpClient(string $domain, ?LoggerInterface $l
// Inject fake keys into apHttpClient
$apHttpClient = new ApHttpClient(
$domain,
+ $this->getService(TombstoneFactory::class),
$this->getService(PersonFactory::class),
$this->getService(GroupFactory::class),
$logger ?? $this->getService(LoggerInterface::class),
@@ -419,6 +400,7 @@ private function setCacheKeysForApHttpClient(string $domain, ?LoggerInterface $l
$this->getService(UserRepository::class),
$this->getService(MagazineRepository::class),
$this->getService(SiteRepository::class),
+ $this->getService(ProjectInfoService::class),
);
self::getContainer()->set(ApHttpClient::class, $apHttpClient);
}
diff --git a/tests/Functional/Controller/Api/User/Admin/UserBanApiTest.php b/tests/Functional/Controller/Api/User/Admin/UserBanApiTest.php
index aad3bec0c..2055fa518 100644
--- a/tests/Functional/Controller/Api/User/Admin/UserBanApiTest.php
+++ b/tests/Functional/Controller/Api/User/Admin/UserBanApiTest.php
@@ -12,14 +12,13 @@ class UserBanApiTest extends WebTestCase
{
public function testApiCannotBanUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -29,15 +28,14 @@ public function testApiCannotBanUserWithoutScope(): void
public function testApiCannotUnbanUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -47,14 +45,13 @@ public function testApiCannotUnbanUserWithoutScope(): void
public function testApiCannotBanUserWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -64,15 +61,14 @@ public function testApiCannotBanUserWithoutAdminAccount(): void
public function testApiCannotUnbanUserWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -82,17 +78,16 @@ public function testApiCannotUnbanUserWithoutAdminAccount(): void
public function testApiCanBanUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(array_merge(self::USER_RESPONSE_KEYS, ['isBanned']), $jsonData);
self::assertTrue($jsonData['isBanned']);
@@ -104,20 +99,19 @@ public function testApiCanBanUser(): void
public function testApiCanUnbanUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(array_merge(self::USER_RESPONSE_KEYS, ['isBanned']), $jsonData);
self::assertFalse($jsonData['isBanned']);
@@ -129,14 +123,13 @@ public function testApiCanUnbanUser(): void
public function testBanApiReturns404IfUserNotFound(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) ($bannedUser->getId() * 10).'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) ($bannedUser->getId() * 10).'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(404);
$repository = $this->getService(UserRepository::class);
@@ -146,17 +139,16 @@ public function testBanApiReturns404IfUserNotFound(): void
public function testUnbanApiReturns404IfUserNotFound(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) ($bannedUser->getId() * 10).'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) ($bannedUser->getId() * 10).'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(404);
$repository = $this->getService(UserRepository::class);
@@ -166,39 +158,36 @@ public function testUnbanApiReturns404IfUserNotFound(): void
public function testBanApiReturns401IfTokenNotProvided(): void
{
- $client = self::createClient();
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban');
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban');
self::assertResponseStatusCodeSame(401);
}
public function testUnbanApiReturns401IfTokenNotProvided(): void
{
- $client = self::createClient();
$bannedUser = $this->getUserByUsername('JohnDoe');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban');
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban');
self::assertResponseStatusCodeSame(401);
}
public function testBanApiIsIdempotent(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
// Ban user a second time with the API
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/ban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(array_merge(self::USER_RESPONSE_KEYS, ['isBanned']), $jsonData);
self::assertTrue($jsonData['isBanned']);
@@ -210,20 +199,19 @@ public function testBanApiIsIdempotent(): void
public function testUnbanApiIsIdempotent(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
// Do not ban user
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('POST', '/api/admin/users/'.(string) $bannedUser->getId().'/unban', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(array_merge(self::USER_RESPONSE_KEYS, ['isBanned']), $jsonData);
self::assertFalse($jsonData['isBanned']);
diff --git a/tests/Functional/Controller/Api/User/Admin/UserDeleteApiTest.php b/tests/Functional/Controller/Api/User/Admin/UserDeleteApiTest.php
index 37b87943b..c05ac9122 100644
--- a/tests/Functional/Controller/Api/User/Admin/UserDeleteApiTest.php
+++ b/tests/Functional/Controller/Api/User/Admin/UserDeleteApiTest.php
@@ -12,14 +12,13 @@ class UserDeleteApiTest extends WebTestCase
{
public function testApiCannotDeleteUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$deletedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request(
+ $this->client->request(
'DELETE',
'/api/admin/users/'.(string) $deletedUser->getId().'/delete_account',
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -33,14 +32,13 @@ public function testApiCannotDeleteUserWithoutScope(): void
public function testApiCannotDeleteUserWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$deletedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:delete');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:delete');
- $client->request(
+ $this->client->request(
'DELETE',
'/api/admin/users/'.(string) $deletedUser->getId().'/delete_account',
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -54,21 +52,20 @@ public function testApiCannotDeleteUserWithoutAdminAccount(): void
public function testApiCanDeleteUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$deletedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:delete');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:delete');
- $client->request(
+ $this->client->request(
'DELETE',
'/api/admin/users/'.(string) $deletedUser->getId().'/delete_account',
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -79,14 +76,13 @@ public function testApiCanDeleteUser(): void
public function testDeleteApiReturns404IfUserNotFound(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$deletedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:delete');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:delete');
- $client->request(
+ $this->client->request(
'DELETE',
'/api/admin/users/'.(string) ($deletedUser->getId() * 10).'/delete_account',
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -100,39 +96,33 @@ public function testDeleteApiReturns404IfUserNotFound(): void
public function testDeleteApiReturns401IfTokenNotProvided(): void
{
- $client = self::createClient();
$deletedUser = $this->getUserByUsername('JohnDoe');
- $client->request('DELETE', '/api/admin/users/'.(string) $deletedUser->getId().'/delete_account');
+ $this->client->request('DELETE', '/api/admin/users/'.(string) $deletedUser->getId().'/delete_account');
self::assertResponseStatusCodeSame(401);
}
- public function testDeleteApiIsIdempotent(): void
+ public function testDeleteApiIsNotIdempotent(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$deletedUser = $this->getUserByUsername('JohnDoe');
-
+ $deleteId = $deletedUser->getId();
$this->getService(UserManager::class)->delete($deletedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:delete');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:delete');
// Ban user a second time with the API
- $client->request(
+ $this->client->request(
'DELETE',
- '/api/admin/users/'.(string) $deletedUser->getId().'/delete_account',
+ '/api/admin/users/'.(string) $deleteId.'/delete_account',
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
- self::assertResponseIsSuccessful();
-
- $jsonData = self::getJsonResponse($client);
-
- self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
+ self::assertResponseStatusCodeSame(404);
$repository = $this->getService(UserRepository::class);
- $deletedUser = $repository->find($deletedUser->getId());
- self::assertTrue($deletedUser->isAccountDeleted());
+ $deletedUser = $repository->find($deleteId);
+ self::assertNull($deletedUser);
}
}
diff --git a/tests/Functional/Controller/Api/User/Admin/UserPurgeApiTest.php b/tests/Functional/Controller/Api/User/Admin/UserPurgeApiTest.php
index fd2d93c97..04ea16192 100644
--- a/tests/Functional/Controller/Api/User/Admin/UserPurgeApiTest.php
+++ b/tests/Functional/Controller/Api/User/Admin/UserPurgeApiTest.php
@@ -11,14 +11,13 @@ class UserPurgeApiTest extends WebTestCase
{
public function testApiCannotPurgeUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$purgedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -28,14 +27,13 @@ public function testApiCannotPurgeUserWithoutScope(): void
public function testApiCannotPurgeUserWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$purgedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:purge');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:purge');
- $client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
@@ -46,14 +44,13 @@ public function testApiCannotPurgeUserWithoutAdminAccount(): void
public function testApiCanPurgeUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$purgedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:purge');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:purge');
- $client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(204);
$repository = $this->getService(UserRepository::class);
@@ -63,14 +60,13 @@ public function testApiCanPurgeUser(): void
public function testPurgeApiReturns404IfUserNotFound(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$purgedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:purge');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:purge');
- $client->request('DELETE', '/api/admin/users/'.(string) ($purgedUser->getId() * 10).'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/admin/users/'.(string) ($purgedUser->getId() * 10).'/purge_account', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(404);
$repository = $this->getService(UserRepository::class);
@@ -80,10 +76,9 @@ public function testPurgeApiReturns404IfUserNotFound(): void
public function testPurgeApiReturns401IfTokenNotProvided(): void
{
- $client = self::createClient();
$purgedUser = $this->getUserByUsername('JohnDoe');
- $client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account');
+ $this->client->request('DELETE', '/api/admin/users/'.(string) $purgedUser->getId().'/purge_account');
self::assertResponseStatusCodeSame(401);
}
}
diff --git a/tests/Functional/Controller/Api/User/Admin/UserRetrieveBannedApiTest.php b/tests/Functional/Controller/Api/User/Admin/UserRetrieveBannedApiTest.php
index eb617d375..79920372b 100644
--- a/tests/Functional/Controller/Api/User/Admin/UserRetrieveBannedApiTest.php
+++ b/tests/Functional/Controller/Api/User/Admin/UserRetrieveBannedApiTest.php
@@ -11,46 +11,43 @@ class UserRetrieveBannedApiTest extends WebTestCase
{
public function testApiCannotRetrieveBannedUsersWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotRetrieveBannedUsersWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveBannedUsers(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$bannedUser = $this->getUserByUsername('JohnDoe');
$this->getService(UserManager::class)->ban($bannedUser);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:ban');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:ban');
- $client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/admin/users/banned', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/User/Admin/UserVerifyApiTest.php b/tests/Functional/Controller/Api/User/Admin/UserVerifyApiTest.php
index 874815f06..82ae0b615 100644
--- a/tests/Functional/Controller/Api/User/Admin/UserVerifyApiTest.php
+++ b/tests/Functional/Controller/Api/User/Admin/UserVerifyApiTest.php
@@ -11,14 +11,13 @@ class UserVerifyApiTest extends WebTestCase
{
public function testApiCannotVerifyUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$unverifiedUser = $this->getUserByUsername('JohnDoe', active: false);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -28,14 +27,13 @@ public function testApiCannotVerifyUserWithoutScope(): void
public function testApiCannotVerifyUserWithoutAdminAccount(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: false);
$unverifiedUser = $this->getUserByUsername('JohnDoe', active: false);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:verify');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:verify');
- $client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
$repository = $this->getService(UserRepository::class);
@@ -45,17 +43,16 @@ public function testApiCannotVerifyUserWithoutAdminAccount(): void
public function testApiCanVerifyUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$unverifiedUser = $this->getUserByUsername('JohnDoe', active: false);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:verify');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:verify');
- $client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(200);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(array_merge(self::USER_RESPONSE_KEYS, ['isVerified']), $jsonData);
self::assertTrue($jsonData['isVerified']);
@@ -67,23 +64,21 @@ public function testApiCanVerifyUser(): void
public function testVerifyApiReturns404IfUserNotFound(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout', isAdmin: true);
$unverifiedUser = $this->getUserByUsername('JohnDoe', active: false);
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read admin:user:verify');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read admin:user:verify');
- $client->request('PUT', '/api/admin/users/'.(string) ($unverifiedUser->getId() * 10).'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/admin/users/'.(string) ($unverifiedUser->getId() * 10).'/verify', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(404);
}
public function testVerifyApiReturns401IfTokenNotProvided(): void
{
- $client = self::createClient();
$unverifiedUser = $this->getUserByUsername('JohnDoe', active: false);
- $client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify');
+ $this->client->request('PUT', '/api/admin/users/'.(string) $unverifiedUser->getId().'/verify');
self::assertResponseStatusCodeSame(401);
}
}
diff --git a/tests/Functional/Controller/Api/User/UserBlockApiTest.php b/tests/Functional/Controller/Api/User/UserBlockApiTest.php
index 293da6ef8..cf7d5ba06 100644
--- a/tests/Functional/Controller/Api/User/UserBlockApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserBlockApiTest.php
@@ -11,43 +11,40 @@ class UserBlockApiTest extends WebTestCase
{
public function testApiCannotBlockUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$blockedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/block', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/block', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUnblockUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$blockedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanBlockUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/block', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/block', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('userId', $jsonData);
@@ -73,7 +70,6 @@ public function testApiCanBlockUser(): void
public function testApiCanUnblockUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$blockedUser = $this->getUserByUsername('JohnDoe');
@@ -85,13 +81,13 @@ public function testApiCanUnblockUser(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $blockedUser->getId().'/unblock', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('userId', $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserFollowApiTest.php b/tests/Functional/Controller/Api/User/UserFollowApiTest.php
index c8c738b6b..f0d3bac8c 100644
--- a/tests/Functional/Controller/Api/User/UserFollowApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserFollowApiTest.php
@@ -11,43 +11,40 @@ class UserFollowApiTest extends WebTestCase
{
public function testApiCannotFollowUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/follow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/follow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotUnfollowUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/unfollow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/unfollow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanFollowUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/follow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/follow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('userId', $jsonData);
@@ -73,7 +70,6 @@ public function testApiCanFollowUser(): void
public function testApiCanUnfollowUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
@@ -85,13 +81,13 @@ public function testApiCanUnfollowUser(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/unfollow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('PUT', '/api/users/'.(string) $followedUser->getId().'/unfollow', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('userId', $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserRetrieveApiTest.php b/tests/Functional/Controller/Api/User/UserRetrieveApiTest.php
index f3b1059dc..00aaccf69 100644
--- a/tests/Functional/Controller/Api/User/UserRetrieveApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserRetrieveApiTest.php
@@ -32,17 +32,15 @@ class UserRetrieveApiTest extends WebTestCase
public function testApiCanRetrieveUsersWithAboutAnonymous(): void
{
- $client = self::createClient();
-
$users = [];
for ($i = 0; $i < self::NUM_USERS; ++$i) {
$users[] = $this->getUserByUsername('user'.(string) ($i + 1), about: 'Test user '.(string) ($i + 1));
}
- $client->request('GET', '/api/users');
+ $this->client->request('GET', '/api/users');
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -62,20 +60,19 @@ public function testApiCanRetrieveUsersWithAboutAnonymous(): void
public function testApiCanRetrieveUsersWithAbout(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
- $client->loginUser($this->getUserByUsername('UserWithoutAbout'));
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($this->getUserByUsername('UserWithoutAbout'));
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
$users = [];
for ($i = 0; $i < self::NUM_USERS; ++$i) {
$users[] = $this->getUserByUsername('user'.(string) ($i + 1), about: 'Test user '.(string) ($i + 1));
}
- $client->request('GET', '/api/users', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -85,13 +82,12 @@ public function testApiCanRetrieveUsersWithAbout(): void
public function testApiCanRetrieveUserByIdAnonymous(): void
{
- $client = self::createClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->request('GET', '/api/users/'.(string) $testUser->getId());
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId());
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -110,16 +106,15 @@ public function testApiCanRetrieveUserByIdAnonymous(): void
public function testApiCanRetrieveUserById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -138,13 +133,12 @@ public function testApiCanRetrieveUserById(): void
public function testApiCanRetrieveUserByNameAnonymous(): void
{
- $client = self::createClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->request('GET', '/api/users/name/'.$testUser->getUsername());
+ $this->client->request('GET', '/api/users/name/'.$testUser->getUsername());
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -163,16 +157,15 @@ public function testApiCanRetrieveUserByNameAnonymous(): void
public function testApiCanRetrieveUserByName(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/name/'.$testUser->getUsername(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/name/'.$testUser->getUsername(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -191,28 +184,26 @@ public function testApiCanRetrieveUserByName(): void
public function testApiCannotRetrieveCurrentUserWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/me', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/me', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanRetrieveCurrentUser(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
- $client->request('GET', '/api/users/me', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/me', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -231,7 +222,6 @@ public function testApiCanRetrieveCurrentUser(): void
public function testApiCanRetrieveUserFlagsWithScopes(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$follower = $this->getUserByUsername('follower');
@@ -243,13 +233,13 @@ public function testApiCanRetrieveUserFlagsWithScopes(): void
$manager->persist($follower);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/'.(string) $follower->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $follower->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -261,7 +251,6 @@ public function testApiCanRetrieveUserFlagsWithScopes(): void
public function testApiCanGetBlockedUsers(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$blockedUser = $this->getUserByUsername('JohnDoe');
@@ -273,13 +262,13 @@ public function testApiCanGetBlockedUsers(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/blocked', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/blocked', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -295,33 +284,30 @@ public function testApiCanGetBlockedUsers(): void
public function testApiCannotGetFollowedUsersWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotGetFollowersWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetFollowedUsers(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
@@ -333,13 +319,13 @@ public function testApiCanGetFollowedUsers(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -355,7 +341,6 @@ public function testApiCanGetFollowedUsers(): void
public function testApiCanGetFollowers(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followingUser = $this->getUserByUsername('JohnDoe');
@@ -367,13 +352,13 @@ public function testApiCanGetFollowers(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -389,7 +374,6 @@ public function testApiCanGetFollowers(): void
public function testApiCannotGetFollowedUsersByIdIfNotShared(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
@@ -402,16 +386,15 @@ public function testApiCannotGetFollowedUsersByIdIfNotShared(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($followedUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($followedUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/'.(string) $testUser->getId().'/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId().'/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetFollowedUsersById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followedUser = $this->getUserByUsername('JohnDoe');
@@ -423,13 +406,13 @@ public function testApiCanGetFollowedUsersById(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($followedUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($followedUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/'.(string) $testUser->getId().'/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId().'/followed', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -445,7 +428,6 @@ public function testApiCanGetFollowedUsersById(): void
public function testApiCanGetFollowersById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('UserWithoutAbout');
$followingUser = $this->getUserByUsername('JohnDoe');
@@ -457,13 +439,13 @@ public function testApiCanGetFollowersById(): void
$manager->persist($testUser);
$manager->flush();
- $client->loginUser($followingUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($followingUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/'.(string) $testUser->getId().'/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId().'/followers', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -479,30 +461,28 @@ public function testApiCanGetFollowersById(): void
public function testApiCannotGetSettingsWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read');
- $client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetSettings(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
- $client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_SETTINGS_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserRetrieveOAuthConsentsApiTest.php b/tests/Functional/Controller/Api/User/UserRetrieveOAuthConsentsApiTest.php
index 27244e463..fed9be15c 100644
--- a/tests/Functional/Controller/Api/User/UserRetrieveOAuthConsentsApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserRetrieveOAuthConsentsApiTest.php
@@ -20,30 +20,28 @@ class UserRetrieveOAuthConsentsApiTest extends WebTestCase
public function testApiCannotGetConsentsWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:follow user:block');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanGetConsents(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:follow user:block');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -73,21 +71,20 @@ public function testApiCanGetConsents(): void
public function testApiCannotGetOtherUsersConsentsById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
$testUser2 = $this->getUserByUsername('someuser2');
- $client->loginUser($testUser);
- $codes1 = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes1 = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:follow user:block');
- $client->loginUser($testUser2);
- $codes2 = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:follow user:block');
+ $this->client->loginUser($testUser2);
+ $codes2 = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:follow user:block');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes1['token_type'].' '.$codes1['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes1['token_type'].' '.$codes1['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -98,7 +95,7 @@ public function testApiCannotGetOtherUsersConsentsById(): void
self::assertIsArray($jsonData['items'][0]);
self::assertArrayKeysMatch(self::CONSENT_RESPONSE_KEYS, $jsonData['items'][0]);
- $client->request(
+ $this->client->request(
'GET', '/api/users/consents/'.(string) $jsonData['items'][0]['consentId'],
server: ['HTTP_AUTHORIZATION' => $codes2['token_type'].' '.$codes2['access_token']]
);
@@ -107,17 +104,16 @@ public function testApiCannotGetOtherUsersConsentsById(): void
public function testApiCanGetConsentsById(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:follow user:block');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:follow user:block');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -130,13 +126,13 @@ public function testApiCanGetConsentsById(): void
$consent = $jsonData['items'][0];
- $client->request(
+ $this->client->request(
'GET', '/api/users/consents/'.(string) $consent['consentId'],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertEquals($consent, $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserUpdateApiTest.php b/tests/Functional/Controller/Api/User/UserUpdateApiTest.php
index d4742653d..d29674e88 100644
--- a/tests/Functional/Controller/Api/User/UserUpdateApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserUpdateApiTest.php
@@ -12,13 +12,12 @@ class UserUpdateApiTest extends WebTestCase
{
public function testApiCannotUpdateCurrentUserProfileWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/profile',
parameters: [
'about' => 'Updated during test',
@@ -30,23 +29,22 @@ public function testApiCannotUpdateCurrentUserProfileWithoutScope(): void
public function testApiCanUpdateCurrentUserProfile(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:edit user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:edit user:profile:read');
- $client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
self::assertSame($testUser->getId(), $jsonData['userId']);
self::assertNull($jsonData['about']);
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/profile',
parameters: [
'about' => 'Updated during test',
@@ -55,17 +53,17 @@ public function testApiCanUpdateCurrentUserProfile(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
self::assertSame($testUser->getId(), $jsonData['userId']);
self::assertEquals('Updated during test', $jsonData['about']);
- $client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/'.(string) $testUser->getId(), server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -75,11 +73,10 @@ public function testApiCanUpdateCurrentUserProfile(): void
public function testApiCannotUpdateCurrentUserSettingsWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
$settings = (new UserSettingsDto(
false,
@@ -98,7 +95,7 @@ public function testApiCannotUpdateCurrentUserSettingsWithoutScope(): void
['en']
))->jsonSerialize();
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/settings',
parameters: $settings,
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -108,11 +105,10 @@ public function testApiCannotUpdateCurrentUserSettingsWithoutScope(): void
public function testApiCanUpdateCurrentUserSettings(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:edit user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:edit user:profile:read');
$settings = (new UserSettingsDto(
false,
@@ -131,14 +127,14 @@ public function testApiCanUpdateCurrentUserSettings(): void
['en']
))->jsonSerialize();
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/settings',
parameters: $settings,
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(UserRetrieveApiTest::USER_SETTINGS_KEYS, $jsonData);
@@ -158,10 +154,10 @@ public function testApiCanUpdateCurrentUserSettings(): void
self::assertEquals(['test'], $jsonData['featuredMagazines']);
self::assertEquals(['en'], $jsonData['preferredLanguages']);
- $client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/settings', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(UserRetrieveApiTest::USER_SETTINGS_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserUpdateImagesApiTest.php b/tests/Functional/Controller/Api/User/UserUpdateImagesApiTest.php
index 904505806..5d2309b8d 100644
--- a/tests/Functional/Controller/Api/User/UserUpdateImagesApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserUpdateImagesApiTest.php
@@ -19,17 +19,16 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testApiCannotUpdateCurrentUserAvatarWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', '/api/users/avatar',
files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -39,17 +38,16 @@ public function testApiCannotUpdateCurrentUserAvatarWithoutScope(): void
public function testApiCannotUpdateCurrentUserCoverWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', '/api/users/cover',
files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
@@ -59,48 +57,45 @@ public function testApiCannotUpdateCurrentUserCoverWithoutScope(): void
public function testApiCannotDeleteCurrentUserAvatarWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
- $client->request('DELETE', '/api/users/avatar', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/users/avatar', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCannotDeleteCurrentUserCoverWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:read');
- $client->request('DELETE', '/api/users/cover', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/users/cover', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseStatusCodeSame(403);
}
public function testApiCanUpdateAndDeleteCurrentUserAvatar(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:edit user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:edit user:profile:read');
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', '/api/users/avatar',
files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -115,10 +110,10 @@ public function testApiCanUpdateAndDeleteCurrentUserAvatar(): void
// This isn't great, but since people could have their media directory
// pretty much anywhere, its difficult to reliably clean up uploaded files
// otherwise. This is certainly something that could be improved.
- $client->request('DELETE', '/api/users/avatar', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/users/avatar', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -127,24 +122,23 @@ public function testApiCanUpdateAndDeleteCurrentUserAvatar(): void
public function testApiCanUpdateAndDeleteCurrentUserCover(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('JohnDoe');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:profile:edit user:profile:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:profile:edit user:profile:read');
// Uploading a file appears to delete the file at the given path, so make a copy before upload
copy($this->kibbyPath, $this->kibbyPath.'.tmp');
$image = new UploadedFile($this->kibbyPath.'.tmp', 'kibby_emoji.png', 'image/png');
- $client->request(
+ $this->client->request(
'POST', '/api/users/cover',
files: ['uploadImage' => $image],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
@@ -159,10 +153,10 @@ public function testApiCanUpdateAndDeleteCurrentUserCover(): void
// This isn't great, but since people could have their media directory
// pretty much anywhere, its difficult to reliably clean up uploaded files
// otherwise. This is certainly something that could be improved.
- $client->request('DELETE', '/api/users/cover', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('DELETE', '/api/users/cover', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::USER_RESPONSE_KEYS, $jsonData);
diff --git a/tests/Functional/Controller/Api/User/UserUpdateOAuthConsentsApiTest.php b/tests/Functional/Controller/Api/User/UserUpdateOAuthConsentsApiTest.php
index d2192ac15..8e58dd6ba 100644
--- a/tests/Functional/Controller/Api/User/UserUpdateOAuthConsentsApiTest.php
+++ b/tests/Functional/Controller/Api/User/UserUpdateOAuthConsentsApiTest.php
@@ -10,17 +10,16 @@ class UserUpdateOAuthConsentsApiTest extends WebTestCase
{
public function testApiCannotUpdateConsentsWithoutScope(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -28,7 +27,7 @@ public function testApiCannotUpdateConsentsWithoutScope(): void
self::assertCount(1, $jsonData['items']);
self::assertArrayKeysMatch(UserRetrieveOAuthConsentsApiTest::CONSENT_RESPONSE_KEYS, $jsonData['items'][0]);
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/consents/'.(string) $jsonData['items'][0]['consentId'],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
@@ -37,17 +36,16 @@ public function testApiCannotUpdateConsentsWithoutScope(): void
public function testApiCanUpdateConsents(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -62,7 +60,7 @@ public function testApiCanUpdateConsents(): void
'user:follow',
], $jsonData['items'][0]['scopesGranted']);
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/consents/'.(string) $jsonData['items'][0]['consentId'],
parameters: ['scopes' => [
'read',
@@ -73,7 +71,7 @@ public function testApiCanUpdateConsents(): void
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(UserRetrieveOAuthConsentsApiTest::CONSENT_RESPONSE_KEYS, $jsonData);
self::assertEquals([
@@ -85,18 +83,17 @@ public function testApiCanUpdateConsents(): void
public function testApiUpdatingConsentsDoesNotAffectExistingKeys(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
- $client->jsonRequest(
+ $jsonData = self::getJsonResponse($this->client);
+ $this->client->jsonRequest(
'PUT', '/api/users/consents/'.(string) $jsonData['items'][0]['consentId'],
parameters: ['scopes' => [
'read',
@@ -105,16 +102,16 @@ public function testApiUpdatingConsentsDoesNotAffectExistingKeys(): void
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
// Existing token still has permission to read oauth consents despite client consent being revoked.
- $client->jsonRequest(
+ $this->client->jsonRequest(
'GET', '/api/users/consents/'.(string) $jsonData['consentId'],
server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]
);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(UserRetrieveOAuthConsentsApiTest::CONSENT_RESPONSE_KEYS, $jsonData);
self::assertEquals([
@@ -125,17 +122,16 @@ public function testApiUpdatingConsentsDoesNotAffectExistingKeys(): void
public function testApiCannotAddConsents(): void
{
- $client = self::createClient();
self::createOAuth2AuthCodeClient();
$testUser = $this->getUserByUsername('someuser');
- $client->loginUser($testUser);
- $codes = self::getAuthorizationCodeTokenResponse($client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
+ $this->client->loginUser($testUser);
+ $codes = self::getAuthorizationCodeTokenResponse($this->client, scopes: 'read user:oauth_clients:read user:oauth_clients:edit user:follow');
- $client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
+ $this->client->request('GET', '/api/users/consents', server: ['HTTP_AUTHORIZATION' => $codes['token_type'].' '.$codes['access_token']]);
self::assertResponseIsSuccessful();
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayKeysMatch(self::PAGINATED_KEYS, $jsonData);
@@ -150,7 +146,7 @@ public function testApiCannotAddConsents(): void
'user:follow',
], $jsonData['items'][0]['scopesGranted']);
- $client->jsonRequest(
+ $this->client->jsonRequest(
'PUT', '/api/users/consents/'.(string) $jsonData['items'][0]['consentId'],
parameters: ['scopes' => [
'read',
diff --git a/tests/Functional/Controller/Domain/DomainBlockControllerTest.php b/tests/Functional/Controller/Domain/DomainBlockControllerTest.php
index 1723dd6dc..d0192fe2b 100644
--- a/tests/Functional/Controller/Domain/DomainBlockControllerTest.php
+++ b/tests/Functional/Controller/Domain/DomainBlockControllerTest.php
@@ -10,8 +10,6 @@ class DomainBlockControllerTest extends WebTestCase
{
public function testUserCanBlockAndUnblockDomain(): void
{
- $client = $this->createClient();
-
$entry = $this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -19,27 +17,25 @@ public function testUserCanBlockAndUnblockDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
// Block
- $client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=domain_block] .active');
// Unblock
- $client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#sidebar form[name=domain_block] .active');
}
public function testXmlUserCanBlockDomain(): void
{
- $client = $this->createClient();
-
$entry = $this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -47,21 +43,19 @@ public function testXmlUserCanBlockDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('active', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnblockDomain(): void
{
- $client = $this->createClient();
-
$entry = $this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -69,19 +63,19 @@ public function testXmlUserCanUnblockDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
// Block
- $client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
+ $crawler = $this->client->followRedirect();
// Unblock
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=domain_block] button')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringNotContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringNotContainsString('active', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/Domain/DomainCommentFrontControllerTest.php b/tests/Functional/Controller/Domain/DomainCommentFrontControllerTest.php
index e411a9013..e9f962546 100644
--- a/tests/Functional/Controller/Domain/DomainCommentFrontControllerTest.php
+++ b/tests/Functional/Controller/Domain/DomainCommentFrontControllerTest.php
@@ -10,8 +10,6 @@ class DomainCommentFrontControllerTest extends WebTestCase
{
public function testDomainCommentFrontPage(): void
{
- $client = $this->createClient();
-
$entry = $this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -20,16 +18,16 @@ public function testDomainCommentFrontPage(): void
);
$this->createEntryComment('test comment 1', $entry);
- $crawler = $client->request('GET', '/d/kbin.pub');
- $crawler = $client->click($crawler->filter('#header')->selectLink('Comments')->link());
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->click($crawler->filter('#header')->selectLink('Comments')->link());
$this->assertSelectorTextContains('#header', '/d/kbin.pub');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 1');
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
$this->assertSelectorTextContains('h1', 'kbin.pub');
$this->assertSelectorTextContains('h2', ucfirst($sortOption));
@@ -38,6 +36,6 @@ public function testDomainCommentFrontPage(): void
private function getSortOptions(): array
{
- return ['hot', 'newest', 'active', 'oldest'];
+ return ['Hot', 'Newest', 'Active', 'Oldest'];
}
}
diff --git a/tests/Functional/Controller/Domain/DomainFrontControllerTest.php b/tests/Functional/Controller/Domain/DomainFrontControllerTest.php
index ef3895857..e4ee58575 100644
--- a/tests/Functional/Controller/Domain/DomainFrontControllerTest.php
+++ b/tests/Functional/Controller/Domain/DomainFrontControllerTest.php
@@ -10,8 +10,6 @@ class DomainFrontControllerTest extends WebTestCase
{
public function testDomainCommentFrontPage(): void
{
- $client = $this->createClient();
-
$this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -19,16 +17,16 @@ public function testDomainCommentFrontPage(): void
'http://kbin.pub/instances'
);
- $crawler = $client->request('GET', '/');
- $crawler = $client->click($crawler->filter('#content article')->selectLink('more from domain')->link());
+ $crawler = $this->client->request('GET', '/');
+ $crawler = $this->client->click($crawler->filter('#content article')->selectLink('More from domain')->link());
$this->assertSelectorTextContains('#header', '/d/kbin.pub');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', 'kbin.pub');
$this->assertSelectorTextContains('h2', ucfirst($sortOption));
}
@@ -36,6 +34,6 @@ public function testDomainCommentFrontPage(): void
private function getSortOptions(): array
{
- return ['top', 'hot', 'newest', 'active', 'commented'];
+ return ['Top', 'Hot', 'Newest', 'Active', 'Commented'];
}
}
diff --git a/tests/Functional/Controller/Domain/DomainSubControllerTest.php b/tests/Functional/Controller/Domain/DomainSubControllerTest.php
index bd21d345d..d5727e852 100644
--- a/tests/Functional/Controller/Domain/DomainSubControllerTest.php
+++ b/tests/Functional/Controller/Domain/DomainSubControllerTest.php
@@ -10,8 +10,6 @@ class DomainSubControllerTest extends WebTestCase
{
public function testUserCanSubAndUnsubDomain(): void
{
- $client = $this->createClient();
-
$this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -19,21 +17,21 @@ public function testUserCanSubAndUnsubDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
// Subscribe
- $client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=domain_subscribe] .active');
$this->assertSelectorTextContains('#sidebar .domain', 'Unsubscribe');
$this->assertSelectorTextContains('#sidebar .domain', '1');
// Unsubscribe
- $client->submit($crawler->filter('#sidebar .domain')->selectButton('Unsubscribe')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .domain')->selectButton('Unsubscribe')->form());
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#sidebar form[name=domain_subscribe] .active');
$this->assertSelectorTextContains('#sidebar .domain', 'Subscribe');
@@ -42,8 +40,6 @@ public function testUserCanSubAndUnsubDomain(): void
public function testXmlUserCanSubDomain(): void
{
- $client = $this->createClient();
-
$this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -51,22 +47,20 @@ public function testXmlUserCanSubDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
// Subscribe
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Unsubscribe', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Unsubscribe', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnsubDomain(): void
{
- $client = $this->createClient();
-
$this->createEntry(
'test entry 1',
$this->getMagazineByName('acme'),
@@ -74,19 +68,19 @@ public function testXmlUserCanUnsubDomain(): void
'http://kbin.pub/instances'
);
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', '/d/kbin.pub');
+ $crawler = $this->client->request('GET', '/d/kbin.pub');
// Subscribe
- $client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .domain')->selectButton('Subscribe')->form());
+ $crawler = $this->client->followRedirect();
// Unsubscribe
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .domain')->selectButton('Unsubscribe')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .domain')->selectButton('Unsubscribe')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Subscribe', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Subscribe', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentBoostControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentBoostControllerTest.php
index 34031f8bd..708bff76d 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentBoostControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentBoostControllerTest.php
@@ -8,10 +8,9 @@
class EntryCommentBoostControllerTest extends WebTestCase
{
- public function testLoggedUserCanAddToFavouritesEntryComment(): void
+ public function testLoggedUserCanAddToBoostsEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
@@ -22,19 +21,20 @@ public function testLoggedUserCanAddToFavouritesEntryComment(): void
);
$this->createEntryComment('test comment 1', $entry, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
-
- $client->submit(
- $crawler->filter('#main .entry-comment')->selectButton('boost')->form([])
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $this->client->submit(
+ $crawler->filter('#main .entry-comment')->selectButton('Boost')->form()
);
+ $this->client->followRedirect();
+ self::assertResponseIsSuccessful();
- $crawler = $client->followRedirect();
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $this->assertSelectorTextContains('#main .entry-comment', 'boost (1)');
+ $this->assertSelectorTextContains('#main .entry-comment', 'Boost (1)');
- $crawler = $client->click($crawler->filter('#main .entry-comment')->selectLink('activity')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry-comment')->selectLink('Activity')->link());
- $client->click($crawler->filter('#main #activity')->selectLink('boosts (1)')->link());
+ $this->client->click($crawler->filter('#main #activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JohnDoe');
}
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentChangeLangControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentChangeLangControllerTest.php
index c541507d4..b7af1a2c6 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentChangeLangControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentChangeLangControllerTest.php
@@ -10,21 +10,20 @@ class EntryCommentChangeLangControllerTest extends WebTestCase
{
public function testModCanChangeLanguage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createEntryComment('test comment 1');
- $crawler = $client->request('GET', "/m/acme/t/{$comment->entry->getId()}/-/comment/{$comment->getId()}/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$comment->entry->getId()}/-/comment/{$comment->getId()}/moderate");
- $form = $crawler->filter('.moderate-panel')->selectButton('change language')->form();
+ $form = $crawler->filter('.moderate-panel')->selectButton('lang[submit]')->form();
$this->assertSame($form['lang']['lang']->getValue(), 'en');
$form['lang']['lang']->select('fr');
- $client->submit($form);
- $client->followRedirect();
+ $this->client->submit($form);
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .badge-lang', 'French');
}
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentCreateControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentCreateControllerTest.php
index 1e3f2723e..87cecdeb4 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentCreateControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentCreateControllerTest.php
@@ -16,14 +16,13 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testUserCanCreateEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Add comment')->form(
[
'entry_comment[body]' => 'test comment 1',
@@ -32,29 +31,28 @@ public function testUserCanCreateEntryComment(): void
);
$this->assertResponseRedirects('/m/acme/t/'.$entry->getId().'/test-entry-1');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main blockquote', 'test comment 1');
}
public function testUserCanCreateEntryCommentWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $form = $crawler->filter('form[name=entry_comment]')->selectButton('Add comment')->form();
+ $form = $crawler->filter('form[name=entry_comment]')->selectButton('entry_comment[submit]')->form();
$form->get('entry_comment[body]')->setValue('test comment 1');
$form->get('entry_comment[image]')->upload($this->kibbyPath);
// Needed since we require this global to be set when validating entries but the client doesn't actually set it
$_FILES = $form->getPhpFiles();
- $client->submit($form);
+ $this->client->submit($form);
$this->assertResponseRedirects('/m/acme/t/'.$entry->getId().'/test-entry-1');
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main blockquote', 'test comment 1');
$this->assertSelectorExists('blockquote footer figure img');
@@ -65,22 +63,20 @@ public function testUserCanCreateEntryCommentWithImage(): void
public function testUserCanReplyEntryComment(): void
{
- $client = $this->createClient();
-
$comment = $this->createEntryComment(
'test comment 1',
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub'),
$this->getUserByUsername('JaneDoe')
);
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('reply')->link());
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('Reply')->link());
$this->assertSelectorTextContains('#main blockquote', 'test comment 1');
- $crawler = $client->submit(
+ $crawler = $this->client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Add comment')->form(
[
'entry_comment[body]' => 'test comment 2',
@@ -89,21 +85,20 @@ public function testUserCanReplyEntryComment(): void
);
$this->assertResponseRedirects('/m/acme/t/'.$entry->getId().'/test-entry-1');
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertEquals(2, $crawler->filter('#main blockquote')->count());
}
public function testUserCantCreateInvalidEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Add comment')->form(
[
'entry_comment[body]' => '',
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentDeleteControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentDeleteControllerTest.php
index 99a986a07..de6b41921 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentDeleteControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentDeleteControllerTest.php
@@ -5,23 +5,23 @@
namespace App\Tests\Functional\Controller\Entry\Comment;
use App\Tests\WebTestCase;
+use Symfony\Contracts\Translation\TranslatorInterface;
class EntryCommentDeleteControllerTest extends WebTestCase
{
public function testUserCanDeleteEntryComment()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$entry = $this->getEntryByTitle('comment deletion test', body: 'a comment will be deleted', magazine: $magazine, user: $user);
$comment = $this->createEntryComment('Delete me!', $entry, $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/comment-deletion-test");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/comment-deletion-test");
$this->assertSelectorExists('#comments form[action$="delete"]');
- $client->submit(
- $crawler->filter('#comments form[action$="delete"]')->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter('#comments form[action$="delete"]')->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
@@ -29,24 +29,25 @@ public function testUserCanDeleteEntryComment()
public function testUserCanSoftDeleteEntryComment()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$entry = $this->getEntryByTitle('comment deletion test', body: 'a comment will be deleted', magazine: $magazine, user: $user);
$comment = $this->createEntryComment('Delete me!', $entry, $user);
$reply = $this->createEntryComment('Are you deleted yet?', $entry, $user, $comment);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/comment-deletion-test");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/comment-deletion-test");
$this->assertSelectorExists("#entry-comment-{$comment->getId()} form[action$=\"delete\"]");
- $client->submit(
- $crawler->filter("#entry-comment-{$comment->getId()} form[action$=\"delete\"]")->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter("#entry-comment-{$comment->getId()} form[action$=\"delete\"]")->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
- $this->assertSelectorTextContains("#entry-comment-{$comment->getId()} .content", 'deleted_by_author');
+ $translator = $this->getService(TranslatorInterface::class);
+
+ $this->assertSelectorTextContains("#entry-comment-{$comment->getId()} .content", $translator->trans('deleted_by_author'));
}
}
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentEditControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentEditControllerTest.php
index 0a8daae90..791bd0f46 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentEditControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentEditControllerTest.php
@@ -10,21 +10,20 @@ class EntryCommentEditControllerTest extends WebTestCase
{
public function testAuthorCanEditOwnEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
$this->createEntryComment('test comment 1', $entry);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry-comment')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry-comment')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .entry-comment');
$this->assertSelectorTextContains('#main .entry-comment', 'test comment 1');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Update comment')->form(
[
'entry_comment[body]' => 'test comment 2 body',
@@ -32,22 +31,21 @@ public function testAuthorCanEditOwnEntryComment(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry-comment', 'test comment 2 body');
}
public function testAuthorCanEditOwnEntryCommentWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
$this->createEntryComment('test comment 1', $entry, imageDto: $this->getKibbyImageDto());
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry-comment')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry-comment')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .entry-comment');
@@ -57,7 +55,7 @@ public function testAuthorCanEditOwnEntryCommentWithImage(): void
$this->assertNotNull($node);
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $node->attributes->getNamedItem('src')->textContent);
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Update comment')->form(
[
'entry_comment[body]' => 'test comment 2 body',
@@ -65,7 +63,7 @@ public function testAuthorCanEditOwnEntryCommentWithImage(): void
)
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry-comment', 'test comment 2 body');
$this->assertSelectorExists('#main .entry-comment img');
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentFrontControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentFrontControllerTest.php
index 745d70d7b..c61504a54 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentFrontControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentFrontControllerTest.php
@@ -14,21 +14,21 @@ class EntryCommentFrontControllerTest extends WebTestCase
{
public function testFrontPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/comments');
+ $this->client->request('GET', '/comments');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/comments/newest');
+ $crawler = $this->client->request('GET', '/comments/newest');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextContains('blockquote header', 'to kbin in test entry 2');
$this->assertSelectorTextContains('blockquote .content', 'test comment 3');
$this->assertcount(3, $crawler->filter('.comment'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
@@ -36,14 +36,14 @@ public function testFrontPage(): void
public function testMagazinePage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/m/acme/comments');
+ $this->client->request('GET', '/m/acme/comments');
$this->assertSelectorTextContains('h2', 'Hot');
- $crawler = $client->request('GET', '/m/acme/comments/newest');
+ $crawler = $this->client->request('GET', '/m/acme/comments/newest');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextNotContains('blockquote header', 'to acme');
$this->assertSelectorTextContains('blockquote header', 'in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
@@ -54,28 +54,28 @@ public function testMagazinePage(): void
$this->assertcount(2, $crawler->filter('.comment'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
- $this->assertSelectorTextContains('h1', 'Magazine title');
+ $this->assertSelectorTextContains('h1', 'acme');
$this->assertSelectorTextContains('h2', ucfirst($sortOption));
}
}
public function testSubPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$magazineManager->subscribe($this->getMagazineByName('acme'), $this->getUserByUsername('Actor'));
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/sub/comments');
+ $this->client->request('GET', '/sub/comments');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/sub/comments/newest');
+ $crawler = $this->client->request('GET', '/sub/comments/newest');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
@@ -84,7 +84,7 @@ public function testSubPage(): void
$this->assertcount(2, $crawler->filter('.comment'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
@@ -92,21 +92,23 @@ public function testSubPage(): void
public function testModPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$moderator = new ModeratorDto($this->getMagazineByName('acme'));
$moderator->user = $this->getUserByUsername('Actor');
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/mod/comments');
+ $this->client->request('GET', '/mod/comments');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/mod/comments/newest');
+ $crawler = $this->client->request('GET', '/mod/comments/newest');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
@@ -115,7 +117,7 @@ public function testModPage(): void
$this->assertcount(2, $crawler->filter('.comment'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
@@ -123,7 +125,7 @@ public function testModPage(): void
public function testFavPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
$favouriteManager = $this->getService(FavouriteManager::class);
$favouriteManager->toggle(
@@ -131,21 +133,21 @@ public function testFavPage(): void
$this->createEntryComment('test comment 1', $this->getEntryByTitle('test entry 1'))
);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/fav/comments');
+ $this->client->request('GET', '/fav/comments');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/fav/comments/newest');
+ $crawler = $this->client->request('GET', '/fav/comments/newest');
- $this->assertSelectorTextContains('blockquote header', 'JohnDoe,');
+ $this->assertSelectorTextContains('blockquote header', 'JohnDoe');
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 1');
$this->assertcount(1, $crawler->filter('.comment'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
@@ -153,8 +155,6 @@ public function testFavPage(): void
private function prepareEntries(): KernelBrowser
{
- $client = $this->createClient();
-
$this->createEntryComment(
'test comment 1',
$this->getEntryByTitle('test entry 1', 'https://kbin.pub'),
@@ -171,11 +171,11 @@ private function prepareEntries(): KernelBrowser
$this->getUserByUsername('JohnDoe')
);
- return $client;
+ return $this->client;
}
private function getSortOptions(): array
{
- return ['hot', 'newest', 'active', 'oldest'];
+ return ['Hot', 'Newest', 'Active', 'Oldest'];
}
}
diff --git a/tests/Functional/Controller/Entry/Comment/EntryCommentModerateControllerTest.php b/tests/Functional/Controller/Entry/Comment/EntryCommentModerateControllerTest.php
index 0f696970d..4e7c3402e 100644
--- a/tests/Functional/Controller/Entry/Comment/EntryCommentModerateControllerTest.php
+++ b/tests/Functional/Controller/Entry/Comment/EntryCommentModerateControllerTest.php
@@ -10,42 +10,39 @@ class EntryCommentModerateControllerTest extends WebTestCase
{
public function testModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createEntryComment('test comment 1');
- $crawler = $client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
- $client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
+ $this->client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('Moderate')->link());
- $this->assertSelectorTextContains('.moderate-panel', 'ban');
+ $this->assertSelectorTextContains('.moderate-panel', 'Ban');
}
public function testXmlModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createEntryComment('test comment 1');
- $crawler = $client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('#entry-comment-'.$comment->getId())->selectLink('Moderate')->link());
- $this->assertStringContainsString('moderate-panel', $client->getResponse()->getContent());
+ $this->assertStringContainsString('moderate-panel', $this->client->getResponse()->getContent());
}
public function testUnauthorizedCanNotShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$comment = $this->createEntryComment('test comment 1');
- $client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
- $this->assertSelectorTextNotContains('#entry-comment-'.$comment->getId(), 'moderate');
+ $this->client->request('get', "/m/{$comment->magazine->name}/t/{$comment->entry->getId()}");
+ $this->assertSelectorTextNotContains('#entry-comment-'.$comment->getId(), 'Moderate');
- $client->request(
+ $this->client->request(
'get',
"/m/{$comment->magazine->name}/t/{$comment->entry->getId()}/-/comment/{$comment->getId()}/moderate"
);
diff --git a/tests/Functional/Controller/Entry/EntryBoostControllerTest.php b/tests/Functional/Controller/Entry/EntryBoostControllerTest.php
index 067bb10e3..a35385f54 100644
--- a/tests/Functional/Controller/Entry/EntryBoostControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryBoostControllerTest.php
@@ -10,8 +10,7 @@ class EntryBoostControllerTest extends WebTestCase
{
public function testLoggedUserCanBoostEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
@@ -21,17 +20,17 @@ public function testLoggedUserCanBoostEntry(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $client->submit(
- $crawler->filter('#main .entry')->selectButton('boost')->form([])
+ $this->client->submit(
+ $crawler->filter('#main .entry')->selectButton('Boost')->form([])
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
- $this->assertSelectorTextContains('#main .entry', 'boost (1)');
+ $this->assertSelectorTextContains('#main .entry', 'Boost (1)');
- $client->click($crawler->filter('#activity')->selectLink('boosts (1)')->link());
+ $this->client->click($crawler->filter('#activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JohnDoe');
}
diff --git a/tests/Functional/Controller/Entry/EntryChangeAdultControllerTest.php b/tests/Functional/Controller/Entry/EntryChangeAdultControllerTest.php
index 47606cc53..8e1ceb8cb 100644
--- a/tests/Functional/Controller/Entry/EntryChangeAdultControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryChangeAdultControllerTest.php
@@ -10,29 +10,30 @@ class EntryChangeAdultControllerTest extends WebTestCase
{
public function testModCanMarkAsAdultContent(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
'https://kbin.pub',
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
- $client->submit(
- $crawler->filter('.moderate-panel')->selectButton('18+ / nsfw')->form([
- 'adult' => true,
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Mark NSFW')->form([
+ 'adult' => 'on',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry .badge', '18+');
- $client->submit(
- $crawler->filter('.moderate-panel')->selectButton('18+ / nsfw')->form([
- 'adult' => false,
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Unmark NSFW')->form([
+ 'adult' => 'off',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextNotContains('#main .entry', '18+');
}
}
diff --git a/tests/Functional/Controller/Entry/EntryChangeLangControllerTest.php b/tests/Functional/Controller/Entry/EntryChangeLangControllerTest.php
index 5e4a43a82..a68fc9e5c 100644
--- a/tests/Functional/Controller/Entry/EntryChangeLangControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryChangeLangControllerTest.php
@@ -10,24 +10,23 @@ class EntryChangeLangControllerTest extends WebTestCase
{
public function testModCanChangeLanguage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
'https://kbin.pub',
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
- $form = $crawler->filter('.moderate-panel')->selectButton('change language')->form();
+ $form = $crawler->filter('.moderate-panel')->selectButton('Change language')->form();
$this->assertSame($form['lang']['lang']->getValue(), 'en');
$form['lang']['lang']->select('fr');
- $client->submit($form);
- $client->followRedirect();
+ $this->client->submit($form);
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .badge-lang', 'French');
}
diff --git a/tests/Functional/Controller/Entry/EntryChangeMagazineControllerTest.php b/tests/Functional/Controller/Entry/EntryChangeMagazineControllerTest.php
index f3714b47c..d933903a1 100644
--- a/tests/Functional/Controller/Entry/EntryChangeMagazineControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryChangeMagazineControllerTest.php
@@ -10,11 +10,9 @@ class EntryChangeMagazineControllerTest extends WebTestCase
{
public function testAdminCanChangeMagazine(): void
{
- $client = $this->createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$this->setAdmin($user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
$this->getMagazineByName('kbin');
@@ -23,27 +21,25 @@ public function testAdminCanChangeMagazine(): void
'https://kbin.pub',
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
- $client->submit(
- $crawler->filter('form[name=change_magazine]')->selectButton('change magazine')->form(
+ $this->client->submit(
+ $crawler->filter('form[name=change_magazine]')->selectButton('Change magazine')->form(
[
'change_magazine[new_magazine]' => 'kbin',
]
)
);
- $client->followRedirect();
- $client->followRedirect();
+ $this->client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('.head-title', 'kbin');
}
public function testUnauthorizedUserCantChangeMagazine(): void
{
- $client = $this->createClient();
-
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('kbin');
@@ -52,8 +48,8 @@ public function testUnauthorizedUserCantChangeMagazine(): void
'https://kbin.pub',
);
- $client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+ $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
- $this->assertSelectorTextNotContains('.moderate-panel', 'change magazine');
+ $this->assertSelectorTextNotContains('.moderate-panel', 'Change magazine');
}
}
diff --git a/tests/Functional/Controller/Entry/EntryCreateControllerTest.php b/tests/Functional/Controller/Entry/EntryCreateControllerTest.php
index 09976eec6..219017954 100644
--- a/tests/Functional/Controller/Entry/EntryCreateControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryCreateControllerTest.php
@@ -19,24 +19,22 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testUserCanCreateEntryLink()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $client->request('GET', '/m/acme/new');
+ $this->client->request('GET', '/m/acme/new');
$this->assertSelectorExists('form[name=entry_link]');
}
public function testUserCanCreateEntryLinkFromMagazinePage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/new');
+ $crawler = $this->client->request('GET', '/m/acme/new');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_link]')->selectButton('Add new link')->form(
[
'entry_link[url]' => 'https://kbin.pub',
@@ -46,32 +44,30 @@ public function testUserCanCreateEntryLinkFromMagazinePage(): void
)
);
- $this->assertResponseRedirects('/m/acme/newest');
- $client->followRedirect();
+ $this->assertResponseRedirects('/m/acme/threads/newest');
+ $this->client->followRedirect();
$this->assertSelectorTextContains('article h2', 'Test entry 1');
}
public function testUserCanCreateEntryArticle()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $client->request('GET', '/m/acme/new/article');
+ $this->client->request('GET', '/m/acme/new/article');
$this->assertSelectorExists('form[name=entry_article]');
}
public function testUserCanCreateEntryArticleFromMagazinePage()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/new/article');
+ $crawler = $this->client->request('GET', '/m/acme/new/article');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_article]')->selectButton('Add new thread')->form(
[
'entry_article[title]' => 'Test entry 1',
@@ -80,51 +76,51 @@ public function testUserCanCreateEntryArticleFromMagazinePage()
)
);
- $this->assertResponseRedirects('/m/acme/newest');
- $client->followRedirect();
+ $this->assertResponseRedirects('/m/acme/threads/newest');
+ $this->client->followRedirect();
$this->assertSelectorTextContains('article h2', 'Test entry 1');
}
public function testUserCanCreateEntryPhoto()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
- $client->request('GET', '/m/acme/new/photo');
+ $this->client->request('GET', '/m/acme/new/photo');
$this->assertSelectorExists('form[name=entry_image]');
}
public function testUserCanCreateEntryPhotoFromMagazinePage()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user'));
+ $this->client->loginUser($this->getUserByUsername('user'));
$this->getMagazineByName('acme');
$repository = $this->getService(EntryRepository::class);
- $crawler = $client->request('GET', '/m/acme/new/photo');
+ $crawler = $this->client->request('GET', '/m/acme/new/photo');
$this->assertSelectorExists('form[name=entry_image]');
- $form = $crawler->filter('#main form[name=entry_image]')->selectButton('Add new photo')->form();
- $form->get('entry_image[title]')->setValue('Test image 1');
- $form->get('entry_image[image]')->upload($this->kibbyPath);
+ $form = $crawler->filter('#main form[name=entry_image]')->selectButton('Add new photo')->form([
+ 'entry_image[title]' => 'Test image 1',
+ 'entry_image[image]' => $this->kibbyPath,
+ ]);
// Needed since we require this global to be set when validating entries but the client doesn't actually set it
$_FILES = $form->getPhpFiles();
- $client->submit($form);
+ $this->client->submit($form);
- $this->assertResponseRedirects('/m/acme/newest');
+ $this->assertResponseRedirects('/m/acme/threads/newest');
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('article h2', 'Test image 1');
$this->assertSelectorExists('figure img');
- $imgSrc = $crawler->filter('figure img')->getNode(0)->attributes->getNamedItem('src')->textContent;
+ $imgSrc = $crawler->filter('figure img.thumb-subject')->getNode(0)->attributes->getNamedItem('src')->textContent;
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $imgSrc);
- $entry = $repository->findOneBy(['user' => $this->getUserByUsername('user')]);
+ $user = $this->getUserByUsername('user');
+ $entry = $repository->findOneBy(['user' => $user]);
$this->assertNotNull($entry);
$this->assertNotNull($entry->image);
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $entry->image->filePath);
@@ -133,14 +129,13 @@ public function testUserCanCreateEntryPhotoFromMagazinePage()
public function testUserCanCreateEntryArticleForAdults()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('user', hideAdult: false));
+ $this->client->loginUser($this->getUserByUsername('user', hideAdult: false));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/new/article');
+ $crawler = $this->client->request('GET', '/m/acme/new/article');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=entry_article]')->selectButton('Add new thread')->form(
[
'entry_article[title]' => 'Test entry 1',
@@ -150,8 +145,8 @@ public function testUserCanCreateEntryArticleForAdults()
)
);
- $this->assertResponseRedirects('/m/acme/newest');
- $client->followRedirect();
+ $this->assertResponseRedirects('/m/acme/threads/newest');
+ $this->client->followRedirect();
$this->assertSelectorTextContains('article h2', 'Test entry 1');
$this->assertSelectorTextContains('article h2 .danger', '18+');
diff --git a/tests/Functional/Controller/Entry/EntryDeleteControllerTest.php b/tests/Functional/Controller/Entry/EntryDeleteControllerTest.php
index d12eff246..01dbd212c 100644
--- a/tests/Functional/Controller/Entry/EntryDeleteControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryDeleteControllerTest.php
@@ -5,22 +5,22 @@
namespace App\Tests\Functional\Controller\Entry;
use App\Tests\WebTestCase;
+use Symfony\Contracts\Translation\TranslatorInterface;
class EntryDeleteControllerTest extends WebTestCase
{
public function testUserCanDeleteEntry()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$entry = $this->getEntryByTitle('deletion test', body: 'will be deleted', magazine: $magazine, user: $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
$this->assertSelectorExists('form[action$="delete"]');
- $client->submit(
- $crawler->filter('form[action$="delete"]')->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter('form[action$="delete"]')->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
@@ -28,23 +28,24 @@ public function testUserCanDeleteEntry()
public function testUserCanSoftDeleteEntry()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$entry = $this->getEntryByTitle('deletion test', body: 'will be deleted', magazine: $magazine, user: $user);
$comment = $this->createEntryComment('only softly', $entry, $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
$this->assertSelectorExists('form[action$="delete"]');
- $client->submit(
- $crawler->filter('form[action$="delete"]')->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter('form[action$="delete"]')->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
- $client->request('GET', "/m/acme/t/{$entry->getId()}/deletion-test");
+ $this->client->request('GET', "/m/acme/t/{$entry->getId()}/deletion-test");
- $this->assertSelectorTextContains("#entry-{$entry->getId()} header", 'deleted_by_author');
+ $translator = $this->getService(TranslatorInterface::class);
+
+ $this->assertSelectorTextContains("#entry-{$entry->getId()} header", $translator->trans('deleted_by_author'));
}
}
diff --git a/tests/Functional/Controller/Entry/EntryEditControllerTest.php b/tests/Functional/Controller/Entry/EntryEditControllerTest.php
index ad0f12aa0..865835a79 100644
--- a/tests/Functional/Controller/Entry/EntryEditControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryEditControllerTest.php
@@ -10,30 +10,28 @@ class EntryEditControllerTest extends WebTestCase
{
public function testAuthorCanEditOwnEntryLink(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .entry');
- $this->assertInputValueSame('entry_link[url]', 'https://kbin.pub');
- $this->assertEquals('disabled', $crawler->filter('#entry_link_url')->attr('disabled'));
- $this->assertEquals('disabled', $crawler->filter('#entry_link_magazine_autocomplete')->attr('disabled'));
+ $this->assertInputValueSame('entry_edit[url]', 'https://kbin.pub');
+ $this->assertEquals('disabled', $crawler->filter('#entry_edit_magazine')->attr('disabled'));
- $client->submit(
- $crawler->filter('form[name=entry_link]')->selectButton('Edit link')->form(
+ $this->client->submit(
+ $crawler->filter('form[name=entry_edit]')->selectButton('Edit thread')->form(
[
- 'entry_link[title]' => 'test entry 2 title',
- 'entry_link[body]' => 'test entry 2 body',
+ 'entry_edit[title]' => 'test entry 2 title',
+ 'entry_edit[body]' => 'test entry 2 body',
]
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry header', 'test entry 2 title');
$this->assertSelectorTextContains('#main .entry .entry__body', 'test entry 2 body');
@@ -41,28 +39,27 @@ public function testAuthorCanEditOwnEntryLink(): void
public function testAuthorCanEditOwnEntryArticle(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', null, 'entry content test entry 1');
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .entry');
- $this->assertEquals('disabled', $crawler->filter('#entry_article_magazine_autocomplete')->attr('disabled'));
+ $this->assertEquals('disabled', $crawler->filter('#entry_edit_magazine')->attr('disabled'));
- $client->submit(
- $crawler->filter('form[name=entry_article]')->selectButton('Edit thread')->form(
+ $this->client->submit(
+ $crawler->filter('form[name=entry_edit]')->selectButton('Edit thread')->form(
[
- 'entry_article[title]' => 'test entry 2 title',
- 'entry_article[body]' => 'test entry 2 body',
+ 'entry_edit[title]' => 'test entry 2 title',
+ 'entry_edit[body]' => 'test entry 2 body',
]
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry header', 'test entry 2 title');
$this->assertSelectorTextContains('#main .entry .entry__body', 'test entry 2 body');
@@ -70,14 +67,13 @@ public function testAuthorCanEditOwnEntryArticle(): void
public function testAuthorCanEditOwnEntryImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', image: $this->getKibbyImageDto());
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$this->assertResponseIsSuccessful();
- $crawler = $client->click($crawler->filter('#main .entry')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .entry')->selectLink('Edit')->link());
$this->assertResponseIsSuccessful();
$this->assertSelectorExists('#main .entry');
@@ -86,17 +82,17 @@ public function testAuthorCanEditOwnEntryImage(): void
$this->assertNotNull($node);
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $node->attributes->getNamedItem('src')->textContent);
- $this->assertEquals('disabled', $crawler->filter('#entry_image_magazine_autocomplete')->attr('disabled'));
+ $this->assertEquals('disabled', $crawler->filter('#entry_edit_magazine')->attr('disabled'));
- $client->submit(
- $crawler->filter('form[name=entry_image]')->selectButton('Edit photo')->form(
+ $this->client->submit(
+ $crawler->filter('form[name=entry_edit]')->selectButton('Edit thread')->form(
[
- 'entry_image[title]' => 'test entry 2 title',
+ 'entry_edit[title]' => 'test entry 2 title',
]
)
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .entry header', 'test entry 2 title');
$this->assertSelectorExists('#main .entry img');
diff --git a/tests/Functional/Controller/Entry/EntryFrontControllerTest.php b/tests/Functional/Controller/Entry/EntryFrontControllerTest.php
index c6364827f..b6ec6576e 100644
--- a/tests/Functional/Controller/Entry/EntryFrontControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryFrontControllerTest.php
@@ -14,12 +14,12 @@ class EntryFrontControllerTest extends WebTestCase
{
public function testRootPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/');
+ $this->client->request('GET', '/');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/newest');
+ $crawler = $this->client->request('GET', '/newest');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
@@ -29,48 +29,44 @@ public function testRootPage(): void
$this->assertcount(2, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testXmlRootPage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testXmlRootPageIsFrontPage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/');
- $root_content = $this->clearTokens($client->getResponse()->getContent());
+ $root_content = $this->clearTokens($this->client->getResponse()->getContent());
- $client->request('GET', '/all');
+ $this->client->request('GET', '/all');
- $this->assertSame($root_content, $this->clearTokens($client->getResponse()->getContent()));
+ $this->assertSame($root_content, $this->clearTokens($this->client->getResponse()->getContent()));
}
public function testFrontPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/all');
+ $this->client->request('GET', '/all');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/all/newest');
+ $crawler = $this->client->request('GET', '/all/newest');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
@@ -80,35 +76,33 @@ public function testFrontPage(): void
$this->assertcount(2, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testXmlFrontPage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/all');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/all');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testMagazinePage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/m/acme');
+ $this->client->request('GET', '/m/acme');
$this->assertSelectorTextContains('h2', 'Hot');
- $client->request('GET', '/m/ACME');
+ $this->client->request('GET', '/m/ACME');
$this->assertSelectorTextContains('h2', 'Hot');
- $crawler = $client->request('GET', '/m/acme/newest');
+ $crawler = $this->client->request('GET', '/m/acme/threads/newest');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextNotContains('.entry__meta', 'to acme');
@@ -121,38 +115,36 @@ public function testMagazinePage(): void
$this->assertcount(1, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
- $this->assertSelectorTextContains('h1', 'Magazine title');
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
+ $this->assertSelectorTextContains('h1', 'acme');
$this->assertSelectorTextContains('h2', ucfirst($sortOption));
}
}
public function testXmlMagazinePage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/m/acme/newest');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/m/acme/newest');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testSubPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$magazineManager->subscribe($this->getMagazineByName('acme'), $this->getUserByUsername('Actor'));
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/sub');
+ $this->client->request('GET', '/sub');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/sub/newest');
+ $crawler = $this->client->request('GET', '/sub/threads/newest');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
@@ -164,44 +156,44 @@ public function testSubPage(): void
$this->assertcount(1, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testXmlSubPage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$magazineManager->subscribe($this->getMagazineByName('acme'), $this->getUserByUsername('Actor'));
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/sub');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/sub');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testModPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$moderator = new ModeratorDto($this->getMagazineByName('acme'));
$moderator->user = $this->getUserByUsername('Actor');
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/mod');
+ $this->client->request('GET', '/mod');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/mod/newest');
+ $crawler = $this->client->request('GET', '/mod/threads/newest');
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
@@ -213,34 +205,35 @@ public function testModPage(): void
$this->assertcount(1, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testXmlModPage(): void
{
- $client = $this->createClient();
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$moderator = new ModeratorDto($this->getMagazineByName('acme'));
$moderator->user = $this->getUserByUsername('Actor');
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/mod');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/mod');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testFavPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
$favouriteManager = $this->getService(FavouriteManager::class);
$favouriteManager->toggle(
@@ -248,12 +241,12 @@ public function testFavPage(): void
$this->getEntryByTitle('test entry 1', 'https://kbin.pub')
);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/fav');
+ $this->client->request('GET', '/fav');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/fav/newest');
+ $crawler = $this->client->request('GET', '/fav/threads/newest');
$this->assertSelectorTextContains('.entry__meta', 'JaneDoe');
$this->assertSelectorTextContains('.entry__meta', 'to kbin');
@@ -265,16 +258,14 @@ public function testFavPage(): void
$this->assertcount(1, $crawler->filter('.entry'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testXmlFavPage(): void
{
- $client = $this->createClient();
-
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
$favouriteManager = $this->getService(FavouriteManager::class);
@@ -283,18 +274,16 @@ public function testXmlFavPage(): void
$this->getEntryByTitle('test entry 1', 'https://kbin.pub')
);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->request('GET', '/fav');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->request('GET', '/fav');
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
private function prepareEntries(): KernelBrowser
{
- $client = $this->createClient();
-
$this->getEntryByTitle(
'test entry 1',
'https://kbin.pub',
@@ -305,12 +294,12 @@ private function prepareEntries(): KernelBrowser
$this->getEntryByTitle('test entry 2', 'https://kbin.pub');
- return $client;
+ return $this->client;
}
private function getSortOptions(): array
{
- return ['top', 'hot', 'newest', 'active', 'commented'];
+ return ['Top', 'Hot', 'Newest', 'Active', 'Commented'];
}
private function clearTokens(string $responseContent): string
diff --git a/tests/Functional/Controller/Entry/EntryModerateControllerTest.php b/tests/Functional/Controller/Entry/EntryModerateControllerTest.php
index ea8300889..f79c66918 100644
--- a/tests/Functional/Controller/Entry/EntryModerateControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryModerateControllerTest.php
@@ -10,42 +10,39 @@ class EntryModerateControllerTest extends WebTestCase
{
public function testModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('get', '/');
- $client->click($crawler->filter('#entry-'.$entry->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', '/');
+ $this->client->click($crawler->filter('#entry-'.$entry->getId())->selectLink('Moderate')->link());
$this->assertSelectorTextContains('.moderate-panel', 'ban');
}
public function testXmlModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('get', '/');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('#entry-'.$entry->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', '/');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('#entry-'.$entry->getId())->selectLink('Moderate')->link());
- $this->assertStringContainsString('moderate-panel', $client->getResponse()->getContent());
+ $this->assertStringContainsString('moderate-panel', $this->client->getResponse()->getContent());
}
public function testUnauthorizedCanNotShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->request('get', "/m/{$entry->magazine->name}/t/{$entry->getId()}");
- $this->assertSelectorTextNotContains('#entry-'.$entry->getId(), 'moderate');
+ $this->client->request('get', "/m/{$entry->magazine->name}/t/{$entry->getId()}");
+ $this->assertSelectorTextNotContains('#entry-'.$entry->getId(), 'Moderate');
- $client->request(
+ $this->client->request(
'get',
"/m/{$entry->magazine->name}/t/{$entry->getId()}/-/moderate"
);
diff --git a/tests/Functional/Controller/Entry/EntryPinControllerTest.php b/tests/Functional/Controller/Entry/EntryPinControllerTest.php
index 7affbdf9e..87079a217 100644
--- a/tests/Functional/Controller/Entry/EntryPinControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryPinControllerTest.php
@@ -10,22 +10,21 @@ class EntryPinControllerTest extends WebTestCase
{
public function testModCanPinEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
'https://kbin.pub',
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/-/moderate");
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('pin')->form([]));
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Pin')->form([]));
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#main .entry .fa-thumbtack');
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('unpin')->form([]));
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Unpin')->form([]));
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#main .entry .fa-thumbtack');
}
}
diff --git a/tests/Functional/Controller/Entry/EntrySingleControllerTest.php b/tests/Functional/Controller/Entry/EntrySingleControllerTest.php
index 90eec5d98..6a4246191 100644
--- a/tests/Functional/Controller/Entry/EntrySingleControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntrySingleControllerTest.php
@@ -13,16 +13,15 @@ class EntrySingleControllerTest extends WebTestCase
{
public function testUserCanGoToEntryFromFrontpage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/');
$this->assertSelectorTextContains('#header nav .active', 'Threads');
- $client->click($crawler->selectLink('test entry 1')->link());
+ $this->client->click($crawler->selectLink('test entry 1')->link());
$this->assertSelectorTextContains('.head-title', '/m/acme');
$this->assertSelectorTextContains('#header nav .active', 'Threads');
@@ -35,12 +34,11 @@ public function testUserCanGoToEntryFromFrontpage(): void
public function testUserCanSeeArticle(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', null, 'Test entry content');
- $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$this->assertSelectorTextContains('article h1', 'test entry 1');
$this->assertSelectorNotExists('article h1 > a');
@@ -49,52 +47,49 @@ public function testUserCanSeeArticle(): void
public function testUserCanSeeLink(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$this->assertSelectorExists('article h1 a[href="https://kbin.pub"]', 'test entry 1');
}
public function testPostActivityCounter(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $manager = $client->getContainer()->get(VoteManager::class);
+ $manager = $this->client->getContainer()->get(VoteManager::class);
$manager->vote(VotableInterface::VOTE_DOWN, $entry, $this->getUserByUsername('JaneDoe'));
- $manager = $client->getContainer()->get(FavouriteManager::class);
+ $manager = $this->client->getContainer()->get(FavouriteManager::class);
$manager->toggle($this->getUserByUsername('JohnDoe'), $entry);
$manager->toggle($this->getUserByUsername('JaneDoe'), $entry);
- $client->request('GET', "/m/acme/t/{$entry->getId()}/-/test-entry-1");
+ $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$this->assertSelectorTextContains('.options-activity', 'Activity (2)');
}
public function testCanSortComments()
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
$this->createEntryComment('test comment 1', $entry);
$this->createEntryComment('test comment 2', $entry);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
+ $crawler = $this->client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
$this->assertSelectorTextContains('.options__main', $sortOption);
}
}
private function getSortOptions(): array
{
- return ['hot', 'newest', 'active', 'oldest'];
+ return ['Top', 'Hot', 'Newest', 'Active', 'Oldest'];
}
}
diff --git a/tests/Functional/Controller/Entry/EntryVotersControllerTest.php b/tests/Functional/Controller/Entry/EntryVotersControllerTest.php
index b5bf0bc0a..6ac66a70c 100644
--- a/tests/Functional/Controller/Entry/EntryVotersControllerTest.php
+++ b/tests/Functional/Controller/Entry/EntryVotersControllerTest.php
@@ -12,35 +12,34 @@ class EntryVotersControllerTest extends WebTestCase
{
public function testUserCanSeeUpVoters(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $manager = $client->getContainer()->get(VoteManager::class);
+ $manager = $this->client->getContainer()->get(VoteManager::class);
$manager->vote(VotableInterface::VOTE_UP, $entry, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $client->click($crawler->filter('.options-activity')->selectLink('boosts (1)')->link());
+ $this->client->click($crawler->filter('.options-activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
}
- public function testUserCanSeeDownVoters(): void
+ public function testUserCannotSeeDownVoters(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $manager = $client->getContainer()->get(VoteManager::class);
+ $manager = $this->client->getContainer()->get(VoteManager::class);
$manager->vote(VotableInterface::VOTE_DOWN, $entry, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $client->click($crawler->filter('.options-activity')->selectLink('reduces (1)')->link());
+ $crawler = $crawler->filter('.options-activity')->selectLink('Reduces (1)');
+ self::assertEquals(0, $crawler->count());
- $this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
+ $this->assertSelectorTextContains('.options-activity', 'Reduces (1)');
}
}
diff --git a/tests/Functional/Controller/Magazine/MagazineBlockControllerTest.php b/tests/Functional/Controller/Magazine/MagazineBlockControllerTest.php
index ee8c73610..982e0521f 100644
--- a/tests/Functional/Controller/Magazine/MagazineBlockControllerTest.php
+++ b/tests/Functional/Controller/Magazine/MagazineBlockControllerTest.php
@@ -10,60 +10,57 @@ class MagazineBlockControllerTest extends WebTestCase
{
public function testUserCanBlockAndUnblockMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
// Block magazine
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=magazine_block] .active');
// Unblock magazine
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#sidebar form[name=magazine_block] .active');
}
public function testXmlUserCanBlockMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('active', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnblockMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
// Block magazine
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $crawler = $this->client->followRedirect();
// Unblock magazine
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=magazine_block] button')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringNotContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringNotContainsString('active', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/Magazine/MagazineCreateControllerTest.php b/tests/Functional/Controller/Magazine/MagazineCreateControllerTest.php
index 5fb64a80e..b6bc9b354 100644
--- a/tests/Functional/Controller/Magazine/MagazineCreateControllerTest.php
+++ b/tests/Functional/Controller/Magazine/MagazineCreateControllerTest.php
@@ -10,12 +10,11 @@ class MagazineCreateControllerTest extends WebTestCase
{
public function testUserCanCreateMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/newMagazine');
+ $crawler = $this->client->request('GET', '/newMagazine');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=magazine]')->selectButton('Create new magazine')->form(
[
'magazine[name]' => 'TestMagazine',
@@ -26,7 +25,7 @@ public function testUserCanCreateMagazine(): void
$this->assertResponseRedirects('/m/TestMagazine');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('.head-title', '/m/TestMagazine');
$this->assertSelectorTextContains('#content', 'Empty');
@@ -34,12 +33,11 @@ public function testUserCanCreateMagazine(): void
public function testUserCantCreateInvalidMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/newMagazine');
+ $crawler = $this->client->request('GET', '/newMagazine');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=magazine]')->selectButton('Create new magazine')->form(
[
'magazine[name]' => 't',
@@ -53,14 +51,13 @@ public function testUserCantCreateInvalidMagazine(): void
public function testUserCantCreateTwoSameMagazines(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/newMagazine');
+ $crawler = $this->client->request('GET', '/newMagazine');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=magazine]')->selectButton('Create new magazine')->form(
[
'magazine[name]' => 'acme',
diff --git a/tests/Functional/Controller/Magazine/MagazineListControllerTest.php b/tests/Functional/Controller/Magazine/MagazineListControllerTest.php
index 3e95266a8..ca5fdb918 100644
--- a/tests/Functional/Controller/Magazine/MagazineListControllerTest.php
+++ b/tests/Functional/Controller/Magazine/MagazineListControllerTest.php
@@ -5,26 +5,27 @@
namespace App\Tests\Functional\Controller\Magazine;
use App\Tests\WebTestCase;
+use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\DomCrawler\Crawler;
class MagazineListControllerTest extends WebTestCase
{
- /** @dataProvider magazines */
+ #[DataProvider('magazines')]
public function testMagazineListIsFiltered(array $queryParams, array $expectedMagazines): void
{
- $client = $this->createClient();
-
$this->loadExampleMagazines();
- $crawler = $client->request('GET', '/magazines');
+ $crawler = $this->client->request('GET', '/magazines');
- $crawler = $client->submit(
+ $crawler = $this->client->submit(
$crawler->filter('form[method=get]')->selectButton('')->form($queryParams)
);
+ $actualMagazines = $crawler->filter('#content .table-responsive .magazine-inline')->each(fn (Crawler $node) => $node->innerText());
+
$this->assertSame(
- $expectedMagazines,
- $crawler->filter('#content .table-responsive .magazine-inline')->each(fn (Crawler $node) => $node->innerText()),
+ sort($expectedMagazines),
+ sort($actualMagazines),
);
}
@@ -32,12 +33,12 @@ public static function magazines(): iterable
{
return [
[['query' => 'test'], []],
- [['query' => 'acme'], ['acme']],
- [['query' => '', 'adult' => 'only'], ['adult']],
+ [['query' => 'acme'], ['Magazyn polityczny']],
+ [['query' => '', 'adult' => 'only'], ['Adult only']],
[['query' => 'acme', 'adult' => 'only'], []],
- [['query' => 'foobar', 'fields' => 'names_descriptions'], ['acme']],
- [['adult' => 'show'], ['acme', 'kbin', 'adult', 'starwarsmemes@republic.new']],
- [['federation' => 'local'], ['acme', 'kbin', 'adult']],
+ [['query' => 'foobar', 'fields' => 'names_descriptions'], ['Magazyn polityczny']],
+ [['adult' => 'show'], ['Magazyn polityczny', 'kbin devlog', 'Adult only', 'starwarsmemes@republic.new']],
+ [['federation' => 'local'], ['Magazyn polityczny', 'kbin devlog', 'Adult only']],
[['query' => 'starwars', 'federation' => 'local'], []],
[['query' => 'starwars', 'federation' => 'all'], ['starwarsmemes@republic.new']],
[['query' => 'trap', 'fields' => 'names_descriptions'], ['starwarsmemes@republic.new']],
diff --git a/tests/Functional/Controller/Magazine/MagazinePeopleControllerTest.php b/tests/Functional/Controller/Magazine/MagazinePeopleControllerTest.php
index c5bcd0a25..6777729ca 100644
--- a/tests/Functional/Controller/Magazine/MagazinePeopleControllerTest.php
+++ b/tests/Functional/Controller/Magazine/MagazinePeopleControllerTest.php
@@ -11,15 +11,13 @@ class MagazinePeopleControllerTest extends WebTestCase
{
public function testMagazinePeoplePage(): void
{
- $client = $this->createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$this->createPost('test post content');
$user->about = 'Loerm ipsum';
$this->getService(EntityManagerInterface::class)->flush();
- $crawler = $client->request('GET', '/m/acme/people');
+ $crawler = $this->client->request('GET', '/m/acme/people');
$this->assertEquals(1, $crawler->filter('#main .user-box')->count());
$this->assertSelectorTextContains('#main .users .user-box', 'Loerm ipsum');
diff --git a/tests/Functional/Controller/Magazine/MagazineSubControllerTest.php b/tests/Functional/Controller/Magazine/MagazineSubControllerTest.php
index 0b14ab342..a7a6ec7ba 100644
--- a/tests/Functional/Controller/Magazine/MagazineSubControllerTest.php
+++ b/tests/Functional/Controller/Magazine/MagazineSubControllerTest.php
@@ -10,61 +10,58 @@ class MagazineSubControllerTest extends WebTestCase
{
public function testUserCanSubAndUnsubMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
// Sub magazine
- $client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=magazine_subscribe] .active');
$this->assertSelectorTextContains('#sidebar .magazine', 'Unsubscribe');
$this->assertSelectorTextContains('#sidebar .magazine', '2');
// Unsub magazine
- $client->submit($crawler->filter('#sidebar .magazine')->selectButton('Unsubscribe')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .magazine')->selectButton('Unsubscribe')->form());
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#sidebar .magazine', '1');
}
public function testXmlUserCanSubMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Unsubscribe', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Unsubscribe', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnsubMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme');
+ $crawler = $this->client->request('GET', '/m/acme');
// Sub magazine
- $client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .magazine')->selectButton('Subscribe')->form());
+ $crawler = $this->client->followRedirect();
// Unsub magazine
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .magazine')->selectButton('Unsubscribe')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .magazine')->selectButton('Unsubscribe')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Subscribe', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Subscribe', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineAppearanceControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineAppearanceControllerTest.php
index 45a5b867a..88a16ba1b 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineAppearanceControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineAppearanceControllerTest.php
@@ -10,15 +10,14 @@ class MagazineAppearanceControllerTest extends WebTestCase
{
public function testOwnerCanEditMagazineTheme(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/panel/appearance');
- $this->assertSelectorTextContains('#main .options__main a.active', 'appearance');
+ $crawler = $this->client->request('GET', '/m/acme/panel/appearance');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Appearance');
$form = $crawler->filter('#main form[name=magazine_theme]')->selectButton('Done')->form();
$form['magazine_theme[icon]']->upload($this->kibbyPath);
- $crawler = $client->submit($form);
+ $crawler = $this->client->submit($form);
$this->assertResponseIsSuccessful();
$this->assertSelectorExists('#sidebar .magazine img');
@@ -28,27 +27,25 @@ public function testOwnerCanEditMagazineTheme(): void
public function testOwnerCanEditMagazineCSS(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/panel/appearance');
- $this->assertSelectorTextContains('#main .options__main a.active', 'appearance');
+ $crawler = $this->client->request('GET', '/m/acme/panel/appearance');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Appearance');
$form = $crawler->filter('#main form[name=magazine_theme]')->selectButton('Done')->form();
$form['magazine_theme[customCss]']->setValue('#middle { display: none; }');
- $crawler = $client->submit($form);
+ $crawler = $this->client->submit($form);
$this->assertResponseIsSuccessful();
}
public function testUnauthorizedUserCannotEditMagazineTheme(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/appearance');
+ $this->client->request('GET', '/m/acme/panel/appearance');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineBadgeControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineBadgeControllerTest.php
index 27d9693df..7f8dfc116 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineBadgeControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineBadgeControllerTest.php
@@ -10,39 +10,37 @@ class MagazineBadgeControllerTest extends WebTestCase
{
public function testModCanAddAndRemoveBadge(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
// Add badge
- $crawler = $client->request('GET', '/m/acme/panel/badges');
- $this->assertSelectorTextContains('#main .options__main a.active', 'badges');
- $client->submit(
+ $crawler = $this->client->request('GET', '/m/acme/panel/badges');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Badges');
+ $this->client->submit(
$crawler->filter('#main form[name=badge]')->selectButton('Add badge')->form([
'badge[name]' => 'test',
])
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .badges', 'test');
// Remove badge
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main .badges')->selectButton('Delete')->form()
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .section--muted', 'Empty');
}
public function testUnauthorizedUserCannotAddBadge(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/badges');
+ $this->client->request('GET', '/m/acme/panel/badges');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineBanControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineBanControllerTest.php
index dfb29534c..9b0e3c1aa 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineBanControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineBanControllerTest.php
@@ -10,48 +10,46 @@ class MagazineBanControllerTest extends WebTestCase
{
public function testModCanAddAndRemoveBan(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getUserByUsername('JaneDoe');
$this->getMagazineByName('acme');
// Add ban
- $crawler = $client->request('GET', '/m/acme/panel/bans');
- $this->assertSelectorTextContains('#main .options__main a.active', 'bans');
- $crawler = $client->submit(
+ $crawler = $this->client->request('GET', '/m/acme/panel/bans');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Bans');
+ $crawler = $this->client->submit(
$crawler->filter('#main form[name=ban]')->selectButton('Add ban')->form([
'username' => 'JaneDoe',
])
);
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form[name=magazine_ban]')->selectButton('Ban')->form([
'magazine_ban[reason]' => 'Reason test',
'magazine_ban[expiredAt]' => (new \DateTime('+2 weeks'))->format('Y-m-d H:i:s'),
])
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .bans-table', 'JaneDoe');
// Remove ban
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main .bans-table')->selectButton('Delete')->form()
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .bans-table', 'seconds');
}
public function testUnauthorizedUserCannotAddBan(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/bans');
+ $this->client->request('GET', '/m/acme/panel/bans');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineEditControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineEditControllerTest.php
index 088b3bcd9..3a597750c 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineEditControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineEditControllerTest.php
@@ -4,29 +4,37 @@
namespace App\Tests\Functional\Controller\Magazine\Panel;
+use App\DTO\ModeratorDto;
+use App\Service\MagazineManager;
use App\Tests\WebTestCase;
class MagazineEditControllerTest extends WebTestCase
{
- public function testModCanSeePanelLink(): void
+ public function testModCannotSeePanelLink(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $this->getMagazineByName('acme');
+ $mod = $this->getUserByUsername('JohnDoe');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
+ $this->client->loginUser($mod);
+ $magazine = $this->getMagazineByName('acme', $admin);
+
+ $manager = $this->getService(MagazineManager::class);
+ $dto = new ModeratorDto($magazine, $mod, $admin);
+ $manager->addModerator($dto);
- $client->request('GET', '/m/acme');
- $this->assertSelectorTextContains('#sidebar .magazine', 'Magazine panel');
+ $this->client->request('GET', '/m/acme');
+ $this->assertSelectorTextNotContains('#sidebar .magazine', 'Magazine panel');
}
public function testOwnerCanEditMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
- $this->getMagazineByName('acme');
-
- $crawler = $client->request('GET', '/m/acme/panel/general');
- $this->assertSelectorTextContains('#main .options__main a.active', 'general');
- $client->submit(
+ $owner = $this->getUserByUsername('JohnDoe');
+ $this->client->loginUser($owner);
+ $this->getMagazineByName('acme', $owner);
+
+ $crawler = $this->client->request('GET', '/m/acme/panel/general');
+ self::assertResponseIsSuccessful();
+ $this->assertSelectorTextContains('#main .options__main a.active', 'General');
+ $this->client->submit(
$crawler->filter('#main form[name=magazine]')->selectButton('Done')->form([
'magazine[description]' => 'test description edit',
'magazine[rules]' => 'test rules edit',
@@ -34,19 +42,18 @@ public function testOwnerCanEditMagazine(): void
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#sidebar .magazine', 'test description edit');
$this->assertSelectorTextContains('#sidebar .magazine', 'test rules edit');
}
public function testUnauthorizedUserCannotEditMagazine(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/general');
+ $this->client->request('GET', '/m/acme/panel/general');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineModeratorControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineModeratorControllerTest.php
index bc94af11e..d965d84dc 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineModeratorControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineModeratorControllerTest.php
@@ -10,15 +10,14 @@ class MagazineModeratorControllerTest extends WebTestCase
{
public function testOwnerCanAddAndRemoveModerator(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getUserByUsername('JaneDoe');
$this->getMagazineByName('acme');
// Add moderator
- $crawler = $client->request('GET', '/m/acme/panel/moderators');
- $this->assertSelectorTextContains('#main .options__main a.active', 'moderators');
- $crawler = $client->submit(
+ $crawler = $this->client->request('GET', '/m/acme/panel/moderators');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Moderators');
+ $crawler = $this->client->submit(
$crawler->filter('#main form[name=moderator]')->selectButton('Add moderator')->form([
'moderator[user]' => 'JaneDoe',
])
@@ -27,23 +26,22 @@ public function testOwnerCanAddAndRemoveModerator(): void
$this->assertEquals(2, $crawler->filter('#main .users-columns ul li')->count());
// Remove moderator
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main .users-columns')->selectButton('Delete')->form()
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextNotContains('#main .users-columns', 'JaneDoe');
$this->assertEquals(1, $crawler->filter('#main .users-columns ul li')->count());
}
public function testUnauthorizedUserCannotAddModerator(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/moderators');
+ $this->client->request('GET', '/m/acme/panel/moderators');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineReportControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineReportControllerTest.php
index 68cb76da4..be651182f 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineReportControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineReportControllerTest.php
@@ -12,8 +12,7 @@ class MagazineReportControllerTest extends WebTestCase
{
public function testModCanSeeEntryReports(): void
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JohnDoe'));
$user2 = $this->getUserByUsername('JaneDoe');
$entryComment = $this->createEntryComment('Test comment 1');
@@ -26,10 +25,10 @@ public function testModCanSeeEntryReports(): void
);
}
- $client->request('GET', '/');
- $crawler = $client->request('GET', '/m/acme/panel/reports');
+ $this->client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/m/acme/panel/reports');
- $this->assertSelectorTextContains('#main .options__main a.active', 'reports');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Reports');
$this->assertEquals(
4,
$crawler->filter('#main .report')->count()
@@ -38,12 +37,11 @@ public function testModCanSeeEntryReports(): void
public function testUnauthorizedUserCannotSeeReports(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/reports');
+ $this->client->request('GET', '/m/acme/panel/reports');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/Magazine/Panel/MagazineTrashControllerTest.php b/tests/Functional/Controller/Magazine/Panel/MagazineTrashControllerTest.php
index bbc5f8ae0..ba892a574 100644
--- a/tests/Functional/Controller/Magazine/Panel/MagazineTrashControllerTest.php
+++ b/tests/Functional/Controller/Magazine/Panel/MagazineTrashControllerTest.php
@@ -10,8 +10,7 @@ class MagazineTrashControllerTest extends WebTestCase
{
public function testModCanSeeEntryInTrash(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
$entry = $this->getEntryByTitle(
@@ -22,18 +21,17 @@ public function testModCanSeeEntryInTrash(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId().'/test-entry-1/moderate');
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('delete')->form([]));
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId().'/test-entry-1/moderate');
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Delete')->form([]));
- $client->request('GET', '/m/acme/panel/trash');
- $this->assertSelectorTextContains('#main .options__main a.active', 'trash');
+ $this->client->request('GET', '/m/acme/panel/trash');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Trash');
$this->assertSelectorTextContains('#main .entry', 'Test entry 1');
}
public function testModCanSeeEntryCommentInTrash(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
$comment = $this->createEntryComment(
@@ -42,20 +40,19 @@ public function testModCanSeeEntryCommentInTrash(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request(
+ $crawler = $this->client->request(
'GET',
'/m/acme/t/'.$comment->entry->getId().'/test-entry-1/comment/'.$comment->getId().'/moderate'
);
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('delete')->form([]));
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Delete')->form([]));
- $client->request('GET', '/m/acme/panel/trash');
+ $this->client->request('GET', '/m/acme/panel/trash');
$this->assertSelectorTextContains('#main .comment', 'Test comment 1');
}
public function testModCanSeePostInTrash(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
$post = $this->createPost(
@@ -64,20 +61,19 @@ public function testModCanSeePostInTrash(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request(
+ $crawler = $this->client->request(
'GET',
'/m/acme/p/'.$post->getId().'/-/moderate'
);
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('delete')->form([]));
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Delete')->form([]));
- $client->request('GET', '/m/acme/panel/trash');
+ $this->client->request('GET', '/m/acme/panel/trash');
$this->assertSelectorTextContains('#main .post', 'Test post 1');
}
public function testModCanSeePostCommentInTrash(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
$comment = $this->createPostComment(
@@ -86,24 +82,23 @@ public function testModCanSeePostCommentInTrash(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request(
+ $crawler = $this->client->request(
'GET',
'/m/acme/p/'.$comment->post->getId().'/test-entry-1/reply/'.$comment->getId().'/moderate'
);
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('delete')->form([]));
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Delete')->form([]));
- $client->request('GET', '/m/acme/panel/trash');
+ $this->client->request('GET', '/m/acme/panel/trash');
$this->assertSelectorTextContains('#main .comment', 'Test comment 1');
}
public function testUnauthorizedUserCannotSeeTrash(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$this->getMagazineByName('acme');
- $client->request('GET', '/m/acme/panel/trash');
+ $this->client->request('GET', '/m/acme/panel/trash');
$this->assertResponseStatusCodeSame(403);
}
diff --git a/tests/Functional/Controller/People/FrontControllerTest.php b/tests/Functional/Controller/People/FrontControllerTest.php
index 2f6038fb2..aeda352f3 100644
--- a/tests/Functional/Controller/People/FrontControllerTest.php
+++ b/tests/Functional/Controller/People/FrontControllerTest.php
@@ -11,14 +11,12 @@ class FrontControllerTest extends WebTestCase
{
public function testFrontPeoplePage(): void
{
- $client = $this->createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$user->about = 'Loerm ipsum';
$this->getService(EntityManagerInterface::class)->flush();
- $crawler = $client->request('GET', '/people');
+ $crawler = $this->client->request('GET', '/people');
$this->assertEquals(1, $crawler->filter('#main .user-box')->count());
$this->assertSelectorTextContains('#main .users .user-box', 'Loerm ipsum');
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentBoostControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentBoostControllerTest.php
index bd6153df8..7ea68c812 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentBoostControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentBoostControllerTest.php
@@ -10,25 +10,28 @@ class PostCommentBoostControllerTest extends WebTestCase
{
public function testLoggedUserBoostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1', null, $this->getUserByUsername('JaneDoe'));
- $this->createPostComment('test comment 1', $post, $this->getUserByUsername('JaneDoe'));
+ $comment = $this->createPostComment('test comment 1', $post, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $client->submit(
- $crawler->filter('#main .post-comment')->selectButton('boost')->form([])
+ $crawler = $this->client->submit(
+ $crawler->filter("#post-comment-{$comment->getId()}")->selectButton('Boost')->form()
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
+ self::assertResponseIsSuccessful();
- $this->assertSelectorTextContains('#main .post-comment', 'boost (1)');
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post-comment')->selectLink('activity')->link());
+ // $this->assertSelectorTextContains("#post-comment-{$comment->getId()}", 'Boost (1)');
- $client->click($crawler->filter('#main #activity')->selectLink('boosts (1)')->link());
+ $crawler = $this->client->click($crawler->filter("#post-comment-{$comment->getId()}")->selectLink('Activity')->link());
+
+ $this->assertSelectorTextContains('#main #activity', 'Boosts (1)');
+ $this->client->click($crawler->filter('#main #activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JohnDoe');
}
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentChangeLangControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentChangeLangControllerTest.php
index afe50a19b..bccb996d9 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentChangeLangControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentChangeLangControllerTest.php
@@ -10,21 +10,20 @@ class PostCommentChangeLangControllerTest extends WebTestCase
{
public function testModCanChangeLanguage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createPostComment('test comment 1');
- $crawler = $client->request('GET', "/m/acme/p/{$comment->post->getId()}/-/reply/{$comment->getId()}/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$comment->post->getId()}/-/reply/{$comment->getId()}/moderate");
- $form = $crawler->filter('.moderate-panel')->selectButton('change language')->form();
+ $form = $crawler->filter('.moderate-panel')->selectButton('Change language')->form();
$this->assertSame($form['lang']['lang']->getValue(), 'en');
$form['lang']['lang']->select('fr');
- $client->submit($form);
- $client->followRedirect();
+ $this->client->submit($form);
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .badge-lang', 'French');
}
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentCreateControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentCreateControllerTest.php
index 83c23f13f..5adc0efd8 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentCreateControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentCreateControllerTest.php
@@ -16,14 +16,13 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testUserCanCreatePostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', '/m/acme/p/'.$post->getId().'/test-post-1');
+ $crawler = $this->client->request('GET', '/m/acme/p/'.$post->getId().'/test-post-1/reply');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post_comment]')->selectButton('Add comment')->form(
[
'post_comment[body]' => 'test comment 1',
@@ -32,29 +31,28 @@ public function testUserCanCreatePostComment(): void
);
$this->assertResponseRedirects('/m/acme/p/'.$post->getId().'/test-post-1');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#comments .content', 'test comment 1');
}
public function testUserCanCreatePostCommentWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1/reply");
$form = $crawler->filter('form[name=post_comment]')->selectButton('Add comment')->form();
$form->get('post_comment[body]')->setValue('Test comment 1');
$form->get('post_comment[image]')->upload($this->kibbyPath);
// Needed since we require this global to be set when validating entries but the client doesn't actually set it
$_FILES = $form->getPhpFiles();
- $client->submit($form);
+ $this->client->submit($form);
$this->assertResponseRedirects("/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#comments .content', 'Test comment 1');
$this->assertSelectorExists('#comments footer figure img');
@@ -65,14 +63,13 @@ public function testUserCanCreatePostCommentWithImage(): void
public function testUserCannotCreateInvalidPostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', '/m/acme/p/'.$post->getId().'/test-post-1');
+ $crawler = $this->client->request('GET', '/m/acme/p/'.$post->getId().'/test-post-1/reply');
- $crawler = $client->submit(
+ $crawler = $this->client->submit(
$crawler->filter('form[name=post_comment]')->selectButton('Add comment')->form(
[
'post_comment[body]' => '',
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentDeleteControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentDeleteControllerTest.php
index 9dba27b41..3d2f639db 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentDeleteControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentDeleteControllerTest.php
@@ -5,23 +5,49 @@
namespace App\Tests\Functional\Controller\Post\Comment;
use App\Tests\WebTestCase;
+use Symfony\Contracts\Translation\TranslatorInterface;
class PostCommentDeleteControllerTest extends WebTestCase
{
- public function testUserCanDeletePostComment()
+ public function testUserCannotPurgePostComment()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
- $magazine = $this->getMagazineByName('acme');
+ $magazine = $this->getMagazineByName('acme', $user);
$post = $this->createPost('deletion test', magazine: $magazine, user: $user);
$comment = $this->createPostComment('delete me!', $post, $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ self::assertResponseIsSuccessful();
- $this->assertSelectorExists('#comments form[action$="delete"]');
- $client->submit(
- $crawler->filter('#comments form[action$="delete"]')->selectButton('delete')->form()
+ $link = $crawler->filter('#comments .post-comment footer')->selectLink('Moderate')->link();
+ $crawler = $this->client->click($link);
+ self::assertResponseIsSuccessful();
+
+ $this->assertSelectorNotExists('.moderate-panel form[action$="purge"]');
+ }
+
+ public function testAdminCanPurgePostComment()
+ {
+ $user = $this->getUserByUsername('user');
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
+ $magazine = $this->getMagazineByName('acme', $user);
+ $post = $this->createPost('deletion test', magazine: $magazine, user: $user);
+ $comment = $this->createPostComment('delete me!', $post, $user);
+ $this->client->loginUser($admin);
+ self::assertTrue($admin->isAdmin());
+
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ self::assertResponseIsSuccessful();
+
+ $link = $crawler->filter("#comments #post-comment-{$comment->getId()} footer")->selectLink('Moderate')->link();
+ $crawler = $this->client->click($link);
+ self::assertResponseIsSuccessful();
+
+ self::assertSelectorExists('.moderate-panel');
+ $this->assertSelectorExists('.moderate-panel form[action$="purge"]');
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Purge')->form()
);
$this->assertResponseRedirects();
@@ -29,24 +55,29 @@ public function testUserCanDeletePostComment()
public function testUserCanSoftDeletePostComment()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
- $magazine = $this->getMagazineByName('acme');
+ $magazine = $this->getMagazineByName('acme', $user);
$post = $this->createPost('deletion test', magazine: $magazine, user: $user);
$comment = $this->createPostComment('delete me!', $post, $user);
$reply = $this->createPostCommentReply('Are you deleted yet?', $post, $user, $comment);
- $client->loginUser($user);
+ $this->client->loginUser($user);
+
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ self::assertResponseIsSuccessful();
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $link = $crawler->filter('#comments .post-comment footer')->selectLink('Moderate')->link();
+ $crawler = $this->client->click($link);
+ self::assertResponseIsSuccessful();
- $this->assertSelectorExists("#post-comment-{$comment->getId()} form[action$=\"delete\"]");
- $client->submit(
- $crawler->filter("#post-comment-{$comment->getId()} form[action$=\"delete\"]")->selectButton('delete')->form()
+ $this->assertSelectorExists('.moderate-panel form[action$="delete"]');
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
- $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
- $this->assertSelectorTextContains("#post-comment-{$comment->getId()} .content", 'deleted_by_author');
+ $translator = $this->getService(TranslatorInterface::class);
+ $this->assertSelectorTextContains("#post-comment-{$comment->getId()} .content", $translator->trans('deleted_by_author'));
}
}
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentEditControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentEditControllerTest.php
index 2ccd90b5c..037fffdcd 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentEditControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentEditControllerTest.php
@@ -10,20 +10,19 @@ class PostCommentEditControllerTest extends WebTestCase
{
public function testAuthorCanEditOwnPostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
$this->createPostComment('test comment 1', $post);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post-comment')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .post-comment')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .post-comment');
$this->assertSelectorTextContains('textarea[name="post_comment[body]"]', 'test comment 1');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post_comment]')->selectButton('Save changes')->form(
[
'post_comment[body]' => 'test comment 2 body',
@@ -31,22 +30,21 @@ public function testAuthorCanEditOwnPostComment(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .post-comment', 'test comment 2 body');
}
public function testAuthorCanEditOwnPostCommentWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
$this->createPostComment('test comment 1', $post, imageDto: $this->getKibbyImageDto());
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post-comment')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .post-comment')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .post-comment');
$this->assertSelectorTextContains('textarea[name="post_comment[body]"]', 'test comment 1');
@@ -55,7 +53,7 @@ public function testAuthorCanEditOwnPostCommentWithImage(): void
$this->assertNotNull($node);
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $node->attributes->getNamedItem('src')->textContent);
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post_comment]')->selectButton('Save changes')->form(
[
'post_comment[body]' => 'test comment 2 body',
@@ -63,7 +61,7 @@ public function testAuthorCanEditOwnPostCommentWithImage(): void
)
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .post-comment', 'test comment 2 body');
$this->assertSelectorExists('#main .post-comment img');
diff --git a/tests/Functional/Controller/Post/Comment/PostCommentModerateControllerTest.php b/tests/Functional/Controller/Post/Comment/PostCommentModerateControllerTest.php
index 4d32a0143..be8a0ccf1 100644
--- a/tests/Functional/Controller/Post/Comment/PostCommentModerateControllerTest.php
+++ b/tests/Functional/Controller/Post/Comment/PostCommentModerateControllerTest.php
@@ -10,42 +10,39 @@ class PostCommentModerateControllerTest extends WebTestCase
{
public function testModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createPostComment('test comment 1');
- $crawler = $client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
- $client->click($crawler->filter('#post-comment-'.$comment->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
+ $this->client->click($crawler->filter('#post-comment-'.$comment->getId())->selectLink('Moderate')->link());
$this->assertSelectorTextContains('.moderate-panel', 'ban');
}
public function testXmlModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$comment = $this->createPostComment('test comment 1');
- $crawler = $client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('#post-comment-'.$comment->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('#post-comment-'.$comment->getId())->selectLink('Moderate')->link());
- $this->assertStringContainsString('moderate-panel', $client->getResponse()->getContent());
+ $this->assertStringContainsString('moderate-panel', $this->client->getResponse()->getContent());
}
public function testUnauthorizedCanNotShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$comment = $this->createPostComment('test comment 1');
- $client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
+ $this->client->request('get', "/m/{$comment->magazine->name}/p/{$comment->post->getId()}");
$this->assertSelectorTextNotContains('#post-comment-'.$comment->getId(), 'moderate');
- $client->request(
+ $this->client->request(
'get',
"/m/{$comment->magazine->name}/p/{$comment->post->getId()}/-/reply/{$comment->getId()}/moderate"
);
diff --git a/tests/Functional/Controller/Post/PostBoostControllerTest.php b/tests/Functional/Controller/Post/PostBoostControllerTest.php
index 6318803d8..6e303764c 100644
--- a/tests/Functional/Controller/Post/PostBoostControllerTest.php
+++ b/tests/Functional/Controller/Post/PostBoostControllerTest.php
@@ -10,22 +10,21 @@ class PostBoostControllerTest extends WebTestCase
{
public function testLoggedUserBoostPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1', null, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $client->submit(
- $crawler->filter('#main .post')->selectButton('boost')->form([])
+ $this->client->submit(
+ $crawler->filter('#main .post')->selectButton('Boost')->form([])
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
- $this->assertSelectorTextContains('#main .post', 'boost (1)');
+ $this->assertSelectorTextContains('#main .post', 'Boost (1)');
- $client->click($crawler->filter('#activity')->selectLink('boosts (1)')->link());
+ $this->client->click($crawler->filter('#activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JohnDoe');
}
diff --git a/tests/Functional/Controller/Post/PostChangeAdultControllerTest.php b/tests/Functional/Controller/Post/PostChangeAdultControllerTest.php
index 3b9da4dca..274c51ee8 100644
--- a/tests/Functional/Controller/Post/PostChangeAdultControllerTest.php
+++ b/tests/Functional/Controller/Post/PostChangeAdultControllerTest.php
@@ -10,26 +10,25 @@ class PostChangeAdultControllerTest extends WebTestCase
{
public function testModCanMarkAsAdultContent(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
- $client->submit(
- $crawler->filter('.moderate-panel')->selectButton('18+ / nsfw')->form([
- 'adult' => true,
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Mark NSFW')->form([
+ 'adult' => 'on',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .post .badge', '18+');
- $client->submit(
- $crawler->filter('.moderate-panel')->selectButton('18+ / nsfw')->form([
+ $this->client->submit(
+ $crawler->filter('.moderate-panel')->selectButton('Mark NSFW')->form([
'adult' => false,
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextNotContains('#main .post', '18+');
}
}
diff --git a/tests/Functional/Controller/Post/PostChangeLangControllerTest.php b/tests/Functional/Controller/Post/PostChangeLangControllerTest.php
index 2bc9745b9..51d289f24 100644
--- a/tests/Functional/Controller/Post/PostChangeLangControllerTest.php
+++ b/tests/Functional/Controller/Post/PostChangeLangControllerTest.php
@@ -10,21 +10,20 @@ class PostChangeLangControllerTest extends WebTestCase
{
public function testModCanChangeLanguage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
- $form = $crawler->filter('.moderate-panel')->selectButton('change language')->form();
+ $form = $crawler->filter('.moderate-panel')->selectButton('Change language')->form();
$this->assertSame($form['lang']['lang']->getValue(), 'en');
$form['lang']['lang']->select('fr');
- $client->submit($form);
- $client->followRedirect();
+ $this->client->submit($form);
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .badge-lang', 'French');
}
diff --git a/tests/Functional/Controller/Post/PostChangeMagazineControllerTest.php b/tests/Functional/Controller/Post/PostChangeMagazineControllerTest.php
index 46993ee42..b09db9320 100644
--- a/tests/Functional/Controller/Post/PostChangeMagazineControllerTest.php
+++ b/tests/Functional/Controller/Post/PostChangeMagazineControllerTest.php
@@ -10,11 +10,9 @@ class PostChangeMagazineControllerTest extends WebTestCase
{
public function testAdminCanChangeMagazine(): void
{
- $client = $this->createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$this->setAdmin($user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
$this->getMagazineByName('kbin');
@@ -22,27 +20,25 @@ public function testAdminCanChangeMagazine(): void
'test post 1',
);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
- $client->submit(
- $crawler->filter('form[name=change_magazine]')->selectButton('change magazine')->form(
+ $this->client->submit(
+ $crawler->filter('form[name=change_magazine]')->selectButton('Change magazine')->form(
[
'change_magazine[new_magazine]' => 'kbin',
]
)
);
- $client->followRedirect();
- $client->followRedirect();
+ $this->client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('.head-title', 'kbin');
}
public function testUnauthorizedUserCantChangeMagazine(): void
{
- $client = $this->createClient();
-
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('kbin');
@@ -50,8 +46,8 @@ public function testUnauthorizedUserCantChangeMagazine(): void
'test post 1',
);
- $client->request('GET', "/m/acme/p/{$entry->getId()}/-/moderate");
+ $this->client->request('GET', "/m/acme/p/{$entry->getId()}/-/moderate");
- $this->assertSelectorTextNotContains('.moderate-panel', 'change magazine');
+ $this->assertSelectorTextNotContains('.moderate-panel', 'Change magazine');
}
}
diff --git a/tests/Functional/Controller/Post/PostCreateControllerTest.php b/tests/Functional/Controller/Post/PostCreateControllerTest.php
index 801046a12..d0984999c 100644
--- a/tests/Functional/Controller/Post/PostCreateControllerTest.php
+++ b/tests/Functional/Controller/Post/PostCreateControllerTest.php
@@ -16,14 +16,13 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testUserCanCreatePost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/microblog');
+ $crawler = $this->client->request('GET', '/m/acme/microblog');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Add post')->form(
[
'post[body]' => 'test post 1',
@@ -32,29 +31,28 @@ public function testUserCanCreatePost(): void
);
$this->assertResponseRedirects('/m/acme/microblog/newest');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#content .post', 'test post 1');
}
public function testUserCanCreatePostWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/microblog');
+ $crawler = $this->client->request('GET', '/m/acme/microblog');
$form = $crawler->filter('form[name=post]')->selectButton('Add post')->form();
$form->get('post[body]')->setValue('test post 1');
$form->get('post[image]')->upload($this->kibbyPath);
// Needed since we require this global to be set when validating entries but the client doesn't actually set it
$_FILES = $form->getPhpFiles();
- $client->submit($form);
+ $this->client->submit($form);
$this->assertResponseRedirects('/m/acme/microblog/newest');
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#content .post', 'test post 1');
$this->assertSelectorExists('#content .post footer figure img');
@@ -65,14 +63,13 @@ public function testUserCanCreatePostWithImage(): void
public function testUserCannotCreateInvalidPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/microblog');
+ $crawler = $this->client->request('GET', '/m/acme/microblog');
- $crawler = $client->submit(
+ $crawler = $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Add post')->form(
[
'post[body]' => '',
@@ -85,14 +82,13 @@ public function testUserCannotCreateInvalidPost(): void
public function testCreatedPostIsMarkedAsForAdults(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', hideAdult: false));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', hideAdult: false));
$this->getMagazineByName('acme');
- $crawler = $client->request('GET', '/m/acme/microblog');
+ $crawler = $this->client->request('GET', '/m/acme/microblog');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Add post')->form(
[
'post[body]' => 'test nsfw 1',
@@ -102,21 +98,20 @@ public function testCreatedPostIsMarkedAsForAdults(): void
);
$this->assertResponseRedirects('/m/acme/microblog/newest');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('blockquote header .danger', '18+');
}
public function testPostCreatedInAdultMagazineIsAutomaticallyMarkedAsForAdults(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe', hideAdult: false));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe', hideAdult: false));
$this->getMagazineByName('adult', isAdult: true);
- $crawler = $client->request('GET', '/m/adult/microblog');
+ $crawler = $this->client->request('GET', '/m/adult/microblog');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Add post')->form(
[
'post[body]' => 'test nsfw 1',
@@ -125,7 +120,7 @@ public function testPostCreatedInAdultMagazineIsAutomaticallyMarkedAsForAdults()
);
$this->assertResponseRedirects('/m/adult/microblog/newest');
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('blockquote header .danger', '18+');
}
diff --git a/tests/Functional/Controller/Post/PostDeleteControllerTest.php b/tests/Functional/Controller/Post/PostDeleteControllerTest.php
index 82f17ba0a..f94a6dfa1 100644
--- a/tests/Functional/Controller/Post/PostDeleteControllerTest.php
+++ b/tests/Functional/Controller/Post/PostDeleteControllerTest.php
@@ -5,22 +5,22 @@
namespace App\Tests\Functional\Controller\Post;
use App\Tests\WebTestCase;
+use Symfony\Contracts\Translation\TranslatorInterface;
class PostDeleteControllerTest extends WebTestCase
{
public function testUserCanDeletePost()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$post = $this->createPost('deletion test', magazine: $magazine, user: $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
$this->assertSelectorExists('form[action$="delete"]');
- $client->submit(
- $crawler->filter('form[action$="delete"]')->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter('form[action$="delete"]')->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
@@ -28,22 +28,22 @@ public function testUserCanDeletePost()
public function testUserCanSoftDeletePost()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$magazine = $this->getMagazineByName('acme');
$post = $this->createPost('deletion test', magazine: $magazine, user: $user);
$comment = $this->createPostComment('really?', $post, $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
$this->assertSelectorExists("#post-{$post->getId()} form[action$=\"delete\"]");
- $client->submit(
- $crawler->filter("#post-{$post->getId()} form[action$=\"delete\"]")->selectButton('delete')->form()
+ $this->client->submit(
+ $crawler->filter("#post-{$post->getId()} form[action$=\"delete\"]")->selectButton('Delete')->form()
);
$this->assertResponseRedirects();
- $client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
- $this->assertSelectorTextContains("#post-{$post->getId()} .content", 'deleted_by_author');
+ $this->client->request('GET', "/m/acme/p/{$post->getId()}/deletion-test");
+ $translator = $this->getService(TranslatorInterface::class);
+ $this->assertSelectorTextContains("#post-{$post->getId()} .content", $translator->trans('deleted_by_author'));
}
}
diff --git a/tests/Functional/Controller/Post/PostEditControllerTest.php b/tests/Functional/Controller/Post/PostEditControllerTest.php
index 884fad5e2..1a78d02eb 100644
--- a/tests/Functional/Controller/Post/PostEditControllerTest.php
+++ b/tests/Functional/Controller/Post/PostEditControllerTest.php
@@ -10,19 +10,18 @@ class PostEditControllerTest extends WebTestCase
{
public function testAuthorCanEditOwnPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .post')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .post');
$this->assertSelectorTextContains('#post_body', 'test post 1');
// $this->assertEquals('disabled', $crawler->filter('#post_magazine_autocomplete')->attr('disabled')); @todo
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Edit post')->form(
[
'post[body]' => 'test post 2 body',
@@ -30,20 +29,19 @@ public function testAuthorCanEditOwnPost(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .post .content', 'test post 2 body');
}
public function testAuthorCanEditOwnPostWithImage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1', imageDto: $this->getKibbyImageDto());
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .post')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .post');
$this->assertSelectorTextContains('#post_body', 'test post 1');
@@ -53,7 +51,7 @@ public function testAuthorCanEditOwnPostWithImage(): void
$this->assertNotNull($node);
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $node->attributes->getNamedItem('src')->textContent);
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Edit post')->form(
[
'post[body]' => 'test post 2 body',
@@ -61,7 +59,7 @@ public function testAuthorCanEditOwnPostWithImage(): void
)
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#main .post .content', 'test post 2 body');
$this->assertSelectorExists('#main .post img');
@@ -72,17 +70,16 @@ public function testAuthorCanEditOwnPostWithImage(): void
public function testAuthorCanEditPostToMarkItIsForAdults(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1/edit");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1/edit");
- $crawler = $client->click($crawler->filter('#main .post')->selectLink('edit')->link());
+ $crawler = $this->client->click($crawler->filter('#main .post')->selectLink('Edit')->link());
$this->assertSelectorExists('#main .post');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=post]')->selectButton('Edit post')->form(
[
'post[isAdult]' => '1',
@@ -90,7 +87,7 @@ public function testAuthorCanEditPostToMarkItIsForAdults(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('blockquote header .danger', '18+');
}
diff --git a/tests/Functional/Controller/Post/PostFrontControllerTest.php b/tests/Functional/Controller/Post/PostFrontControllerTest.php
index 3f148469e..f352cb928 100644
--- a/tests/Functional/Controller/Post/PostFrontControllerTest.php
+++ b/tests/Functional/Controller/Post/PostFrontControllerTest.php
@@ -14,12 +14,12 @@ class PostFrontControllerTest extends WebTestCase
{
public function testFrontPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/microblog');
+ $this->client->request('GET', '/microblog');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/microblog/newest');
+ $crawler = $this->client->request('GET', '/microblog/newest');
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
@@ -29,20 +29,20 @@ public function testFrontPage(): void
$this->assertcount(2, $crawler->filter('.post'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testMagazinePage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $client->request('GET', '/m/acme/microblog');
+ $this->client->request('GET', '/m/acme/microblog');
$this->assertSelectorTextContains('h2', 'Hot');
- $crawler = $client->request('GET', '/m/acme/microblog/newest');
+ $crawler = $this->client->request('GET', '/m/acme/microblog/newest');
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextNotContains('.post header', 'to acme');
@@ -55,26 +55,26 @@ public function testMagazinePage(): void
$this->assertcount(1, $crawler->filter('.post'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
- $this->assertSelectorTextContains('h1', 'Magazine title');
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
+ $this->assertSelectorTextContains('h1', 'acme');
$this->assertSelectorTextContains('h2', ucfirst($sortOption));
}
}
public function testSubPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
$magazineManager = $this->getService(MagazineManager::class);
$magazineManager->subscribe($this->getMagazineByName('acme'), $this->getUserByUsername('Actor'));
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/sub/microblog');
+ $this->client->request('GET', '/sub/microblog');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/sub/microblog/newest');
+ $crawler = $this->client->request('GET', '/sub/microblog/newest');
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
@@ -86,27 +86,29 @@ public function testSubPage(): void
$this->assertcount(1, $crawler->filter('.post'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testModPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
+ $admin = $this->getUserByUsername('admin', isAdmin: true);
- $magazineManager = $client->getContainer()->get(MagazineManager::class);
+ $magazineManager = $this->client->getContainer()->get(MagazineManager::class);
$moderator = new ModeratorDto($this->getMagazineByName('acme'));
$moderator->user = $this->getUserByUsername('Actor');
+ $moderator->addedBy = $admin;
$magazineManager->addModerator($moderator);
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/mod/microblog');
+ $this->client->request('GET', '/mod/microblog');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/mod/microblog/newest');
+ $crawler = $this->client->request('GET', '/mod/microblog/newest');
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
@@ -118,25 +120,25 @@ public function testModPage(): void
$this->assertcount(1, $crawler->filter('.post'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
public function testFavPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
$favouriteManager = $this->getService(FavouriteManager::class);
$favouriteManager->toggle($this->getUserByUsername('Actor'), $this->createPost('test post 3'));
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
- $client->request('GET', '/fav/microblog');
+ $this->client->request('GET', '/fav/microblog');
$this->assertSelectorTextContains('h1', 'Hot');
- $crawler = $client->request('GET', '/fav/microblog/newest');
+ $crawler = $this->client->request('GET', '/fav/microblog/newest');
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
@@ -148,16 +150,14 @@ public function testFavPage(): void
$this->assertcount(1, $crawler->filter('.post'));
foreach ($this->getSortOptions() as $sortOption) {
- $crawler = $client->click($crawler->filter('.options__main')->selectLink($sortOption)->link());
- $this->assertSelectorTextContains('.options__main', $sortOption);
+ $crawler = $this->client->click($crawler->filter('.options__filter')->selectLink($sortOption)->link());
+ $this->assertSelectorTextContains('.options__filter', $sortOption);
$this->assertSelectorTextContains('h1', ucfirst($sortOption));
}
}
private function prepareEntries(): KernelBrowser
{
- $client = $this->createClient();
-
$this->createPost(
'test post 1',
$this->getMagazineByName('kbin', $this->getUserByUsername('JaneDoe')),
@@ -166,11 +166,11 @@ private function prepareEntries(): KernelBrowser
$this->createPost('test post 2');
- return $client;
+ return $this->client;
}
private function getSortOptions(): array
{
- return ['top', 'hot', 'newest', 'active', 'commented'];
+ return ['Top', 'Hot', 'Newest', 'Active', 'Commented'];
}
}
diff --git a/tests/Functional/Controller/Post/PostModerateControllerTest.php b/tests/Functional/Controller/Post/PostModerateControllerTest.php
index 6d44a41b9..23c459379 100644
--- a/tests/Functional/Controller/Post/PostModerateControllerTest.php
+++ b/tests/Functional/Controller/Post/PostModerateControllerTest.php
@@ -10,42 +10,39 @@ class PostModerateControllerTest extends WebTestCase
{
public function testModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('get', '/microblog');
- $client->click($crawler->filter('#post-'.$post->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', '/microblog');
+ $this->client->click($crawler->filter('#post-'.$post->getId())->selectLink('Moderate')->link());
$this->assertSelectorTextContains('.moderate-panel', 'ban');
}
public function testXmlModCanShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $crawler = $client->request('get', '/microblog');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('#post-'.$post->getId())->selectLink('moderate')->link());
+ $crawler = $this->client->request('get', '/microblog');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('#post-'.$post->getId())->selectLink('Moderate')->link());
- $this->assertStringContainsString('moderate-panel', $client->getResponse()->getContent());
+ $this->assertStringContainsString('moderate-panel', $this->client->getResponse()->getContent());
}
public function testUnauthorizedCanNotShowPanel(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$post = $this->createPost('test post 1');
- $client->request('get', "/m/{$post->magazine->name}/p/{$post->getId()}");
- $this->assertSelectorTextNotContains('#post-'.$post->getId(), 'moderate');
+ $this->client->request('get', "/m/{$post->magazine->name}/p/{$post->getId()}");
+ $this->assertSelectorTextNotContains('#post-'.$post->getId(), 'Moderate');
- $client->request(
+ $this->client->request(
'get',
"/m/{$post->magazine->name}/p/{$post->getId()}/-/moderate"
);
diff --git a/tests/Functional/Controller/Post/PostPinControllerTest.php b/tests/Functional/Controller/Post/PostPinControllerTest.php
index cb547573a..b6ac43bd1 100644
--- a/tests/Functional/Controller/Post/PostPinControllerTest.php
+++ b/tests/Functional/Controller/Post/PostPinControllerTest.php
@@ -10,22 +10,21 @@ class PostPinControllerTest extends WebTestCase
{
public function testModCanPinEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost(
'test post 1',
$this->getMagazineByName('acme'),
);
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/-/moderate");
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('pin')->form([]));
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Pin')->form([]));
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#main .post .fa-thumbtack');
- $client->submit($crawler->filter('#main .moderate-panel')->selectButton('unpin')->form([]));
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#main .moderate-panel')->selectButton('Unpin')->form([]));
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#main .post .fa-thumbtack');
}
}
diff --git a/tests/Functional/Controller/Post/PostSingleControllerTest.php b/tests/Functional/Controller/Post/PostSingleControllerTest.php
index f80b2b292..46c5ad899 100644
--- a/tests/Functional/Controller/Post/PostSingleControllerTest.php
+++ b/tests/Functional/Controller/Post/PostSingleControllerTest.php
@@ -13,13 +13,12 @@ class PostSingleControllerTest extends WebTestCase
{
public function testUserCanGoToPostFromFrontpage(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$this->createPost('test post 1');
- $crawler = $client->request('GET', '/microblog');
- $client->click($crawler->filter('.link-muted')->link());
+ $crawler = $this->client->request('GET', '/microblog');
+ $this->client->click($crawler->filter('.link-muted')->link());
$this->assertSelectorTextContains('blockquote', 'test post 1');
$this->assertSelectorTextContains('#main', 'No comments');
@@ -29,31 +28,29 @@ public function testUserCanGoToPostFromFrontpage(): void
public function testUserCanSeePost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
$this->assertSelectorTextContains('blockquote', 'test post 1');
}
public function testPostActivityCounter(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $manager = $client->getContainer()->get(VoteManager::class);
+ $manager = $this->client->getContainer()->get(VoteManager::class);
$manager->vote(VotableInterface::VOTE_DOWN, $post, $this->getUserByUsername('JaneDoe'));
- $manager = $client->getContainer()->get(FavouriteManager::class);
+ $manager = $this->client->getContainer()->get(FavouriteManager::class);
$manager->toggle($this->getUserByUsername('JohnDoe'), $post);
$manager->toggle($this->getUserByUsername('JaneDoe'), $post);
- $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
$this->assertSelectorTextContains('.options-activity', 'Activity (2)');
}
diff --git a/tests/Functional/Controller/Post/PostVotersControllerTest.php b/tests/Functional/Controller/Post/PostVotersControllerTest.php
index 274daa324..150ba5904 100644
--- a/tests/Functional/Controller/Post/PostVotersControllerTest.php
+++ b/tests/Functional/Controller/Post/PostVotersControllerTest.php
@@ -12,17 +12,16 @@ class PostVotersControllerTest extends WebTestCase
{
public function testUserCanSeeVoters(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1');
- $manager = $client->getContainer()->get(VoteManager::class);
+ $manager = $this->client->getContainer()->get(VoteManager::class);
$manager->vote(VotableInterface::VOTE_UP, $post, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $client->click($crawler->filter('.options-activity')->selectLink('boosts (1)')->link());
+ $this->client->click($crawler->filter('.options-activity')->selectLink('Boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
}
diff --git a/tests/Functional/Controller/PrivacyPolicyControllerTest.php b/tests/Functional/Controller/PrivacyPolicyControllerTest.php
index 89409d7b3..a5fc99bfc 100644
--- a/tests/Functional/Controller/PrivacyPolicyControllerTest.php
+++ b/tests/Functional/Controller/PrivacyPolicyControllerTest.php
@@ -10,10 +10,8 @@ class PrivacyPolicyControllerTest extends WebTestCase
{
public function testPrivacyPolicyPage(): void
{
- $client = $this->createClient();
-
- $crawler = $client->request('GET', '/');
- $client->click($crawler->filter('#footer a[href="/privacy-policy"]')->link());
+ $crawler = $this->client->request('GET', '/');
+ $this->client->click($crawler->filter('.about.section a[href="/privacy-policy"]')->link());
$this->assertSelectorTextContains('h1', 'Privacy policy');
}
diff --git a/tests/Functional/Controller/ReportControllerControllerTest.php b/tests/Functional/Controller/ReportControllerControllerTest.php
index 0bf463cbd..db9b600ab 100644
--- a/tests/Functional/Controller/ReportControllerControllerTest.php
+++ b/tests/Functional/Controller/ReportControllerControllerTest.php
@@ -11,8 +11,7 @@ class ReportControllerControllerTest extends WebTestCase
{
public function testLoggedUserCanReportEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
@@ -22,12 +21,12 @@ public function testLoggedUserCanReportEntry(): void
$this->getUserByUsername('JaneDoe')
);
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry menu')->selectLink('report')->link());
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->click($crawler->filter('#main .entry menu')->selectLink('Report')->link());
$this->assertSelectorExists('#main .entry');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=report]')->selectButton('Report')->form(
[
'report[reason]' => 'test reason 1',
@@ -42,8 +41,7 @@ public function testLoggedUserCanReportEntry(): void
public function testLoggedUserCanReportEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$entry = $this->getEntryByTitle(
'test entry 1',
@@ -54,12 +52,12 @@ public function testLoggedUserCanReportEntryComment(): void
);
$this->createEntryComment('test comment 1', $entry, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
- $crawler = $client->click($crawler->filter('#main .entry-comment')->selectLink('report')->link());
+ $crawler = $this->client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
+ $crawler = $this->client->click($crawler->filter('#main .entry-comment')->selectLink('Report')->link());
$this->assertSelectorExists('#main .entry-comment');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=report]')->selectButton('Report')->form(
[
'report[reason]' => 'test reason 1',
@@ -74,17 +72,16 @@ public function testLoggedUserCanReportEntryComment(): void
public function testLoggedUserCanReportPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1', null, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post menu')->selectLink('report')->link());
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->click($crawler->filter('#main .post menu')->selectLink('Report')->link());
$this->assertSelectorExists('#main .post');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=report]')->selectButton('Report')->form(
[
'report[reason]' => 'test reason 1',
@@ -99,18 +96,17 @@ public function testLoggedUserCanReportPost(): void
public function testLoggedUserCanReportPostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
$post = $this->createPost('test post 1', null, $this->getUserByUsername('JaneDoe'));
$this->createPostComment('test comment 1', $post, $this->getUserByUsername('JaneDoe'));
- $crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
- $crawler = $client->click($crawler->filter('#main .post-comment menu')->selectLink('report')->link());
+ $crawler = $this->client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
+ $crawler = $this->client->click($crawler->filter('#main .post-comment menu')->selectLink('Report')->link());
$this->assertSelectorExists('#main .post-comment');
- $client->submit(
+ $this->client->submit(
$crawler->filter('form[name=report]')->selectButton('Report')->form(
[
'report[reason]' => 'test reason 1',
diff --git a/tests/Functional/Controller/Security/LoginControllerTest.php b/tests/Functional/Controller/Security/LoginControllerTest.php
index 0914a8b76..2e16e5362 100644
--- a/tests/Functional/Controller/Security/LoginControllerTest.php
+++ b/tests/Functional/Controller/Security/LoginControllerTest.php
@@ -10,12 +10,12 @@ class LoginControllerTest extends WebTestCase
{
public function testUserCanLogin(): void
{
- $client = RegisterControllerTest::register(true);
+ $this->client = $this->register(true);
- $crawler = $client->request('get', '/');
- $crawler = $client->click($crawler->filter('header')->selectLink('Log in')->link());
+ $crawler = $this->client->request('get', '/');
+ $crawler = $this->client->click($crawler->filter('header')->selectLink('Log in')->link());
- $client->submit(
+ $this->client->submit(
$crawler->selectButton('Log in')->form(
[
'email' => 'JohnDoe',
@@ -24,19 +24,19 @@ public function testUserCanLogin(): void
)
);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains('#header', 'JohnDoe');
}
public function testUserCannotLoginWithoutActivation(): void
{
- $client = RegisterControllerTest::register();
+ $this->client = $this->register();
- $crawler = $client->request('get', '/');
- $crawler = $client->click($crawler->filter('header')->selectLink('Log in')->link());
+ $crawler = $this->client->request('get', '/');
+ $crawler = $this->client->click($crawler->filter('header')->selectLink('Log in')->link());
- $client->submit(
+ $this->client->submit(
$crawler->selectButton('Log in')->form(
[
'email' => 'JohnDoe',
@@ -45,20 +45,19 @@ public function testUserCannotLoginWithoutActivation(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main', 'Please check your email for account activation instructions or request a new account activation email');
}
public function testUserCantLoginWithWrongPassword(): void
{
- $client = $this->createClient();
$this->getUserByUsername('JohnDoe');
- $crawler = $client->request('GET', '/');
- $crawler = $client->click($crawler->filter('header')->selectLink('Log in')->link());
+ $crawler = $this->client->request('GET', '/');
+ $crawler = $this->client->click($crawler->filter('header')->selectLink('Log in')->link());
- $client->submit(
+ $this->client->submit(
$crawler->selectButton('Log in')->form(
[
'email' => 'JohnDoe',
@@ -67,7 +66,7 @@ public function testUserCantLoginWithWrongPassword(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('.alert__danger', 'Invalid credentials.'); // @todo
}
diff --git a/tests/Functional/Controller/Security/OAuth2ConsentControllerTest.php b/tests/Functional/Controller/Security/OAuth2ConsentControllerTest.php
index ee2a5ed3c..cddcf4c03 100644
--- a/tests/Functional/Controller/Security/OAuth2ConsentControllerTest.php
+++ b/tests/Functional/Controller/Security/OAuth2ConsentControllerTest.php
@@ -10,18 +10,17 @@ class OAuth2ConsentControllerTest extends WebTestCase
{
public function testUserCanConsent(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- self::runAuthorizationCodeFlowToConsentPage($client, 'read write', 'oauth2state');
+ self::runAuthorizationCodeFlowToConsentPage($this->client, 'read write', 'oauth2state');
self::assertSelectorTextContains("li[id='oauth2.grant.read.general']", 'Read all content you have access to.');
self::assertSelectorTextContains("li[id='oauth2.grant.write.general']", 'Create or edit any of your threads, posts, or comments.');
- self::runAuthorizationCodeFlowToRedirectUri($client, 'read write', 'yes', 'oauth2state');
+ self::runAuthorizationCodeFlowToRedirectUri($this->client, 'read write', 'yes', 'oauth2state');
- $response = $client->getResponse();
+ $response = $this->client->getResponse();
$parsedUrl = parse_url($response->headers->get('Location'));
self::assertEquals('https', $parsedUrl['scheme']);
@@ -32,18 +31,17 @@ public function testUserCanConsent(): void
public function testUserCanDissent(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- self::runAuthorizationCodeFlowToConsentPage($client, 'read write', 'oauth2state');
+ self::runAuthorizationCodeFlowToConsentPage($this->client, 'read write', 'oauth2state');
self::assertSelectorTextContains("li[id='oauth2.grant.read.general']", 'Read all content you have access to.');
self::assertSelectorTextContains("li[id='oauth2.grant.write.general']", 'Create or edit any of your threads, posts, or comments.');
- self::runAuthorizationCodeFlowToRedirectUri($client, 'read write', 'no', 'oauth2state');
+ self::runAuthorizationCodeFlowToRedirectUri($this->client, 'read write', 'no', 'oauth2state');
- $response = $client->getResponse();
+ $response = $this->client->getResponse();
$parsedUrl = parse_url($response->headers->get('Location'));
self::assertEquals('https', $parsedUrl['scheme']);
diff --git a/tests/Functional/Controller/Security/OAuth2TokenControllerTest.php b/tests/Functional/Controller/Security/OAuth2TokenControllerTest.php
index 0be89cf82..ae8fca973 100644
--- a/tests/Functional/Controller/Security/OAuth2TokenControllerTest.php
+++ b/tests/Functional/Controller/Security/OAuth2TokenControllerTest.php
@@ -10,17 +10,16 @@ class OAuth2TokenControllerTest extends WebTestCase
{
public function testCanGetTokenWithValidClientCredentials(): void
{
- $client = self::createClient();
self::createOAuth2ClientCredsClient();
- $client->request('POST', '/token', [
+ $this->client->request('POST', '/token', [
'grant_type' => 'client_credentials',
'client_id' => 'testclient',
'client_secret' => 'testsecret',
'scope' => 'read write',
]);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('token_type', $jsonData);
@@ -34,11 +33,10 @@ public function testCanGetTokenWithValidClientCredentials(): void
public function testCanGetTokenWithValidAuthorizationCode(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -54,17 +52,16 @@ public function testCanGetTokenWithValidAuthorizationCode(): void
public function testCanGetTokenWithValidRefreshToken(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
self::assertArrayHasKey('refresh_token', $jsonData);
- $jsonData = self::getRefreshTokenResponse($client, $jsonData['refresh_token']);
+ $jsonData = self::getRefreshTokenResponse($this->client, $jsonData['refresh_token']);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
self::assertArrayHasKey('token_type', $jsonData);
@@ -79,11 +76,10 @@ public function testCanGetTokenWithValidRefreshToken(): void
public function testCanGetTokenWithValidAuthorizationCodePKCE(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2PublicAuthCodeClient();
- $jsonData = self::getPublicAuthorizationCodeTokenResponse($client);
+ $jsonData = self::getPublicAuthorizationCodeTokenResponse($this->client);
self::assertResponseIsSuccessful();
self::assertIsArray($jsonData);
@@ -99,14 +95,13 @@ public function testCanGetTokenWithValidAuthorizationCodePKCE(): void
public function testCannotGetTokenWithInvalidVerifierAuthorizationCodePKCE(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2PublicAuthCodeClient();
- $pkceCodes = self::runPublicAuthorizationCodeFlow($client, 'yes');
- self::runPublicAuthorizationCodeTokenFetch($client, $pkceCodes['verifier'].'fail');
+ $pkceCodes = self::runPublicAuthorizationCodeFlow($this->client, 'yes');
+ self::runPublicAuthorizationCodeTokenFetch($this->client, $pkceCodes['verifier'].'fail');
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertResponseStatusCodeSame(400);
self::assertIsArray($jsonData);
@@ -119,17 +114,16 @@ public function testCannotGetTokenWithInvalidVerifierAuthorizationCodePKCE(): vo
public function testCannotGetTokenWithoutChallengeAuthorizationCodePKCE(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2PublicAuthCodeClient();
$query = self::buildPrivateAuthCodeQuery('testpublicclient', 'read write', 'oauth2state', 'https://localhost:3001');
$uri = '/authorize?'.$query;
- $client->request('GET', $uri);
+ $this->client->request('GET', $uri);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertResponseStatusCodeSame(400);
self::assertIsArray($jsonData);
@@ -143,11 +137,10 @@ public function testCannotGetTokenWithoutChallengeAuthorizationCodePKCE(): void
public function testReceiveErrorWithInvalidAuthorizationCode(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $client->request('POST', '/token', [
+ $this->client->request('POST', '/token', [
'grant_type' => 'authorization_code',
'client_id' => 'testclient',
'client_secret' => 'testsecret',
@@ -157,7 +150,7 @@ public function testReceiveErrorWithInvalidAuthorizationCode(): void
self::assertResponseStatusCodeSame(400);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertIsArray($jsonData);
self::assertArrayHasKey('error', $jsonData);
@@ -169,17 +162,16 @@ public function testReceiveErrorWithInvalidAuthorizationCode(): void
public function testReceiveErrorWithInvalidClientId(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$query = self::buildPrivateAuthCodeQuery('testclientfake', 'read write', 'oauth2state', 'https://localhost:3001');
$uri = '/authorize?'.$query;
- $client->request('GET', $uri);
+ $this->client->request('GET', $uri);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertResponseStatusCodeSame(401);
@@ -192,11 +184,10 @@ public function testReceiveErrorWithInvalidClientId(): void
public function testReceiveErrorWithInvalidClientSecret(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
- $jsonData = self::getAuthorizationCodeTokenResponse($client, clientSecret: 'testsecretfake');
+ $jsonData = self::getAuthorizationCodeTokenResponse($this->client, clientSecret: 'testsecretfake');
self::assertResponseStatusCodeSame(401);
@@ -209,17 +200,16 @@ public function testReceiveErrorWithInvalidClientSecret(): void
public function testReceiveErrorWithInvalidRedirectUri(): void
{
- $client = self::createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
self::createOAuth2AuthCodeClient();
$query = self::buildPrivateAuthCodeQuery('testclient', 'read write', 'oauth2state', 'https://invalid.com');
$uri = '/authorize?'.$query;
- $client->request('GET', $uri);
+ $this->client->request('GET', $uri);
- $jsonData = self::getJsonResponse($client);
+ $jsonData = self::getJsonResponse($this->client);
self::assertResponseStatusCodeSame(401);
diff --git a/tests/Functional/Controller/Security/RegisterControllerTest.php b/tests/Functional/Controller/Security/RegisterControllerTest.php
index d8caf1d29..945898159 100644
--- a/tests/Functional/Controller/Security/RegisterControllerTest.php
+++ b/tests/Functional/Controller/Security/RegisterControllerTest.php
@@ -4,7 +4,6 @@
namespace App\Tests\Functional\Controller\Security;
-use App\Entity\User;
use App\Tests\WebTestCase;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
@@ -14,9 +13,7 @@ class RegisterControllerTest extends WebTestCase
{
public function testUserCanVerifyAccount(): void
{
- $client = $this->createClient();
-
- $this->registerUserAccount($client);
+ $this->registerUserAccount($this->client);
$this->assertEmailCount(1);
@@ -30,10 +27,10 @@ public function testUserCanVerifyAccount(): void
->attr('href')
;
- $client->request('GET', $verificationLink);
- $crawler = $client->followRedirect();
+ $this->client->request('GET', $verificationLink);
+ $crawler = $this->client->followRedirect();
- $client->submit(
+ $this->client->submit(
$crawler->selectButton('Log in')->form(
[
'email' => 'JohnDoe',
@@ -42,7 +39,7 @@ public function testUserCanVerifyAccount(): void
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextNotContains('#header', 'Log in');
}
@@ -66,15 +63,13 @@ private function registerUserAccount(KernelBrowser $client): void
public function testUserCannotLoginWithoutConfirmation()
{
- $client = $this->createClient();
-
- $this->registerUserAccount($client);
+ $this->registerUserAccount($this->client);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
- $crawler = $client->click($crawler->filter('#header')->selectLink('Log in')->link());
+ $crawler = $this->client->click($crawler->filter('#header')->selectLink('Log in')->link());
- $client->submit(
+ $this->client->submit(
$crawler->selectButton('Log in')->form(
[
'email' => 'JohnDoe',
@@ -83,37 +78,8 @@ public function testUserCannotLoginWithoutConfirmation()
)
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('.alert__danger', 'Your account has not been activated.');
}
-
- public static function register($active = false): KernelBrowser
- {
- $client = self::createClient();
- $crawler = $client->request('GET', '/register');
-
- $client->submit(
- $crawler->filter('form[name=user_register]')->selectButton('Register')->form(
- [
- 'user_register[username]' => 'JohnDoe',
- 'user_register[email]' => 'johndoe@kbin.pub',
- 'user_register[plainPassword][first]' => 'secret',
- 'user_register[plainPassword][second]' => 'secret',
- 'user_register[agreeTerms]' => true,
- ]
- )
- );
-
- if ($active) {
- $user = self::getContainer()->get('doctrine')->getRepository(User::class)
- ->findOneBy(['username' => 'JohnDoe']);
- $user->isVerified = true;
-
- self::getContainer()->get('doctrine')->getManager()->flush();
- self::getContainer()->get('doctrine')->getManager()->refresh($user);
- }
-
- return $client;
- }
}
diff --git a/tests/Functional/Controller/TermsControllerTest.php b/tests/Functional/Controller/TermsControllerTest.php
index 00205b404..bac095bc7 100644
--- a/tests/Functional/Controller/TermsControllerTest.php
+++ b/tests/Functional/Controller/TermsControllerTest.php
@@ -10,10 +10,8 @@ class TermsControllerTest extends WebTestCase
{
public function testTermsPage(): void
{
- $client = $this->createClient();
-
- $crawler = $client->request('GET', '/');
- $client->click($crawler->filter('#footer a[href="/terms"]')->link());
+ $crawler = $this->client->request('GET', '/');
+ $this->client->click($crawler->filter('.about.section a[href="/terms"]')->link());
$this->assertSelectorTextContains('h1', 'Terms');
}
diff --git a/tests/Functional/Controller/User/Admin/UserDeleteControllerTest.php b/tests/Functional/Controller/User/Admin/UserDeleteControllerTest.php
index 55e6847fe..d5932a024 100644
--- a/tests/Functional/Controller/User/Admin/UserDeleteControllerTest.php
+++ b/tests/Functional/Controller/User/Admin/UserDeleteControllerTest.php
@@ -10,43 +10,21 @@ class UserDeleteControllerTest extends WebTestCase
{
public function testAdminCanDeleteUser()
{
- $client = $this->createClient();
$user = $this->getUserByUsername('user');
$entry = $this->getEntryByTitle('An entry', body: 'test', user: $user);
$entryComment = $this->createEntryComment('A comment', $entry, $user);
$post = $this->createPost('A post', user: $user);
$postComment = $this->createPostComment('A comment', $post, $user);
$admin = $this->getUserByUsername('admin', isAdmin: true);
- $client->loginUser($admin);
+ $this->client->loginUser($admin);
- $crawler = $client->request('GET', '/u/user');
+ $crawler = $this->client->request('GET', '/u/user');
$this->assertSelectorExists('#sidebar .panel form[action$="delete_account"]');
- $client->submit(
+ $this->client->submit(
$crawler->filter('#sidebar .panel form[action$="delete_account"]')->selectButton('Delete account')->form()
);
$this->assertResponseRedirects();
}
-
- public function testAdminCanPurgeUser()
- {
- $client = $this->createClient();
- $user = $this->getUserByUsername('user');
- $entry = $this->getEntryByTitle('An entry', body: 'test', user: $user);
- $entryComment = $this->createEntryComment('A comment', $entry, $user);
- $post = $this->createPost('A post', user: $user);
- $postComment = $this->createPostComment('A comment', $post, $user);
- $admin = $this->getUserByUsername('admin', isAdmin: true);
- $client->loginUser($admin);
-
- $crawler = $client->request('GET', '/u/user');
-
- $this->assertSelectorExists('#sidebar .panel form[action$="purge_account"]');
- $client->submit(
- $crawler->filter('#sidebar .panel form[action$="purge_account"]')->selectButton('Purge account')->form()
- );
-
- $this->assertResponseRedirects();
- }
}
diff --git a/tests/Functional/Controller/User/Profile/UserBlockControllerTest.php b/tests/Functional/Controller/User/Profile/UserBlockControllerTest.php
index 97d455126..506333efe 100644
--- a/tests/Functional/Controller/User/Profile/UserBlockControllerTest.php
+++ b/tests/Functional/Controller/User/Profile/UserBlockControllerTest.php
@@ -13,14 +13,13 @@ class UserBlockControllerTest extends WebTestCase
{
public function testUserCanSeeBlockedMagazines()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$magazine = $this->getMagazineByName('acme');
$this->getService(MagazineManager::class)->block($magazine, $user);
- $crawler = $client->request('GET', '/settings/blocked/magazines');
- $client->click($crawler->filter('#main .pills')->selectLink('Magazines')->link());
+ $crawler = $this->client->request('GET', '/settings/blocked/magazines');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('Magazines')->link());
$this->assertSelectorTextContains('#main .pills .active', 'Magazines');
$this->assertSelectorTextContains('#main .magazines', 'acme');
@@ -28,13 +27,12 @@ public function testUserCanSeeBlockedMagazines()
public function testUserCanSeeBlockedUsers()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$this->getService(UserManager::class)->block($user, $this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/settings/blocked/people');
- $client->click($crawler->filter('#main .pills')->selectLink('People')->link());
+ $crawler = $this->client->request('GET', '/settings/blocked/people');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('People')->link());
$this->assertSelectorTextContains('#main .pills .active', 'People');
$this->assertSelectorTextContains('#main .users', 'JohnDoe');
@@ -42,15 +40,14 @@ public function testUserCanSeeBlockedUsers()
public function testUserCanSeeBlockedDomains()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test1', 'https://kbin.pub');
$this->getService(DomainManager::class)->block($entry->domain, $user);
- $crawler = $client->request('GET', '/settings/blocked/domains');
- $client->click($crawler->filter('#main .pills')->selectLink('Domains')->link());
+ $crawler = $this->client->request('GET', '/settings/blocked/domains');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('Domains')->link());
$this->assertSelectorTextContains('#main .pills .active', 'Domains');
$this->assertSelectorTextContains('#main', 'kbin.pub');
diff --git a/tests/Functional/Controller/User/Profile/UserEditControllerTest.php b/tests/Functional/Controller/User/Profile/UserEditControllerTest.php
index 27730d298..10bbc2b17 100644
--- a/tests/Functional/Controller/User/Profile/UserEditControllerTest.php
+++ b/tests/Functional/Controller/User/Profile/UserEditControllerTest.php
@@ -5,7 +5,6 @@
namespace App\Tests\Functional\Controller\User\Profile;
use App\Repository\UserRepository;
-use App\Tests\Functional\Controller\Security\RegisterControllerTest;
use App\Tests\WebTestCase;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\DomCrawler\Crawler;
@@ -22,51 +21,48 @@ public function __construct($name = null, array $data = [], $dataName = '')
public function testUserCanSeeSettingsLink(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/');
- $client->click($crawler->filter('#header menu')->selectLink('Settings')->link());
+ $crawler = $this->client->request('GET', '/');
+ $this->client->click($crawler->filter('#header menu')->selectLink('Settings')->link());
- $this->assertSelectorTextContains('#main .options__main a.active', 'general');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'General');
}
public function testUserCanEditProfile(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/settings/profile');
- $this->assertSelectorTextContains('#main .options__main a.active', 'profile');
+ $crawler = $this->client->request('GET', '/settings/profile');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Profile');
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form[name=user_basic]')->selectButton('Save')->form([
'user_basic[about]' => 'test about',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#main .user-box', 'test about');
- $client->request('GET', '/people');
+ $this->client->request('GET', '/people');
$this->assertSelectorTextContains('#main .user-box', 'JohnDoe');
}
public function testUserCanUploadAvatar(): void
{
- $client = $this->createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$repository = $this->getService(UserRepository::class);
- $crawler = $client->request('GET', '/settings/profile');
- $this->assertSelectorTextContains('#main .options__main a.active', 'profile');
+ $crawler = $this->client->request('GET', '/settings/profile');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Profile');
$this->assertStringContainsString('/dev/random', $user->avatar->filePath);
$form = $crawler->filter('#main form[name=user_basic]')->selectButton('Save')->form();
$form['user_basic[avatar]']->upload($this->kibbyPath);
- $client->submit($form);
+ $this->client->submit($form);
$user = $repository->find($user->getId());
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $user->avatar->filePath);
@@ -74,18 +70,17 @@ public function testUserCanUploadAvatar(): void
public function testUserCanUploadCover(): void
{
- $client = $this->createClient();
$user = $this->getUserByUsername('JohnDoe');
- $client->loginUser($user);
+ $this->client->loginUser($user);
$repository = $this->getService(UserRepository::class);
- $crawler = $client->request('GET', '/settings/profile');
- $this->assertSelectorTextContains('#main .options__main a.active', 'profile');
+ $crawler = $this->client->request('GET', '/settings/profile');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Profile');
$this->assertNull($user->cover);
$form = $crawler->filter('#main form[name=user_basic]')->selectButton('Save')->form();
$form['user_basic[cover]']->upload($this->kibbyPath);
- $client->submit($form);
+ $this->client->submit($form);
$user = $repository->find($user->getId());
$this->assertStringContainsString(self::KIBBY_PNG_URL_RESULT, $user->cover->filePath);
@@ -93,14 +88,14 @@ public function testUserCanUploadCover(): void
public function testUserCanChangePassword(): void
{
- $client = RegisterControllerTest::register(true);
+ $this->client = $this->register(true);
- $client->loginUser($this->getService(UserRepository::class)->findOneBy(['username' => 'JohnDoe']));
+ $this->client->loginUser($this->getService(UserRepository::class)->findOneBy(['username' => 'JohnDoe']));
- $crawler = $client->request('GET', '/settings/password');
- $this->assertSelectorTextContains('#main .options__main a.active', 'password');
+ $crawler = $this->client->request('GET', '/settings/password');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Password');
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form[name=user_password]')->selectButton('Save')->form([
'user_password[currentPassword]' => 'secret',
'user_password[plainPassword][first]' => 'test123',
@@ -108,32 +103,32 @@ public function testUserCanChangePassword(): void
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
- $crawler = $client->request('GET', '/login');
+ $crawler = $this->client->request('GET', '/login');
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form')->selectButton('Log in')->form([
'email' => 'JohnDoe',
'password' => 'test123',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#header', 'JohnDoe');
}
public function testUserCanChangeEmail(): void
{
- $client = RegisterControllerTest::register(true);
+ $this->client = $this->register(true);
- $client->loginUser($this->getService(UserRepository::class)->findOneBy(['username' => 'JohnDoe']));
+ $this->client->loginUser($this->getService(UserRepository::class)->findOneBy(['username' => 'JohnDoe']));
- $crawler = $client->request('GET', '/settings/email');
- $this->assertSelectorTextContains('#main .options__main a.active', 'email');
+ $crawler = $this->client->request('GET', '/settings/email');
+ $this->assertSelectorTextContains('#main .options__main a.active', 'Email');
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form[name=user_email]')->selectButton('Save')->form([
'user_email[newEmail][first]' => 'acme@kbin.pub',
'user_email[newEmail][second]' => 'acme@kbin.pub',
@@ -153,18 +148,18 @@ public function testUserCanChangeEmail(): void
->attr('href')
;
- $client->request('GET', $verificationLink);
+ $this->client->request('GET', $verificationLink);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
- $client->submit(
+ $this->client->submit(
$crawler->filter('#main form')->selectButton('Log in')->form([
'email' => 'JohnDoe',
'password' => 'secret',
])
);
- $client->followRedirect();
+ $this->client->followRedirect();
$this->assertSelectorTextContains('#header', 'JohnDoe');
}
diff --git a/tests/Functional/Controller/User/Profile/UserNotificationControllerTest.php b/tests/Functional/Controller/User/Profile/UserNotificationControllerTest.php
index f4bb459b9..74978560a 100644
--- a/tests/Functional/Controller/User/Profile/UserNotificationControllerTest.php
+++ b/tests/Functional/Controller/User/Profile/UserNotificationControllerTest.php
@@ -11,8 +11,7 @@ class UserNotificationControllerTest extends WebTestCase
{
public function testUserReceiveNotificationTest(): void
{
- $client = $this->createClient();
- $client->loginUser($owner = $this->getUserByUsername('owner'));
+ $this->client->loginUser($owner = $this->getUserByUsername('owner'));
$actor = $this->getUserByUsername('actor');
@@ -21,26 +20,25 @@ public function testUserReceiveNotificationTest(): void
$this->loadNotificationsFixture();
- $crawler = $client->request('GET', '/settings/notifications');
+ $crawler = $this->client->request('GET', '/settings/notifications');
$this->assertCount(2, $crawler->filter('#main .notification'));
- $client->restart();
- $client->loginUser($actor);
+ $this->client->restart();
+ $this->client->loginUser($actor);
- $crawler = $client->request('GET', '/settings/notifications');
+ $crawler = $this->client->request('GET', '/settings/notifications');
$this->assertCount(3, $crawler->filter('#main .notification'));
- $client->restart();
- $client->loginUser($this->getUserByUsername('JohnDoe'));
+ $this->client->restart();
+ $this->client->loginUser($this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/settings/notifications');
+ $crawler = $this->client->request('GET', '/settings/notifications');
$this->assertCount(2, $crawler->filter('#main .notification'));
}
public function testCanReadAllNotifications(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('owner'));
+ $this->client->loginUser($this->getUserByUsername('owner'));
$this->getService(MagazineManager::class)->subscribe(
$this->getMagazineByName('acme'),
@@ -53,24 +51,23 @@ public function testCanReadAllNotifications(): void
$this->loadNotificationsFixture();
- $client->loginUser($this->getUserByUsername('owner'));
+ $this->client->loginUser($this->getUserByUsername('owner'));
- $crawler = $client->request('GET', '/settings/notifications');
+ $crawler = $this->client->request('GET', '/settings/notifications');
$this->assertCount(2, $crawler->filter('#main .notification'));
$this->assertCount(0, $crawler->filter('#main .notification.opacity-50'));
- $client->submit($crawler->selectButton('Read all')->form());
+ $this->client->submit($crawler->selectButton('Read all')->form());
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertCount(2, $crawler->filter('#main .notification.opacity-50'));
}
public function testUserCanDeleteAllNotifications(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('owner'));
+ $this->client->loginUser($this->getUserByUsername('owner'));
$this->getService(MagazineManager::class)->subscribe(
$this->getMagazineByName('acme'),
@@ -83,15 +80,15 @@ public function testUserCanDeleteAllNotifications(): void
$this->loadNotificationsFixture();
- $client->loginUser($this->getUserByUsername('owner'));
+ $this->client->loginUser($this->getUserByUsername('owner'));
- $crawler = $client->request('GET', '/settings/notifications');
+ $crawler = $this->client->request('GET', '/settings/notifications');
$this->assertCount(2, $crawler->filter('#main .notification'));
- $client->submit($crawler->selectButton('Purge')->form());
+ $this->client->submit($crawler->selectButton('Purge')->form());
- $crawler = $client->followRedirect();
+ $crawler = $this->client->followRedirect();
$this->assertCount(0, $crawler->filter('#main .notification'));
}
diff --git a/tests/Functional/Controller/User/Profile/UserSubControllerTest.php b/tests/Functional/Controller/User/Profile/UserSubControllerTest.php
index d646489cd..598d9c013 100644
--- a/tests/Functional/Controller/User/Profile/UserSubControllerTest.php
+++ b/tests/Functional/Controller/User/Profile/UserSubControllerTest.php
@@ -13,14 +13,13 @@ class UserSubControllerTest extends WebTestCase
{
public function testUserCanSeeSubscribedMagazines()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$magazine = $this->getMagazineByName('acme');
$this->getService(MagazineManager::class)->subscribe($magazine, $user);
- $crawler = $client->request('GET', '/settings/subscriptions/magazines');
- $client->click($crawler->filter('#main .pills')->selectLink('Magazines')->link());
+ $crawler = $this->client->request('GET', '/settings/subscriptions/magazines');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('Magazines')->link());
$this->assertSelectorTextContains('#main .pills .active', 'Magazines');
$this->assertSelectorTextContains('#main .magazines', 'acme');
@@ -28,13 +27,12 @@ public function testUserCanSeeSubscribedMagazines()
public function testUserCanSeeSubscribedUsers()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$this->getService(UserManager::class)->follow($user, $this->getUserByUsername('JohnDoe'));
- $crawler = $client->request('GET', '/settings/subscriptions/people');
- $client->click($crawler->filter('#main .pills')->selectLink('People')->link());
+ $crawler = $this->client->request('GET', '/settings/subscriptions/people');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('People')->link());
$this->assertSelectorTextContains('#main .pills .active', 'People');
$this->assertSelectorTextContains('#main .users', 'JohnDoe');
@@ -42,15 +40,14 @@ public function testUserCanSeeSubscribedUsers()
public function testUserCanSeeSubscribedDomains()
{
- $client = $this->createClient();
- $client->loginUser($user = $this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($user = $this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test1', 'https://kbin.pub');
$this->getService(DomainManager::class)->subscribe($entry->domain, $user);
- $crawler = $client->request('GET', '/settings/subscriptions/domains');
- $client->click($crawler->filter('#main .pills')->selectLink('Domains')->link());
+ $crawler = $this->client->request('GET', '/settings/subscriptions/domains');
+ $this->client->click($crawler->filter('#main .pills')->selectLink('Domains')->link());
$this->assertSelectorTextContains('#main .pills .active', 'Domains');
$this->assertSelectorTextContains('#main', 'kbin.pub');
diff --git a/tests/Functional/Controller/User/UserBlockControllerTest.php b/tests/Functional/Controller/User/UserBlockControllerTest.php
index 45436ed25..823ebe7a8 100644
--- a/tests/Functional/Controller/User/UserBlockControllerTest.php
+++ b/tests/Functional/Controller/User/UserBlockControllerTest.php
@@ -10,62 +10,59 @@ class UserBlockControllerTest extends WebTestCase
{
public function testUserCanBlockAndUnblock(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId().'/test-entry-1');
// Block
- $client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=user_block] .active');
// Unblock
- $client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#sidebar form[name=user_block] .active');
}
public function testXmlUserCanBlock(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId().'/test-entry-1');
// Block
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('active', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnblock(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId().'/test-entry-1');
// Block
- $client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
+ $crawler = $this->client->followRedirect();
// Unblock
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar form[name=user_block] button')->form());
$this->assertResponseIsSuccessful();
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringNotContainsString('active', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringNotContainsString('active', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/User/UserFollowControllerTest.php b/tests/Functional/Controller/User/UserFollowControllerTest.php
index cd657c1c4..6f8dc791d 100644
--- a/tests/Functional/Controller/User/UserFollowControllerTest.php
+++ b/tests/Functional/Controller/User/UserFollowControllerTest.php
@@ -10,24 +10,23 @@ class UserFollowControllerTest extends WebTestCase
{
public function testUserCanFollowAndUnfollow(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId());
// Follow
- $client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorExists('#sidebar form[name=user_follow] .active');
$this->assertSelectorTextContains('#sidebar .entry-info', 'Unfollow');
$this->assertSelectorTextContains('#sidebar .entry-info', '1');
// Unfollow
- $client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Unfollow')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Unfollow')->form());
+ $this->client->followRedirect();
$this->assertSelectorNotExists('#sidebar form[name=user_follow] .active');
$this->assertSelectorTextContains('#sidebar .entry-info', 'Follow');
@@ -36,38 +35,36 @@ public function testUserCanFollowAndUnfollow(): void
public function testXmlUserCanFollow(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId());
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Unfollow', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Unfollow', $this->client->getResponse()->getContent());
}
public function testXmlUserCanUnfollow(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('JaneDoe'));
+ $this->client->loginUser($this->getUserByUsername('JaneDoe'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId());
// Follow
- $client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Follow')->form());
+ $crawler = $this->client->followRedirect();
// Unfollow
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Unfollow')->form());
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->submit($crawler->filter('#sidebar .entry-info')->selectButton('Unfollow')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
- $this->assertStringContainsString('Follow', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
+ $this->assertStringContainsString('Follow', $this->client->getResponse()->getContent());
}
}
diff --git a/tests/Functional/Controller/User/UserFrontControllerTest.php b/tests/Functional/Controller/User/UserFrontControllerTest.php
index e3a26b044..2e5916264 100644
--- a/tests/Functional/Controller/User/UserFrontControllerTest.php
+++ b/tests/Functional/Controller/User/UserFrontControllerTest.php
@@ -13,11 +13,11 @@ class UserFrontControllerTest extends WebTestCase
{
public function testOverview(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $crawler = $client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
- $this->assertSelectorTextContains('.options.options .active', 'overview');
+ $this->assertSelectorTextContains('.options.options .active', 'Overview');
$this->assertEquals(2, $crawler->filter('#main .entry')->count());
$this->assertEquals(2, $crawler->filter('#main .entry-comment')->count());
$this->assertEquals(2, $crawler->filter('#main .post')->count());
@@ -26,53 +26,51 @@ public function testOverview(): void
public function testThreadsPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('threads')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('Threads')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'threads (1)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Threads (1)');
$this->assertEquals(1, $crawler->filter('#main .entry')->count());
}
public function testCommentsPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $crawler = $client->request('GET', '/u/JohnDoe');
- $client->click($crawler->filter('#main .options')->selectLink('comments')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $this->client->click($crawler->filter('#main .options')->selectLink('Comments')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'comments (2)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Comments (2)');
$this->assertEquals(2, $crawler->filter('#main .entry-comment')->count());
}
public function testPostsPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('posts')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('Posts')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'posts (1)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Posts (1)');
$this->assertEquals(1, $crawler->filter('#main .post')->count());
}
public function testRepliesPage(): void
{
- $client = $this->prepareEntries();
+ $this->client = $this->prepareEntries();
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('replies')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('Replies')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'replies (2)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Replies (2)');
$this->assertEquals(2, $crawler->filter('#main .post-comment')->count());
$this->assertEquals(2, $crawler->filter('#main .post')->count());
}
public function createSubscriptionsPage()
{
- $client = $this->createClient();
-
$user = $this->getUserByUsername('JohnDoe');
$this->getMagazineByName('kbin');
$this->getMagazineByName('mag', $this->getUserByUsername('JaneDoe'));
@@ -80,10 +78,10 @@ public function createSubscriptionsPage()
$manager = $this->getService(MagazineManager::class);
$manager->subscribe($this->getMagazineByName('mag'), $user);
- $client->loginUser($user);
+ $this->client->loginUser($user);
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('subscriptions')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('subscriptions')->link());
$this->assertSelectorTextContains('.options.options--top .active', 'subscriptions (2)');
$this->assertEquals(2, $crawler->filter('#main .magazines ul li')->count());
@@ -91,46 +89,40 @@ public function createSubscriptionsPage()
public function testFollowersPage(): void
{
- $client = $this->createClient();
-
$user1 = $this->getUserByUsername('JohnDoe');
$user2 = $this->getUserByUsername('JaneDoe');
$manager = $this->getService(UserManager::class);
$manager->follow($user2, $user1);
- $client->loginUser($user1);
+ $this->client->loginUser($user1);
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('followers')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('Followers')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'followers (1)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Followers (1)');
$this->assertEquals(1, $crawler->filter('#main .users ul li')->count());
}
public function testFollowingPage(): void
{
- $client = $this->createClient();
-
$user1 = $this->getUserByUsername('JohnDoe');
$user2 = $this->getUserByUsername('JaneDoe');
$manager = $this->getService(UserManager::class);
$manager->follow($user1, $user2);
- $client->loginUser($user1);
+ $this->client->loginUser($user1);
- $crawler = $client->request('GET', '/u/JohnDoe');
- $crawler = $client->click($crawler->filter('#main .options')->selectLink('following')->link());
+ $crawler = $this->client->request('GET', '/u/JohnDoe');
+ $crawler = $this->client->click($crawler->filter('#main .options')->selectLink('Following')->link());
- $this->assertSelectorTextContains('.options.options--top .active', 'following (1)');
+ $this->assertSelectorTextContains('.options.options--top .active', 'Following (1)');
$this->assertEquals(1, $crawler->filter('#main .users ul li')->count());
}
private function prepareEntries(): KernelBrowser
{
- $client = $this->createClient();
-
$entry1 = $this->getEntryByTitle(
'test entry 1',
'https://kbin.pub',
@@ -167,6 +159,6 @@ private function prepareEntries(): KernelBrowser
$this->createPostComment('test post comment 2', $post2, $this->getUserByUsername('JaneDoe'));
$this->createPostComment('test post comment 3', $post3);
- return $client;
+ return $this->client;
}
}
diff --git a/tests/Functional/Controller/VoteControllerTest.php b/tests/Functional/Controller/VoteControllerTest.php
index 8fee56fb1..3c4283a15 100644
--- a/tests/Functional/Controller/VoteControllerTest.php
+++ b/tests/Functional/Controller/VoteControllerTest.php
@@ -10,8 +10,7 @@ class VoteControllerTest extends WebTestCase
{
public function testUserCanVoteOnEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$entry = $this->getEntryByTitle('test entry 1', 'https://kbin.pub');
@@ -21,30 +20,28 @@ public function testUserCanVoteOnEntry(): void
$this->createVote(1, $entry, $u1);
$this->createVote(1, $entry, $u2);
- $client->request('GET', '/');
- $crawler = $client->request('GET', '/m/acme/t/'.$entry->getId().'/-/comments');
+ $this->client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$entry->getId().'/-/comments');
- $this->assertUpDownVoteActions($client, $crawler);
+ $this->assertUpDownVoteActions($crawler);
}
public function testXmlUserCanVoteOnEntry(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$this->getEntryByTitle('test entry 1', 'https://kbin.pub');
- $crawler = $client->request('GET', '/');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('.entry .vote__up')->form());
+ $crawler = $this->client->request('GET', '/');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('.entry .vote__up')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testUserCanVoteOnEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$comment = $this->createEntryComment('test entry comment 1');
@@ -54,57 +51,56 @@ public function testUserCanVoteOnEntryComment(): void
$this->createVote(1, $comment, $u1);
$this->createVote(1, $comment, $u2);
- $client->request('GET', '/');
- $crawler = $client->request('GET', '/m/acme/t/'.$comment->entry->getId().'/-/comments');
+ $this->client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$comment->entry->getId().'/-/comments');
- $this->assertUpDownVoteActions($client, $crawler, '.comment');
+ $this->assertUpDownVoteActions($crawler, '.comment');
}
public function testXmlUserCanVoteOnEntryComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$comment = $this->createEntryComment('test entry comment 1');
- $crawler = $client->request('GET', '/m/acme/t/'.$comment->entry->getId().'/-/comments');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('.entry-comment .vote__up')->form());
+ $crawler = $this->client->request('GET', '/m/acme/t/'.$comment->entry->getId().'/-/comments');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('.entry-comment .vote__up')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
- private function assertUpDownVoteActions($client, $crawler, string $selector = ''): void
+ private function assertUpDownVoteActions($crawler, string $selector = ''): void
{
$this->assertSelectorTextContains($selector.' .vote__up', '2');
$this->assertSelectorTextContains($selector.' .vote__down', '0');
- $client->click($crawler->filter($selector.' .vote__up')->form());
- $crawler = $client->followRedirect();
+ $this->client->click($crawler->filter($selector.' .vote__up')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '3');
$this->assertSelectorTextContains($selector.' .vote__down', '0');
- $client->click($crawler->filter($selector.' .vote__down')->form());
- $crawler = $client->followRedirect();
+ $this->client->click($crawler->filter($selector.' .vote__down')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '2');
$this->assertSelectorTextContains($selector.' .vote__down', '1');
- $client->click($crawler->filter($selector.' .vote__down')->form());
- $crawler = $client->followRedirect();
+ $this->client->click($crawler->filter($selector.' .vote__down')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '2');
$this->assertSelectorTextContains($selector.' .vote__down', '0');
- $client->submit($crawler->filter($selector.' .vote__up')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter($selector.' .vote__up')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '3');
$this->assertSelectorTextContains($selector.' .vote__down', '0');
- $client->submit($crawler->filter($selector.' .vote__up')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter($selector.' .vote__up')->form());
+ $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '2');
$this->assertSelectorTextContains($selector.' .vote__down', '0');
@@ -112,8 +108,7 @@ private function assertUpDownVoteActions($client, $crawler, string $selector = '
public function testUserCanVoteOnPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$post = $this->createPost('test post 1');
@@ -123,29 +118,28 @@ public function testUserCanVoteOnPost(): void
$this->createVote(1, $post, $u1);
$this->createVote(1, $post, $u2);
- $crawler = $client->request('GET', '/m/acme/p/'.$post->getId().'/-/comments');
+ $crawler = $this->client->request('GET', '/m/acme/p/'.$post->getId().'/-');
+ self::assertResponseIsSuccessful();
- $this->assertUpVoteActions($client, $crawler);
+ $this->assertUpVoteActions($crawler);
}
public function testXmlUserCanVoteOnPost(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$this->createPost('test post 1');
- $crawler = $client->request('GET', '/microblog');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('.post .vote__up')->form());
+ $crawler = $this->client->request('GET', '/microblog');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('.post .vote__up')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
public function testUserCanVoteOnPostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$comment = $this->createPostComment('test post comment 1');
@@ -155,36 +149,35 @@ public function testUserCanVoteOnPostComment(): void
$this->createVote(1, $comment, $u1);
$this->createVote(1, $comment, $u2);
- $crawler = $client->request('GET', '/m/acme/p/'.$comment->post->getId());
+ $crawler = $this->client->request('GET', '/m/acme/p/'.$comment->post->getId());
- $this->assertUpVoteActions($client, $crawler, '.comment');
+ $this->assertUpVoteActions($crawler, '.comment');
}
public function testXmlUserCanVoteOnPostComment(): void
{
- $client = $this->createClient();
- $client->loginUser($this->getUserByUsername('Actor'));
+ $this->client->loginUser($this->getUserByUsername('Actor'));
$comment = $this->createPostComment('test post comment 1');
- $crawler = $client->request('GET', '/m/acme/p/'.$comment->post->getId().'/-');
- $client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
- $client->click($crawler->filter('.post-comment .vote__up')->form());
+ $crawler = $this->client->request('GET', '/m/acme/p/'.$comment->post->getId().'/-');
+ $this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
+ $this->client->click($crawler->filter('.post-comment .vote__up')->form());
- $this->assertStringContainsString('{"html":', $client->getResponse()->getContent());
+ $this->assertStringContainsString('{"html":', $this->client->getResponse()->getContent());
}
- private function assertUpVoteActions($client, $crawler, string $selector = ''): void
+ private function assertUpVoteActions($crawler, string $selector = ''): void
{
$this->assertSelectorTextContains($selector.' .vote__up', '2');
- $client->submit($crawler->filter($selector.' .vote__up')->form());
- $crawler = $client->followRedirect();
+ $this->client->submit($crawler->filter($selector.' .vote__up')->form());
+ $crawler = $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '3');
- $client->submit($crawler->filter($selector.' .vote__up')->form());
- $client->followRedirect();
+ $this->client->submit($crawler->filter($selector.' .vote__up')->form());
+ $this->client->followRedirect();
$this->assertSelectorTextContains($selector.' .vote__up', '2');
}
diff --git a/tests/Unit/Service/MentionManagerTest.php b/tests/Unit/Service/MentionManagerTest.php
index 60eb5abb4..a7f0523a7 100644
--- a/tests/Unit/Service/MentionManagerTest.php
+++ b/tests/Unit/Service/MentionManagerTest.php
@@ -15,8 +15,6 @@ class MentionManagerTest extends WebTestCase
*/
public function testExtract(string $input, ?array $output): void
{
- $this->createClient();
-
// Create a SettingsManager mock
$settingsManagerMock = $this->createMock(SettingsManager::class);
diff --git a/tests/WebTestCase.php b/tests/WebTestCase.php
index e1a1ba1d9..b008d5b23 100644
--- a/tests/WebTestCase.php
+++ b/tests/WebTestCase.php
@@ -5,6 +5,7 @@
namespace App\Tests;
use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
@@ -16,17 +17,17 @@ abstract class WebTestCase extends BaseWebTestCase
protected const PAGINATED_KEYS = ['items', 'pagination'];
protected const PAGINATION_KEYS = ['count', 'currentPage', 'maxPage', 'perPage'];
- protected const IMAGE_KEYS = ['filePath', 'sourceUrl', 'storageUrl', 'altText', 'width', 'height'];
+ protected const IMAGE_KEYS = ['filePath', 'sourceUrl', 'storageUrl', 'altText', 'width', 'height', 'blurHash'];
protected const MESSAGE_RESPONSE_KEYS = ['messageId', 'threadId', 'sender', 'body', 'status', 'createdAt'];
- protected const USER_RESPONSE_KEYS = ['userId', 'username', 'about', 'avatar', 'cover', 'createdAt', 'followersCount', 'apId', 'apProfileId', 'isBot', 'isFollowedByUser', 'isFollowerOfUser', 'isBlockedByUser'];
- protected const USER_SMALL_RESPONSE_KEYS = ['userId', 'username', 'isBot', 'isFollowedByUser', 'isFollowerOfUser', 'isBlockedByUser', 'avatar', 'apId', 'apProfileId', 'createdAt'];
- protected const ENTRY_RESPONSE_KEYS = ['entryId', 'magazine', 'user', 'domain', 'title', 'url', 'image', 'body', 'lang', 'tags', 'badges', 'numComments', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'isOc', 'isAdult', 'isPinned', 'createdAt', 'editedAt', 'lastActive', 'visibility', 'type', 'slug', 'apId'];
- protected const ENTRY_COMMENT_RESPONSE_KEYS = ['commentId', 'magazine', 'user', 'entryId', 'parentId', 'rootId', 'image', 'body', 'lang', 'isAdult', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'mentions', 'tags', 'createdAt', 'editedAt', 'lastActive', 'childCount', 'children'];
- protected const POST_RESPONSE_KEYS = ['postId', 'user', 'magazine', 'image', 'body', 'lang', 'isAdult', 'isPinned', 'comments', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'tags', 'mentions', 'createdAt', 'editedAt', 'lastActive', 'slug'];
- protected const POST_COMMENT_RESPONSE_KEYS = ['commentId', 'user', 'magazine', 'postId', 'parentId', 'rootId', 'image', 'body', 'lang', 'isAdult', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'mentions', 'tags', 'createdAt', 'editedAt', 'lastActive', 'childCount', 'children'];
+ protected const USER_RESPONSE_KEYS = ['userId', 'username', 'about', 'avatar', 'cover', 'createdAt', 'followersCount', 'apId', 'apProfileId', 'isBot', 'isFollowedByUser', 'isFollowerOfUser', 'isBlockedByUser', 'isAdmin', 'isGlobalModerator', 'serverSoftware', 'serverSoftwareVersion'];
+ protected const USER_SMALL_RESPONSE_KEYS = ['userId', 'username', 'isBot', 'isFollowedByUser', 'isFollowerOfUser', 'isBlockedByUser', 'avatar', 'apId', 'apProfileId', 'createdAt', 'isAdmin', 'isGlobalModerator'];
+ protected const ENTRY_RESPONSE_KEYS = ['entryId', 'magazine', 'user', 'domain', 'title', 'url', 'image', 'body', 'lang', 'tags', 'badges', 'numComments', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'isOc', 'isAdult', 'isPinned', 'createdAt', 'editedAt', 'lastActive', 'visibility', 'type', 'slug', 'apId', 'canAuthUserModerate'];
+ protected const ENTRY_COMMENT_RESPONSE_KEYS = ['commentId', 'magazine', 'user', 'entryId', 'parentId', 'rootId', 'image', 'body', 'lang', 'isAdult', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'mentions', 'tags', 'createdAt', 'editedAt', 'lastActive', 'childCount', 'children', 'canAuthUserModerate'];
+ protected const POST_RESPONSE_KEYS = ['postId', 'user', 'magazine', 'image', 'body', 'lang', 'isAdult', 'isPinned', 'comments', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'tags', 'mentions', 'createdAt', 'editedAt', 'lastActive', 'slug', 'canAuthUserModerate'];
+ protected const POST_COMMENT_RESPONSE_KEYS = ['commentId', 'user', 'magazine', 'postId', 'parentId', 'rootId', 'image', 'body', 'lang', 'isAdult', 'uv', 'dv', 'favourites', 'isFavourited', 'userVote', 'visibility', 'apId', 'mentions', 'tags', 'createdAt', 'editedAt', 'lastActive', 'childCount', 'children', 'canAuthUserModerate'];
protected const BAN_RESPONSE_KEYS = ['banId', 'reason', 'expired', 'expiredAt', 'bannedUser', 'bannedBy', 'magazine'];
protected const LOG_ENTRY_KEYS = ['type', 'createdAt', 'magazine', 'moderator', 'subject'];
- protected const MAGAZINE_RESPONSE_KEYS = ['magazineId', 'owner', 'icon', 'name', 'title', 'description', 'rules', 'subscriptionsCount', 'entryCount', 'entryCommentCount', 'postCount', 'postCommentCount', 'isAdult', 'isUserSubscribed', 'isBlockedByUser', 'tags', 'badges', 'moderators', 'apId', 'apProfileId'];
+ protected const MAGAZINE_RESPONSE_KEYS = ['magazineId', 'owner', 'icon', 'name', 'title', 'description', 'rules', 'subscriptionsCount', 'entryCount', 'entryCommentCount', 'postCount', 'postCommentCount', 'isAdult', 'isUserSubscribed', 'isBlockedByUser', 'tags', 'badges', 'moderators', 'apId', 'apProfileId', 'serverSoftware', 'serverSoftwareVersion', 'isPostingRestrictedToMods', 'localSubscribers'];
protected const MAGAZINE_SMALL_RESPONSE_KEYS = ['magazineId', 'name', 'icon', 'isUserSubscribed', 'isBlockedByUser', 'apId', 'apProfileId'];
protected const DOMAIN_RESPONSE_KEYS = ['domainId', 'name', 'entryCount', 'subscriptionsCount', 'isUserSubscribed', 'isBlockedByUser'];
@@ -36,6 +37,9 @@ abstract class WebTestCase extends BaseWebTestCase
protected ArrayCollection $magazines;
protected ArrayCollection $entries;
+ protected EntityManagerInterface $entityManager;
+ protected KernelBrowser $client;
+
protected string $kibbyPath;
public function setUp(): void
@@ -44,6 +48,8 @@ public function setUp(): void
$this->magazines = new ArrayCollection();
$this->entries = new ArrayCollection();
$this->kibbyPath = \dirname(__FILE__).'/assets/kibby_emoji.png';
+ $this->client = static::createClient();
+ $this->entityManager = $this->getService(EntityManagerInterface::class);
}
/**
@@ -83,4 +89,14 @@ public static function assertNotReached(string $message = 'This branch should ne
{
self::assertFalse(true, $message);
}
+
+ protected function tearDown(): void
+ {
+ parent::tearDown();
+
+ $entityManager = $this->entityManager;
+ if ($entityManager->isOpen()) {
+ $entityManager->close();
+ }
+ }
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 029a8df1a..1aed28dfe 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -25,6 +25,12 @@ function bootstrapDatabase(): void
$application = new Application($kernel);
$application->setAutoExit(false);
+ $application->run(new ArrayInput([
+ 'command' => 'cache:pool:clear',
+ '--all' => '1',
+ '--no-interaction' => true,
+ ]));
+
$application->run(new ArrayInput([
'command' => 'doctrine:database:drop',
'--if-exists' => '1',
@@ -40,6 +46,16 @@ function bootstrapDatabase(): void
'--no-interaction' => true,
]));
+ $application->run(new ArrayInput([
+ 'command' => 'mbin:ap:keys:update',
+ '--no-interaction' => true,
+ ]));
+
+ $application->run(new ArrayInput([
+ 'command' => 'mbin:push:keys:update',
+ '--no-interaction' => true,
+ ]));
+
$kernel->shutdown();
}