From f89a409378e58b4ba27f00a61e299245c6659a6f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 17 Jan 2020 18:10:22 -0800 Subject: [PATCH] Add E2E_Core_PathUrlTest to ensure that various path/URL lookups work This will allow E2E matrix to send a signal about whether the default configurations produce valid URLs. --- tests/phpunit/E2E/Core/PathUrlTest.php | 91 ++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/phpunit/E2E/Core/PathUrlTest.php diff --git a/tests/phpunit/E2E/Core/PathUrlTest.php b/tests/phpunit/E2E/Core/PathUrlTest.php new file mode 100644 index 0000000000..83b0b23341 --- /dev/null +++ b/tests/phpunit/E2E/Core/PathUrlTest.php @@ -0,0 +1,91 @@ +assertUrlContentRegex(';class="CRM_Mailing_Form_Subscribe";', + \CRM_Utils_System::url('civicrm/mailing/subscribe', 'reset=1', TRUE, NULL, FALSE)); + } + + /** + * `Civi::paths()->getUrl()` should generate working URLs. + */ + public function testPaths_getUrl() { + $p = \Civi::paths(); + + $this->assertUrlContentRegex(';MIT-LICENSE.txt;', + $p->getUrl('[civicrm.packages]/jquery/plugins/jquery.timeentry.js', 'absolute')); + $this->assertUrlContentRegex(';https://civicrm.org/licensing;', + $p->getUrl('[civicrm.root]/js/Common.js', 'absolute')); + $this->assertUrlContentRegex(';Copyright jQuery Foundation;', + $p->getUrl('[civicrm.bower]/jquery/dist/jquery.js', 'absolute')); + } + + /** + * `Civi::paths()->getPath()` should generate working paths. + */ + public function testPaths_getPath() { + $p = \Civi::paths(); + + $this->assertFileContentRegex(';MIT-LICENSE.txt;', + $p->getPath('[civicrm.packages]/jquery/plugins/jquery.timeentry.js')); + $this->assertFileContentRegex(';https://civicrm.org/licensing;', + $p->getPath('[civicrm.root]/js/Common.js')); + $this->assertFileContentRegex(';Copyright jQuery Foundation;', + $p->getPath('[civicrm.bower]/jquery/dist/jquery.js')); + } + + /** + * `Civi::paths()->getVariable()` should generate working paths+URLs. + */ + public function testPaths_getVariable() { + $pathAndUrl = ['cms.root', 'civicrm.root', 'civicrm.packages', 'civicrm.files']; + $pathOnly = ['civicrm.private', 'civicrm.log', 'civicrm.compile']; + $urlOnly = []; + + foreach (array_merge($pathOnly, $pathAndUrl) as $var) { + $path = \Civi::paths()->getVariable($var, 'path'); + $this->assertTrue(file_exists($path) && is_dir($path), "The path for $var should be a valid directory."); + } + + foreach (array_merge($urlOnly, $pathAndUrl) as $var) { + $url = \Civi::paths()->getVariable($var, 'url'); + $this->assertRegExp(';^https?:;', $url, "The URL for $var should resolve a URL."); + } + } + + /** + * @param string $expectContentRegex + * @param string $url + */ + private function assertUrlContentRegex($expectContentRegex, $url) { + $this->assertRegexp(';^https?:;', $url, "The URL ($url) should be absolute."); + $content = file_get_contents($url); + $this->assertRegexp($expectContentRegex, $content); + } + + /** + * @param string $expectContentRegex + * @param string $file + */ + private function assertFileContentRegex($expectContentRegex, $file) { + $this->assertFileExists($file); + $content = file_get_contents($file); + $this->assertRegexp($expectContentRegex, $content); + } + +} -- 2.25.1