Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I'm writing context tests for Google Analytics module and I issue a context_delete()
, but all assertNoRaw()
are failing as the code still exists in the page.
context_delete()
has a bug as the condition is never true
. Same may be true for context_save(). I have no idea what $context->export_type
is.
if (isset($context->name) && ($context->export_type & EXPORT_IN_DATABASE)) {
Maybe this should be more as nothing else makes sense to me:
if (isset($context->name) && ($context->export_type == EXPORT_IN_DATABASE)) {
Repro case:
$this->drupalGet('');
$this->assertRaw('ga("set", "expId", "Qp0gahJ3RAO3DJ18b0XoUQ");');
$this->assertRaw('ga("set", "campaignName", "(direct)");');
$this->assertRaw('ga("set", "campaignSource", "(direct)");');
// Cleanup
$deleted = context_delete($context);
$this->assertTrue($deleted, 'Context "' . $context->name . '" has been deleted.');
$this->drupalGet('');
$this->assertNoRaw('ga("set", "expId", "Qp0gahJ3RAO3DJ18b0XoUQ");');
$this->assertNoRaw('ga("set", "campaignName", "(direct)");');
$this->assertNoRaw('ga("set", "campaignSource", "(direct)");');
Proposed resolution
Remaining tasks
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#6 | Issue-2355101-Context-still-active-after-contextdele.patch | 5.84 KB | hass |
Comments
Comment #1
hass CreditAttribution: hass commentedHere is a patch that proves this bug.
Comment #2
hass CreditAttribution: hass commentedComment #3
hass CreditAttribution: hass commentedComment #4
hass CreditAttribution: hass commentedThat
context_save()
function is not logic to me as it always saves to the database, but does not set the$context->export_type = EXPORT_IN_DATABASE
on newly added contexts. context_load() also does not set$context->export_type = EXPORT_IN_DATABASE
.I guess it need to be changed to:
Comment #5
hass CreditAttribution: hass commentedComment #6
hass CreditAttribution: hass commentedAs I do not understand the logic I'm changing it here.
Comment #7
hass CreditAttribution: hass commentedComment #8
milos.kroulik CreditAttribution: milos.kroulik commentedI doubt this is the correct solution, since
$context->export_type
could have value 3 (if DB overrides code), which has no corresponding constant value. This is bitwise operator (https://secure.php.net/manual/en/language.operators.bitwise.php) and seems to work fine.