mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update test assertions to be more readable
This commit is contained in:
parent
ea8ed5067d
commit
aa7ab0c494
@ -51,38 +51,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
|
|
||||||
$html = $backend->includeInHTML(self::$html_template);
|
$html = $backend->includeInHTML(self::$html_template);
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertContains('http://www.mydomain.com/test.js', $html, 'Load external javascript URL');
|
||||||
(strpos($html, 'http://www.mydomain.com/test.js') !== false),
|
$this->assertContains('https://www.mysecuredomain.com/test.js', $html, 'Load external secure javascript URL');
|
||||||
'Load external javascript URL'
|
$this->assertContains('//scheme-relative.example.com/test.js', $html, 'Load external scheme-relative JS');
|
||||||
);
|
$this->assertContains('http://www.mydomain.com:3000/test.js', $html, 'Load external with port');
|
||||||
$this->assertTrue(
|
$this->assertContains('http://www.mydomain.com/test.css', $html, 'Load external CSS URL');
|
||||||
(strpos($html, 'https://www.mysecuredomain.com/test.js') !== false),
|
$this->assertContains('https://www.mysecuredomain.com/test.css', $html, 'Load external secure CSS URL');
|
||||||
'Load external secure javascript URL'
|
$this->assertContains('//scheme-relative.example.com/test.css', $html, 'Load scheme-relative CSS URL');
|
||||||
);
|
$this->assertContains('http://www.mydomain.com:3000/test.css', $html, 'Load external with port');
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, '//scheme-relative.example.com/test.js') !== false),
|
|
||||||
'Load external scheme-relative javascript URL'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, 'http://www.mydomain.com:3000/test.js') !== false),
|
|
||||||
'Load external with port'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, 'http://www.mydomain.com/test.css') !== false),
|
|
||||||
'Load external CSS URL'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, 'https://www.mysecuredomain.com/test.css') !== false),
|
|
||||||
'Load external secure CSS URL'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, '//scheme-relative.example.com/test.css') !== false),
|
|
||||||
'Load scheme-relative CSS URL'
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
(strpos($html, 'http://www.mydomain.com:3000/test.css') !== false),
|
|
||||||
'Load external with port'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -227,12 +203,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false),
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('c')") !== false),
|
"alert('c')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -276,12 +254,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false),
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('c')") !== false),
|
"alert('c')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -328,12 +308,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false),
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('c')") !== false),
|
"alert('c')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -400,12 +382,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false),
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('c')") !== false),
|
"alert('c')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -469,12 +453,14 @@ class RequirementsTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false),
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertContains(
|
||||||
(strpos(file_get_contents($combinedFilePath), "alert('c')") !== false),
|
"alert('c')",
|
||||||
|
file_get_contents($combinedFilePath),
|
||||||
'combined javascript has correct content'
|
'combined javascript has correct content'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -605,8 +591,9 @@ class RequirementsTest extends SapphireTest
|
|||||||
clearstatcache(); // needed to get accurate file_exists() results
|
clearstatcache(); // needed to get accurate file_exists() results
|
||||||
$backend->includeInHTML(self::$html_template);
|
$backend->includeInHTML(self::$html_template);
|
||||||
$this->assertFileExists($combinedFilePath2);
|
$this->assertFileExists($combinedFilePath2);
|
||||||
$this->assertTrue(
|
$this->assertNotContains(
|
||||||
strpos(file_get_contents($combinedFilePath2), "alert('b')") === false,
|
"alert('b')",
|
||||||
|
file_get_contents($combinedFilePath2),
|
||||||
'blocked uncombined files are not included'
|
'blocked uncombined files are not included'
|
||||||
);
|
);
|
||||||
$backend->unblock($basePath . '/javascript/RequirementsTest_b.js');
|
$backend->unblock($basePath . '/javascript/RequirementsTest_b.js');
|
||||||
@ -1044,16 +1031,18 @@ EOS
|
|||||||
$failedMatches[] = $file;
|
$failedMatches[] = $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertTrue(
|
$this->assertCount(
|
||||||
(count($failedMatches) == 0),
|
0,
|
||||||
|
$failedMatches,
|
||||||
"Failed asserting the $type files '"
|
"Failed asserting the $type files '"
|
||||||
. implode("', '", $failedMatches)
|
. implode("', '", $failedMatches)
|
||||||
. "' have exact matches in the required elements:\n'"
|
. "' have exact matches in the required elements:\n'"
|
||||||
. implode("'\n'", array_keys($includedFiles)) . "'"
|
. implode("'\n'", array_keys($includedFiles)) . "'"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->assertTrue(
|
$this->assertArrayHasKey(
|
||||||
(array_key_exists($files, $includedFiles)),
|
$files,
|
||||||
|
$includedFiles,
|
||||||
"Failed asserting the $type file '$files' has an exact match in the required elements:\n'"
|
"Failed asserting the $type file '$files' has an exact match in the required elements:\n'"
|
||||||
. implode("'\n'", array_keys($includedFiles)) . "'"
|
. implode("'\n'", array_keys($includedFiles)) . "'"
|
||||||
);
|
);
|
||||||
@ -1070,16 +1059,18 @@ EOS
|
|||||||
$failedMatches[] = $file;
|
$failedMatches[] = $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertTrue(
|
$this->assertCount(
|
||||||
(count($failedMatches) == 0),
|
0,
|
||||||
|
$failedMatches,
|
||||||
"Failed asserting the $type files '"
|
"Failed asserting the $type files '"
|
||||||
. implode("', '", $failedMatches)
|
. implode("', '", $failedMatches)
|
||||||
. "' do not have exact matches in the required elements:\n'"
|
. "' do not have exact matches in the required elements:\n'"
|
||||||
. implode("'\n'", array_keys($includedFiles)) . "'"
|
. implode("'\n'", array_keys($includedFiles)) . "'"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->assertFalse(
|
$this->assertArrayNotHasKey(
|
||||||
(array_key_exists($files, $includedFiles)),
|
$files,
|
||||||
|
$includedFiles,
|
||||||
"Failed asserting the $type file '$files' does not have an exact match in the required elements:"
|
"Failed asserting the $type file '$files' does not have an exact match in the required elements:"
|
||||||
. "\n'" . implode("'\n'", array_keys($includedFiles)) . "'"
|
. "\n'" . implode("'\n'", array_keys($includedFiles)) . "'"
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user