mirror of
https://github.com/flarum/framework.git
synced 2025-02-09 00:47:57 +08:00
Using a different setting key now, so that it won't break tests whenever you re-run them once smtp is set.
Fixed, badly, the test to create users etc caused by the prepareDatabase flushing all settings by default.
This commit is contained in:
parent
bfd3a667dd
commit
ce42b5e035
|
@ -82,12 +82,26 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
// First, truncate all referenced tables so that they are empty.
|
// First, truncate all referenced tables so that they are empty.
|
||||||
foreach (array_keys($tableData) as $table) {
|
foreach (array_keys($tableData) as $table) {
|
||||||
|
if ($table !== 'settings') {
|
||||||
$this->database()->table($table)->truncate();
|
$this->database()->table($table)->truncate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Then, insert all rows required for this test case.
|
// Then, insert all rows required for this test case.
|
||||||
foreach ($tableData as $table => $rows) {
|
foreach ($tableData as $table => $rows) {
|
||||||
$this->database()->table($table)->insert($rows);
|
foreach ($rows as $row) {
|
||||||
|
if ($table === 'settings') {
|
||||||
|
$this->database()->table($table)->updateOrInsert(
|
||||||
|
['key' => $row['key']],
|
||||||
|
$row
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->database()->table($table)->updateOrInsert(
|
||||||
|
isset($row['id']) ? ['id' => $row['id']] : $row,
|
||||||
|
$row
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// And finally, turn on foreign key checks again.
|
// And finally, turn on foreign key checks again.
|
||||||
|
|
|
@ -40,6 +40,9 @@ class CreateUserControllerTest extends ApiControllerTestCase
|
||||||
'group_user' => [
|
'group_user' => [
|
||||||
['user_id' => 1, 'group_id' => 1],
|
['user_id' => 1, 'group_id' => 1],
|
||||||
],
|
],
|
||||||
|
'settings' => [
|
||||||
|
['key' => 'mail_driver', 'value' => 'log']
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
namespace Flarum\Tests\integration\api\csrf_protection;
|
namespace Flarum\Tests\integration\api\csrf_protection;
|
||||||
|
|
||||||
use Flarum\Foundation\Application;
|
|
||||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||||
use Flarum\Tests\integration\TestCase;
|
use Flarum\Tests\integration\TestCase;
|
||||||
|
|
||||||
|
@ -40,8 +39,7 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
['user_id' => 1, 'key' => 'superadmin'],
|
['user_id' => 1, 'key' => 'superadmin'],
|
||||||
],
|
],
|
||||||
'settings' => [
|
'settings' => [
|
||||||
['key' => 'mail_driver', 'value' => 'mail'],
|
['key' => 'csrf_test', 'value' => 1],
|
||||||
['key' => 'version', 'value' => Application::VERSION],
|
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +63,7 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
'POST', '/api/settings',
|
'POST', '/api/settings',
|
||||||
[
|
[
|
||||||
'cookiesFrom' => $auth,
|
'cookiesFrom' => $auth,
|
||||||
'json' => ['mail_driver' => 'log'],
|
'json' => ['csrf_test' => 2],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -111,7 +109,7 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
'POST', '/api/settings',
|
'POST', '/api/settings',
|
||||||
[
|
[
|
||||||
'cookiesFrom' => $auth,
|
'cookiesFrom' => $auth,
|
||||||
'json' => ['mail_driver' => 'log'],
|
'json' => ['csrf_test' => 2],
|
||||||
]
|
]
|
||||||
)->withHeader('X-CSRF-Token', $token)
|
)->withHeader('X-CSRF-Token', $token)
|
||||||
);
|
);
|
||||||
|
@ -121,8 +119,8 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
|
|
||||||
// Was the setting actually changed in the database?
|
// Was the setting actually changed in the database?
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'log',
|
2,
|
||||||
$this->database()->table('settings')->where('key', 'mail_driver')->first()->value
|
$this->database()->table('settings')->where('key', 'csrf_test')->first()->value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +152,7 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
'POST', '/api/settings',
|
'POST', '/api/settings',
|
||||||
[
|
[
|
||||||
'cookiesFrom' => $auth,
|
'cookiesFrom' => $auth,
|
||||||
'json' => ['mail_driver' => 'log', 'csrfToken' => $token],
|
'json' => ['csrf_test' => 2, 'csrfToken' => $token],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -164,8 +162,8 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
|
|
||||||
// Was the setting actually changed in the database?
|
// Was the setting actually changed in the database?
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'log',
|
2,
|
||||||
$this->database()->table('settings')->where('key', 'mail_driver')->first()->value
|
$this->database()->table('settings')->where('key', 'csrf_test')->first()->value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +176,7 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
$this->request(
|
$this->request(
|
||||||
'POST', '/api/settings',
|
'POST', '/api/settings',
|
||||||
[
|
[
|
||||||
'json' => ['mail_driver' => 'log'],
|
'json' => ['csrf_test' => 2],
|
||||||
]
|
]
|
||||||
)->withHeader('Authorization', 'Token superadmin')
|
)->withHeader('Authorization', 'Token superadmin')
|
||||||
);
|
);
|
||||||
|
@ -188,8 +186,8 @@ class RequireCsrfTokenTest extends TestCase
|
||||||
|
|
||||||
// Was the setting actually changed in the database?
|
// Was the setting actually changed in the database?
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'log',
|
2,
|
||||||
$this->database()->table('settings')->where('key', 'mail_driver')->first()->value
|
$this->database()->table('settings')->where('key', 'csrf_test')->first()->value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user