Skip to content
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

Cache clearing is currently broken #15

Merged
merged 19 commits into from Aug 8, 2015
Merged

Conversation

LKS90
Copy link
Contributor

@LKS90 LKS90 commented May 21, 2015

The test isn't sufficient to see this. But it's easy to check when you add some lines to the current test:

CaptchaAdminTestCase.php
Insert after Line 254

// Check for cache results.
$this->drupalLogout();
$this->drupalGet('user/login');
$this->assertFalse($this->drupalGetHeader('x-drupal-cache') == 'HIT', 'Captcha cache has been deleted.');

This pull request adds the test above, fixes the caching by using the appropriate service method. The other pull request was based on a wrong 8.x-1.x branch on my side, sorry about that.

@@ -144,8 +144,7 @@ function captcha_element_process(array $element, FormStateInterface $form_state,
// This needs to be done even if the CAPTCHA will be ommitted later:
// other untrusted users should not get a cached page when
// the current untrusted user can skip the current CAPTCHA.
global $conf;
$conf['cache'] = FALSE;
\Drupal::service('page_cache_kill_switch')->trigger();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hass has a good point. Let's try and move this logic to the separate plugins (test, image and math), all of those should include this I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think the comment there is confusing and incorrect (I don't think some anon users can be trusted and others not?

We also need a max-age 0 in the render array structure, so that it's not getting cached inside a block for example. We probably want to have an explicit tests for a user login block with the math or image plugin, visiting it multiple times should a) never get cached, and b) result in a different output.

@LKS90
Copy link
Contributor Author

LKS90 commented May 21, 2015

Implemented some feedback, test is failing currently because of different behavior of captcha and image_captcha.

@LKS90
Copy link
Contributor Author

LKS90 commented May 21, 2015

The test still fails because image_captcha doesn't behave as expected. Might be a real problem with image_captcha.

@LKS90
Copy link
Contributor Author

LKS90 commented May 22, 2015

Alright, the latest version. Tests are working, caching too, the .travis.yml also works.

Feedback is welcome, nonetheless 😄 .

Edit: The change in image_captcha/src/Controller/CaptchaImageGeneratorController.php was a separate issue which @Berdir found and patched, I added a test for it (drupalGet on the same image path gave an error about db_query being an unknown function).

Changed a comment to indicate which class exactly it was testing

$this->adminUser = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($this->adminUser);
$this->drupalPlaceBlock('user_login_block', array('id' => 'login'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drupalPlaceBlock() uses the API, there is no need to create a user for this.

@LKS90
Copy link
Contributor Author

LKS90 commented May 22, 2015

Alright, should also pass the travis test now. That's what I get for using the online editor 😛


public static $modules = ['block', 'image_captcha'];

function setUp() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docblock for the module list and setUp().

wundo added a commit that referenced this pull request Aug 8, 2015
Cache clearing is currently broken
@wundo wundo merged commit 5c45b47 into chuva-inc:8.x-1.x Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants