public function PhpStorageTestBase::assertCRUD in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php \Drupal\Tests\Component\PhpStorage\PhpStorageTestBase::assertCRUD()
Assert that a PHP storage's load/save/delete operations work.
2 calls to PhpStorageTestBase::assertCRUD()
- FileStorageTest::testCRUD in core/
tests/ Drupal/ Tests/ Component/ PhpStorage/ FileStorageTest.php - Tests basic load/save/delete operations.
- MTimeProtectedFileStorageBase::testCRUD in core/
tests/ Drupal/ Tests/ Component/ PhpStorage/ MTimeProtectedFileStorageBase.php - Tests basic load/save/delete operations.
File
- core/
tests/ Drupal/ Tests/ Component/ PhpStorage/ PhpStorageTestBase.php, line 38 - Contains \Drupal\Tests\Component\PhpStorage\PhpStorageTestBase.
Class
- PhpStorageTestBase
- Base test for PHP storages.
Namespace
Drupal\Tests\Component\PhpStorageCode
public function assertCRUD($php) {
$name = $this
->randomMachineName() . '/' . $this
->randomMachineName() . '.php';
// Find a global that doesn't exist.
do {
$random = mt_rand(10000, 100000);
} while (isset($GLOBALS[$random]));
// Write out a PHP file and ensure it's successfully loaded.
$code = "<?php\n\$GLOBALS[{$random}] = TRUE;";
$success = $php
->save($name, $code);
$this
->assertTrue($success, 'Saved php file');
$php
->load($name);
$this
->assertTrue($GLOBALS[$random], 'File saved correctly with correct value');
// Run additional asserts.
$this
->additionalAssertCRUD($php, $name);
// If the file was successfully loaded, it must also exist, but ensure the
// exists() method returns that correctly.
$this
->assertTrue($php
->exists($name), 'Exists works correctly');
// Delete the file, and then ensure exists() returns FALSE.
$this
->assertTrue($php
->delete($name), 'Delete succeeded');
$this
->assertFalse($php
->exists($name), 'Delete deleted file');
// Ensure delete() can be called on a non-existing file. It should return
// FALSE, but not trigger errors.
$this
->assertFalse($php
->delete($name), 'Delete fails on missing file');
unset($GLOBALS[$random]);
}