From 24ad8b8912abe1e97b406cd272f8609c77306b84 Mon Sep 17 00:00:00 2001 From: lutangar Date: Tue, 27 Apr 2021 13:34:16 +0200 Subject: [PATCH] test(analytics): Add fixtures to test more matching contexts usecases This is useful to test some issues related to wrong stats --- config/packages/easy_admin.yaml | 7 ++ src/DataFixtures/DomainFixtures.php | 12 +++ .../NoticeMatchingContextFixtures.php | 82 +++++++++++++++++++ src/Domain/Factory/MatchingContextFactory.php | 26 ++++++ 4 files changed, 127 insertions(+) create mode 100644 src/DataFixtures/NoticeMatchingContextFixtures.php create mode 100644 src/Domain/Factory/MatchingContextFactory.php diff --git a/config/packages/easy_admin.yaml b/config/packages/easy_admin.yaml index d02e44e4..3722e615 100644 --- a/config/packages/easy_admin.yaml +++ b/config/packages/easy_admin.yaml @@ -71,6 +71,13 @@ easy_admin: - { property: matchingContexts, label: notices.matchingContexts } - { property: expires, label: notices.expires } - { property: unpublishedOnExpiration, label: notices.unpublishedOnExpiration } + - { property: badgedRatingCount, label: notices.badgedRatingCount } + - { property: displayedRatingCount, label: notices.displayedRatingCount, css_class: 'graphable column-displayedRatingCount' } + - { property: unfoldedRatingCount, label: notices.unfoldedRatingCount, css_class: 'graphable column-unfoldedRatingCount' } + - { property: clickedRatingCount, label: notices.clickedRatingCount, css_class: 'graphable column-clickedRatingCount' } + - { property: likedRatingCount, label: notices.likedRatingCount, css_class: 'graphable column-likedRatingCount' } + - { property: dislikedRatingCount, label: notices.dislikedRatingCount, css_class: 'graphable column-dislikedRatingCount' } + - { property: dismissedRatingCount, label: notices.dismissedRatingCount, css_class: 'graphable column-dismissedRatingCount' } form: ¬iceForm fields: - { type: group, label: notices.groups.publication, icon: comments, columns: 8 } diff --git a/src/DataFixtures/DomainFixtures.php b/src/DataFixtures/DomainFixtures.php index 3c0829f4..4a05a27c 100644 --- a/src/DataFixtures/DomainFixtures.php +++ b/src/DataFixtures/DomainFixtures.php @@ -59,6 +59,18 @@ public function load(ObjectManager $manager): void $manager->persist($okinawa); $this->addReference('okinawa_domain', $okinawa); + $testsMenantDomain = new DomainName('tests.menant-benjamin.fr'); + $manager->persist($testsMenantDomain); + $this->addReference('tests_menant_domain', $testsMenantDomain); + + $lbcDomain = new DomainName('leboncoin.fr'); + $manager->persist($lbcDomain); + $this->addReference('lbc_domain', $lbcDomain); + + $lequipe = new DomainName('lequipe.fr'); + $manager->persist($lequipe); + $this->addReference('lequipe_domain', $lequipe); + $manager->flush(); } diff --git a/src/DataFixtures/NoticeMatchingContextFixtures.php b/src/DataFixtures/NoticeMatchingContextFixtures.php new file mode 100644 index 00000000..484f2e29 --- /dev/null +++ b/src/DataFixtures/NoticeMatchingContextFixtures.php @@ -0,0 +1,82 @@ +getReference('famous_contributor'); + + $notice = new Notice(); + $notice->setContributor($famousContributor); + $notice->setMessage('This notice has two matching contexts on same domain'); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('tests_menant_domain'), + '.*', + "//text()[contains(.,'Not Found')]" + )); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('tests_menant_domain'), + '.*', + "//text()[contains(.,'was not found on this server')]" + )); + $manager->persist($notice); + + $notice = new Notice(); + $notice->setContributor($famousContributor); + $notice->setMessage('This notice on the same domain of others notices.'); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('tests_menant_domain'), + '.*', + "//text()[contains(.,'This is not an error!')]" + )); + $manager->persist($notice); + + $notice = new Notice(); + $notice->setContributor($famousContributor); + $notice->setMessage('This notice appear on lbc when the word "location" is found.'); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('lbc_domain'), + '.*', + "//text()[contains(.,'location')]" + )); + $manager->persist($notice); + + $notice = new Notice(); + $notice->setContributor($famousContributor); + $notice->setMessage('This notice appear on lbc when the word "piscine" is found.'); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('lbc_domain'), + '.*', + "//text()[contains(.,'piscine')]" + )); + $manager->persist($notice); + + $notice = new Notice(); + $notice->setContributor($famousContributor); + $notice->setMessage("Accès gratuit aux notes des joueurs sur d'autres sites..."); + $notice->addMatchingContext(MatchingContextFactory::create( + $this->getReference('lequipe_domain'), + '.*((football.*article.*notes)|(football.*notes.*match))' + )); + $manager->persist($notice); + + $manager->flush(); + } + + public function getDependencies() + { + return [ContributorFixtures::class, DomainFixtures::class]; + } +} diff --git a/src/Domain/Factory/MatchingContextFactory.php b/src/Domain/Factory/MatchingContextFactory.php new file mode 100644 index 00000000..ff79fd9a --- /dev/null +++ b/src/Domain/Factory/MatchingContextFactory.php @@ -0,0 +1,26 @@ +addDomainName($domainName); + $matchingContext->setUrlRegex($urlRegex); + if ($xpath) { + $matchingContext->setXpath($xpath); + } + + return $matchingContext; + } +}