-
Notifications
You must be signed in to change notification settings - Fork 8
Udp. Search form. Process requests only if a native search form is used. #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexandergull
wants to merge
5
commits into
dev
Choose a base branch
from
get-forms-vai-alt.ag
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
baf49be
Udp. Search form. Process requests only if a native search form is used.
alexandergull 5d3f426
CP. Minor fixes.
alexandergull da5b5a6
Fix. Create tables on PHP unit.
alexandergull 3b732a0
CP. Reduce calls.
alexandergull b026e11
Merge remote-tracking branch 'origin/dev' into get-forms-vai-alt.ag
Glomberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
tests/Antispam/IntegrationsByClass/TestWPSearchForm.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <?php | ||
|
|
||
| namespace Antispam\IntegrationsByClass; | ||
|
|
||
| use Cleantalk\Antispam\IntegrationsByClass\WPSearchForm; | ||
| use Cleantalk\ApbctWP\UpdatePlugin\DbTablesCreator; | ||
| use Cleantalk\ApbctWP\Variables\AltSessions; | ||
| use Cleantalk\ApbctWP\Variables\Server; | ||
| use PHPUnit\Framework\TestCase; | ||
|
alexandergull marked this conversation as resolved.
|
||
|
|
||
| class TestWPSearchForm extends TestCase | ||
| { | ||
| /** | ||
| * @var array | ||
| */ | ||
| private $serverBackup = array(); | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| global $wpdb; | ||
| parent::setUp(); | ||
|
|
||
| $this->serverBackup = $_SERVER; | ||
| Server::getInstance()->variables = []; | ||
|
|
||
| $_SERVER['HTTP_USER_AGENT'] = 'phpunit-user-agent'; | ||
| $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.9'; | ||
| $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; | ||
| $_SERVER['REQUEST_URI'] = '/search-source-page/'; | ||
| $_SERVER['HTTP_REFERER'] = ''; | ||
|
|
||
| $creator = new DbTablesCreator(); | ||
| $creator->createTable($wpdb->prefix . 'cleantalk_sessions'); | ||
|
|
||
| AltSessions::wipe(); | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| AltSessions::wipe(); | ||
|
|
||
| $_SERVER = $this->serverBackup; | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
|
|
||
| public function testSetSearchFormDrawnStoresCurrentRequestPath() | ||
| { | ||
| $_SERVER['REQUEST_URI'] = '/search-source-page/?foo=bar'; | ||
|
|
||
| WPSearchForm::setSearchFormDrawn(); | ||
|
|
||
| $stored = AltSessions::get('search_form_ready'); | ||
| $stored = is_string($stored) ? json_decode($stored, true) : $stored; | ||
| $this->assertIsArray($stored); | ||
| $this->assertArrayHasKey('/search-source-page/', $stored); | ||
| $this->assertSame(1, $stored['/search-source-page/']); | ||
| } | ||
|
|
||
| public function testIsSearchFormDrawnReturnsStoredPathIfRefererMatches() | ||
| { | ||
| $_SERVER['REQUEST_URI'] = '/search-source-page/'; | ||
| WPSearchForm::setSearchFormDrawn(); | ||
|
|
||
| $_SERVER['HTTP_REFERER'] = 'https://example.test/search-source-page/?s=query'; | ||
|
|
||
| $this->assertSame( | ||
| '/search-source-page/', | ||
| WPSearchForm::isSearchFormDrawn() | ||
| ); | ||
| } | ||
|
|
||
| public function testIsSearchFormDrawnReturnsFalseIfRefererDoesNotMatch() | ||
| { | ||
| $_SERVER['REQUEST_URI'] = '/search-source-page/'; | ||
| WPSearchForm::setSearchFormDrawn(); | ||
|
|
||
| $_SERVER['HTTP_REFERER'] = 'https://example.test/another-page/?s=query'; | ||
|
|
||
| $this->assertFalse(WPSearchForm::isSearchFormDrawn()); | ||
| } | ||
|
|
||
| public function testIsSearchFormDrawnReturnsFalseIfNoStoredSearchFormExists() | ||
| { | ||
| $_SERVER['HTTP_REFERER'] = 'https://example.test/search-source-page/?s=query'; | ||
|
|
||
| $this->assertFalse(WPSearchForm::isSearchFormDrawn()); | ||
| } | ||
|
|
||
| public function testSetSearchFormSentRemovesStoredPath() | ||
| { | ||
| $_SERVER['REQUEST_URI'] = '/search-source-page/'; | ||
| WPSearchForm::setSearchFormDrawn(); | ||
|
|
||
| WPSearchForm::setSearchFormSent('/search-source-page/'); | ||
|
|
||
| $this->assertSame(0, AltSessions::get('search_form_ready')); | ||
|
alexandergull marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public function testSetSearchFormSentKeepsOtherStoredPaths() | ||
| { | ||
| AltSessions::set( | ||
| 'search_form_ready', | ||
| array( | ||
| '/first-page/' => 1, | ||
| '/second-page/' => 1, | ||
| ) | ||
| ); | ||
|
|
||
| WPSearchForm::setSearchFormSent('/first-page/'); | ||
|
|
||
| $stored = AltSessions::get('search_form_ready'); | ||
| $stored = is_string($stored) ? json_decode($stored, true) : $stored; | ||
|
|
||
| $this->assertIsArray($stored); | ||
| $this->assertArrayNotHasKey('/first-page/', $stored); | ||
| $this->assertArrayHasKey('/second-page/', $stored); | ||
| $this->assertSame(1, $stored['/second-page/']); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.