Skip to content

Commit

Permalink
MDL-42081 fix file_storage phpunit tests following adding new stamp f…
Browse files Browse the repository at this point in the history
…iles on fresh install
  • Loading branch information
mouneyrac committed Nov 11, 2013
1 parent 68bcc3f commit 316283c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/filestorage/tests/file_storage_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function test_create_file_from_string() {

$this->resetAfterTest(true);

$this->assertEquals(0, $DB->count_records('files', array()));
// Number of files installed in the database on a fresh Moodle site.
$installedfiles = $DB->count_records('files', array());

$content = 'abcd';
$syscontext = context_system::instance();
Expand Down Expand Up @@ -68,7 +69,7 @@ public function test_create_file_from_string() {
$this->assertFileExists($location);

// Verify the dir placeholder files are created.
$this->assertEquals(3, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 3, $DB->count_records('files', array()));
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>sha1('/'.$filerecord['contextid'].'/'.$filerecord['component'].'/'.$filerecord['filearea'].'/'.$filerecord['itemid'].'/.'))));
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>sha1('/'.$filerecord['contextid'].'/'.$filerecord['component'].'/'.$filerecord['filearea'].'/'.$filerecord['itemid'].$filerecord['filepath'].'.'))));

Expand All @@ -83,7 +84,7 @@ public function test_create_file_from_string() {
$this->assertSame($file->get_contenthash(), $file2->get_contenthash());
$this->assertFileExists($location);

$this->assertEquals(4, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 4, $DB->count_records('files', array()));

// Test that borked content file is recreated.

Expand All @@ -98,7 +99,7 @@ public function test_create_file_from_string() {
$this->assertSame($content, file_get_contents($location));
$this->assertDebuggingCalled();

$this->assertEquals(5, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 5, $DB->count_records('files', array()));
}

/**
Expand All @@ -109,8 +110,8 @@ public function test_create_file_from_pathname() {

$this->resetAfterTest(true);

$filecount = $DB->count_records('files', array());
$this->assertEquals(0, $filecount);
// Number of files installed in the database on a fresh Moodle site.
$installedfiles = $DB->count_records('files', array());

$filepath = $CFG->dirroot.'/lib/filestorage/tests/fixtures/testimage.jpg';
$syscontext = context_system::instance();
Expand All @@ -137,7 +138,7 @@ public function test_create_file_from_pathname() {
$this->assertFileExists($location);

// Verify the dir placeholder files are created.
$this->assertEquals(3, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 3, $DB->count_records('files', array()));
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>sha1('/'.$filerecord['contextid'].'/'.$filerecord['component'].'/'.$filerecord['filearea'].'/'.$filerecord['itemid'].'/.'))));
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>sha1('/'.$filerecord['contextid'].'/'.$filerecord['component'].'/'.$filerecord['filearea'].'/'.$filerecord['itemid'].$filerecord['filepath'].'.'))));

Expand All @@ -152,7 +153,7 @@ public function test_create_file_from_pathname() {
$this->assertSame($file->get_contenthash(), $file2->get_contenthash());
$this->assertFileExists($location);

$this->assertEquals(4, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 4, $DB->count_records('files', array()));

// Test that borked content file is recreated.

Expand All @@ -167,7 +168,7 @@ public function test_create_file_from_pathname() {
$this->assertSame(file_get_contents($filepath), file_get_contents($location));
$this->assertDebuggingCalled();

$this->assertEquals(5, $DB->count_records('files', array()));
$this->assertEquals($installedfiles + 5, $DB->count_records('files', array()));

// Test invalid file creation.

Expand Down

0 comments on commit 316283c

Please sign in to comment.