/** * Get resources for one or more modules. * * @param string|array $moduleNames * List of module names. * @param string $resType * Type of resource ('js', 'css', 'settings'). * @param string $refType * Type of reference to the resource ('cacheUrl', 'rawUrl', 'path', 'settings'). * @return array * List of URLs or paths. * @throws \CRM_Core_Exception */ public function getResources($moduleNames, $resType, $refType) { $result = array(); $moduleNames = (array) $moduleNames; foreach ($moduleNames as $moduleName) { $module = $this->getModule($moduleName); if (isset($module[$resType])) { foreach ($module[$resType] as $file) { switch ($refType) { case 'path': $result[] = $this->res->getPath($module['ext'], $file); break; case 'rawUrl': $result[] = $this->res->getUrl($module['ext'], $file); break; case 'cacheUrl': $result[] = $this->res->getUrl($module['ext'], $file, TRUE); break; case 'settings': if (!empty($module[$resType])) { $result[$moduleName] = $module[$resType]; } break; default: throw new \CRM_Core_Exception("Unrecognized resource format"); } } } } return $result; }
/** * Modules appear to be well-defined. */ public function testGetModules() { $modules = $this->angular->getModules(); $counts = array('js' => 0, 'css' => 0, 'partials' => 0, 'settings' => 0); foreach ($modules as $module) { $this->assertTrue(is_array($module)); $this->assertTrue(is_string($module['ext'])); if (isset($module['js'])) { $this->assertTrue(is_array($module['js'])); foreach ($module['js'] as $file) { $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file))); $counts['js']++; } } if (isset($module['css'])) { $this->assertTrue(is_array($module['css'])); foreach ($module['css'] as $file) { $this->assertTrue(file_exists($this->res->getPath($module['ext'], $file))); $counts['css']++; } } if (isset($module['partials'])) { $this->assertTrue(is_array($module['partials'])); foreach ((array) $module['partials'] as $basedir) { $this->assertTrue(is_dir($this->res->getPath($module['ext']) . '/' . $basedir)); $counts['partials']++; } } if (isset($module['settings'])) { $this->assertTrue(is_array($module['settings'])); foreach ($module['settings'] as $name => $value) { $counts['settings']++; } } } $this->assertTrue($counts['js'] > 0, 'Expect to find at least one JS file'); $this->assertTrue($counts['css'] > 0, 'Expect to find at least one CSS file'); $this->assertTrue($counts['partials'] > 0, 'Expect to find at least one partial HTML file'); $this->assertTrue($counts['settings'] > 1, 'Expect to find at least one setting'); }