Fix tests

This commit is contained in:
Ernest Wiśniewski 2023-03-18 13:40:06 +01:00
parent 581d5600e0
commit 3231f28268
30 changed files with 53 additions and 60 deletions

File diff suppressed because one or more lines are too long

View file

@ -52,7 +52,7 @@ abstract class AbstractController extends BaseAbstractController
return new JsonResponse(
[
'success' => true,
'html' => '<div class="alert alert__info">Reported</div>'
'html' => '<div class="alert alert__info">Reported</div>',
]
);
}

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Controller;
use App\Controller\User\ThemeSettingsController;
use App\DTO\UserNoteDto;
use App\Entity\Entry;
use App\Entity\EntryComment;

View file

@ -74,7 +74,7 @@ class EntrySingleController extends AbstractController
'magazine' => $magazine,
'comments' => $comments,
'entry' => $entry,
'form' => $this->createForm(EntryCommentType::class, null, [
'form' => $this->createForm(EntryCommentType::class, null, [
'action' => $this->generateUrl(
'entry_comment_create',
[

View file

@ -22,7 +22,7 @@ class PostVotersController extends AbstractController
if ($request->isXmlHttpRequest()) {
return new JsonResponse([
'html' => $this->renderView('components/voters_inline.html.twig', [
'voters' => $post->getUpVotes()->map(fn($vote) => $vote->user->username),
'voters' => $post->getUpVotes()->map(fn ($vote) => $vote->user->username),
'attributes' => new ComponentAttributes([]),
'count' => 0,
]),

View file

@ -34,7 +34,6 @@ class ThemeSettingsController extends AbstractController
public const TRUE = 'true';
public const FALSE = 'false';
public const KEYS = [
self::ENTRIES_VIEW,
self::ENTRY_COMMENTS_VIEW,

View file

@ -113,7 +113,7 @@ class UserEditController extends AbstractController
}
}
if($form->has('newEmail')) {
if ($form->has('newEmail')) {
$dto->email = $form->get('newEmail')->getData();
}

View file

@ -257,7 +257,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Equatab
public function getPassword(): string
{
return (string)$this->password;
return (string) $this->password;
}
public function setPassword(string $password): self
@ -288,7 +288,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Equatab
$tokens = $this->moderatorTokens->matching($criteria);
// Magazines
$magazines = $tokens->map(fn($token) => $token->magazine);
$magazines = $tokens->map(fn ($token) => $token->magazine);
$criteria = Criteria::create()
->orderBy(['lastActive' => Criteria::DESC]);
@ -570,7 +570,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Equatab
{
return $this->notifications
->matching($this->getNewNotificationsCriteria())
->filter(fn($notification) => 'message_notification' !== $notification->getType())
->filter(fn ($notification) => 'message_notification' !== $notification->getType())
->count();
}
@ -581,7 +581,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Equatab
return $this->notifications
->matching($criteria)
->filter(fn($notification) => 'message_notification' === $notification->getType())
->filter(fn ($notification) => 'message_notification' === $notification->getType())
->count();
}

View file

@ -23,7 +23,7 @@ class EntryCommentType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('body', TextareaType::class)
->add('body', TextareaType::class, ['required' => false])
->add(
'image',
FileType::class,

View file

@ -44,42 +44,42 @@ class UserSettingsType extends AbstractType
->add(
'showProfileSubscriptions',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'showProfileFollowings',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewEntry',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewEntryReply',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewEntryCommentReply',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewPost',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewPostReply',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add(
'notifyOnNewPostCommentReply',
CheckboxType::class,
[ 'required' => false]
['required' => false]
)
->add('submit', SubmitType::class);

View file

@ -140,7 +140,6 @@ class EntryCommentRepository extends ServiceEntityRepository implements TagRepos
}
if ($criteria->tag) {
$qb->andWhere("JSONB_CONTAINS(c.tags, '\"".$criteria->tag."\"') = true");
}

View file

@ -245,22 +245,22 @@ class MagazineRepository extends ServiceEntityRepository
$result = $pagerfanta->getCurrentPageResults();
$entries = $this->_em->getRepository(Entry::class)->findBy(
['id' => $this->getOverviewIds((array)$result, 'entry')]
['id' => $this->getOverviewIds((array) $result, 'entry')]
);
$this->_em->getRepository(Entry::class)->hydrate(...$entries);
$entryComments = $this->_em->getRepository(EntryComment::class)->findBy(
['id' => $this->getOverviewIds((array)$result, 'entry_comment')]
['id' => $this->getOverviewIds((array) $result, 'entry_comment')]
);
$this->_em->getRepository(EntryComment::class)->hydrate(...$entryComments);
$post = $this->_em->getRepository(Post::class)->findBy(['id' => $this->getOverviewIds((array)$result, 'post')]);
$post = $this->_em->getRepository(Post::class)->findBy(['id' => $this->getOverviewIds((array) $result, 'post')]);
$this->_em->getRepository(Post::class)->hydrate(...$post);
$postComment = $this->_em->getRepository(PostComment::class)->findBy(
['id' => $this->getOverviewIds((array)$result, 'post_comment')]
['id' => $this->getOverviewIds((array) $result, 'post_comment')]
);
$this->_em->getRepository(PostComment::class)->hydrate(...$postComment);
$result = array_merge($entries, $entryComments, $post, $postComment);
uasort($result, fn($a, $b) => $a->getCreatedAt() > $b->getCreatedAt() ? -1 : 1);
uasort($result, fn ($a, $b) => $a->getCreatedAt() > $b->getCreatedAt() ? -1 : 1);
$pagerfanta = new Pagerfanta(
new ArrayAdapter(
@ -271,7 +271,7 @@ class MagazineRepository extends ServiceEntityRepository
try {
$pagerfanta->setMaxPerPage(self::PER_PAGE);
$pagerfanta->setCurrentPage($page);
$pagerfanta->setMaxNbPages($countAll > 0 ? ((int)ceil($countAll / self::PER_PAGE)) : 1);
$pagerfanta->setMaxNbPages($countAll > 0 ? ((int) ceil($countAll / self::PER_PAGE)) : 1);
} catch (NotValidCurrentPageException $e) {
throw new NotFoundHttpException();
}
@ -281,9 +281,9 @@ class MagazineRepository extends ServiceEntityRepository
private function getOverviewIds(array $result, string $type): array
{
$result = array_filter($result, fn($subject) => $subject['type'] === $type);
$result = array_filter($result, fn ($subject) => $subject['type'] === $type);
return array_map(fn($subject) => $subject['id'], $result);
return array_map(fn ($subject) => $subject['id'], $result);
}
public function findAudience(Magazine $magazine): array

View file

@ -10,7 +10,6 @@ use App\Entity\EntryComment;
use App\Entity\Post;
use App\Entity\PostComment;
use App\Entity\User;
use App\Entity\UserBlock;
use App\Entity\UserFollow;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Result;

View file

@ -27,15 +27,14 @@ final class VotersInlineComponent
*/
$votes = $this->subject->votes;
$votes = $votes->matching(
(new Criteria(Criteria::expr()->eq('choice', VoteInterface::VOTE_UP), ['createdAt' => Criteria::DESC]))
new Criteria(Criteria::expr()->eq('choice', VoteInterface::VOTE_UP), ['createdAt' => Criteria::DESC])
)->slice(0, 4);
return $this->twig->render(
'components/voters_inline.html.twig',
[
'attributes' => new ComponentAttributes($attributes->all()),
'voters' => array_map(fn($vote) => $vote->user->username, $votes),
'voters' => array_map(fn ($vote) => $vote->user->username, $votes),
'count' => $this->subject->countUpVotes(),
'url' => $this->url,
]

View file

@ -4,7 +4,6 @@ namespace App\Twig\Extension;
use App\Twig\Runtime\MediaExtensionRuntime;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class MediaExtension extends AbstractExtension

View file

@ -27,6 +27,7 @@ class LinkExtensionRuntime implements RuntimeExtensionInterface
public function getHtmlClass(ContentInterface $content): string
{
$service = $this->generateHtmlClassService;
return $service($content);
}
}

View file

@ -18,7 +18,7 @@
</button>
{{ form_row(form.submit, {label: comment is defined and comment ? 'edit_comment' : 'add_comment', attr: {class: 'btn btn__primary', 'data-action': 'subject#sendForm'}}) }}
</div>
<div class="media">
<div hidden class="media">
{{ form_row(form.image, {label: 'image'}) }}
{{ form_row(form.imageAlt, {label: 'image_alt'}) }}
</div>

View file

@ -74,14 +74,14 @@ class EntryCommentCreateControllerTest extends WebTestCase
$client->submit(
$crawler->filter('form[name=entry_comment]')->selectButton('Add comment')->form(
[
'entry_comment[body]' => 't',
'entry_comment[body]' => '',
]
)
);
$this->assertSelectorTextContains(
'#content',
'This value is too short. It should have 2 characters or more.'
'This value should not be blank.'
);
}
}

View file

@ -48,7 +48,7 @@ class EntryCommentFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('blockquote header', 'in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
$this->assertSelectorTextContains('#header .magazine', '/m/acme');
$this->assertSelectorTextContains('#header .head-title', '/m/acme');
$this->assertSelectorTextContains('#sidebar .magazine', 'acme');
$this->assertcount(2, $crawler->filter('.comment'));
@ -79,7 +79,7 @@ class EntryCommentFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
$this->assertSelectorTextContains('#header .magazine', '/sub');
$this->assertSelectorTextContains('#header .head-title', '/sub');
$this->assertcount(2, $crawler->filter('.comment'));
@ -110,7 +110,7 @@ class EntryCommentFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('blockquote header', 'to acme in test entry 1');
$this->assertSelectorTextContains('blockquote .content', 'test comment 2');
$this->assertSelectorTextContains('#header .magazine', '/mod');
$this->assertSelectorTextContains('#header .head-title', '/mod');
$this->assertcount(2, $crawler->filter('.comment'));

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Tests\Functional\Controller\Entry;
use App\Service\FavouriteManager;
use App\Tests\WebTestCase;
class EntryFavouriteControllerTest extends WebTestCase

View file

@ -47,7 +47,7 @@ class EntryFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextNotContains('.entry__meta', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/m/acme');
$this->assertSelectorTextContains('#header .head-title', '/m/acme');
$this->assertSelectorTextContains('#sidebar .magazine', 'acme');
$this->assertSelectorTextContains('#header .active', 'Threads');
@ -79,7 +79,7 @@ class EntryFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/sub');
$this->assertSelectorTextContains('#header .head-title', '/sub');
$this->assertSelectorTextContains('#header .active', 'Threads');
@ -111,7 +111,7 @@ class EntryFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.entry__meta', 'JohnDoe');
$this->assertSelectorTextContains('.entry__meta', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/mod');
$this->assertSelectorTextContains('#header .head-title', '/mod');
$this->assertSelectorTextContains('#header .active', 'Threads');
@ -141,7 +141,7 @@ class EntryFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.entry__meta', 'JaneDoe');
$this->assertSelectorTextContains('.entry__meta', 'to kbin');
$this->assertSelectorTextContains('#header .magazine', '/fav');
$this->assertSelectorTextContains('#header .head-title', '/fav');
$this->assertSelectorTextContains('#header .active', 'Threads');

View file

@ -24,7 +24,7 @@ class EntrySingleControllerTest extends WebTestCase
$client->click($crawler->selectLink('test entry 1')->link());
$this->assertSelectorTextContains('#header .magazine', '/m/acme');
$this->assertSelectorTextContains('#header .head-title', '/m/acme');
$this->assertSelectorTextContains('#header nav .active', 'Threads');
$this->assertSelectorTextContains('article h1', 'test entry 1');
$this->assertSelectorTextContains('#main', 'No comments');

View file

@ -22,7 +22,7 @@ class EntryVotersControllerTest extends WebTestCase
$crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$client->click($crawler->filter('.options-activity')->selectLink('up votes (1)')->link());
$client->click($crawler->filter('.options-activity')->selectLink('boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
}
@ -39,7 +39,7 @@ class EntryVotersControllerTest extends WebTestCase
$crawler = $client->request('GET', "/m/acme/t/{$entry->getId()}/test-entry-1");
$client->click($crawler->filter('.options-activity')->selectLink('down votes (1)')->link());
$client->click($crawler->filter('.options-activity')->selectLink('reduces (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
}

View file

@ -28,7 +28,7 @@ class MagazineCreateControllerTest extends WebTestCase
$client->followRedirect();
$this->assertSelectorTextContains('header .magazine', '/m/TestMagazine');
$this->assertSelectorTextContains('header .head-title', '/m/TestMagazine');
$this->assertSelectorTextContains('#content', 'Empty');
}

View file

@ -43,11 +43,11 @@ class PostCommentCreateControllerTest extends WebTestCase
$crawler = $client->submit(
$crawler->filter('form[name=post_comment]')->selectButton('Add comment')->form(
[
'post_comment[body]' => 't',
'post_comment[body]' => '',
]
)
);
$this->assertSelectorTextContains('#content', 'This value is too short. It should have 2 characters or more.');
$this->assertSelectorTextContains('#content', 'This value should not be blank.');
}
}

View file

@ -43,11 +43,11 @@ class PostCreateControllerTest extends WebTestCase
$crawler = $client->submit(
$crawler->filter('form[name=post]')->selectButton('Add post')->form(
[
'post[body]' => 't',
'post[body]' => '',
]
)
);
$this->assertSelectorTextContains('#content', 'This value is too short. It should have 2 characters or more.');
$this->assertSelectorTextContains('#content', 'This value should not be blank.');
}
}

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Tests\Functional\Controller\Post;
use App\Service\FavouriteManager;
use App\Tests\WebTestCase;
class PostFavouriteControllerTest extends WebTestCase

View file

@ -47,7 +47,7 @@ class PostFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextNotContains('.post header', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/m/acme');
$this->assertSelectorTextContains('#header .head-title', '/m/acme');
$this->assertSelectorTextContains('#sidebar .magazine', 'acme');
$this->assertSelectorTextContains('#header .active', 'Microblog');
@ -79,7 +79,7 @@ class PostFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/sub');
$this->assertSelectorTextContains('#header .head-title', '/sub');
$this->assertSelectorTextContains('#header .active', 'Microblog');
@ -111,7 +111,7 @@ class PostFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/mod');
$this->assertSelectorTextContains('#header .head-title', '/mod');
$this->assertSelectorTextContains('#header .active', 'Microblog');
@ -141,7 +141,7 @@ class PostFrontControllerTest extends WebTestCase
$this->assertSelectorTextContains('.post header', 'JohnDoe');
$this->assertSelectorTextContains('.post header', 'to acme');
$this->assertSelectorTextContains('#header .magazine', '/fav');
$this->assertSelectorTextContains('#header .head-title', '/fav');
$this->assertSelectorTextContains('#header .active', 'Microblog');

View file

@ -22,7 +22,7 @@ class PostVotersControllerTest extends WebTestCase
$crawler = $client->request('GET', "/m/acme/p/{$post->getId()}/test-post-1");
$client->click($crawler->filter('.options-activity')->selectLink('up votes (1)')->link());
$client->click($crawler->filter('.options-activity')->selectLink('boosts (1)')->link());
$this->assertSelectorTextContains('#main .users-columns', 'JaneDoe');
}

View file

@ -17,7 +17,7 @@ class UserFrontControllerTest extends WebTestCase
$crawler = $client->request('GET', '/u/JohnDoe');
$this->assertSelectorTextContains('.options.options--top .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());