Permalink
Browse files

feature(views): allow getting all view locations

Fixes #8947
  • Loading branch information...
mrclay committed Sep 20, 2015
1 parent fdd0884 commit 7a699f3c11dd8668b06323617730dbdfb12a566f
Showing with 32 additions and 0 deletions.
  1. +11 −0 engine/classes/Elgg/ViewsService.php
  2. +10 −0 engine/lib/views.php
  3. +11 −0 engine/tests/phpunit/Elgg/ViewsServiceTest.php
@@ -550,6 +550,17 @@ public function mergeViewsSpec(array $spec) {
}
}
+ /**
+ * Get full paths for all registered views and viewtypes
+ *
+ * @return string[] [default][view_name] => file_path
+ *
+ * @since 2.0
+ */
+ public function getViewLocations() {
+ return $this->locations;
+ }
+
/**
* Get inspector data
*
View
@@ -309,6 +309,16 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) {
return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
}
+/**
+ * Get the file path for all registered views and viewtypes
+ *
+ * @return string[] [viewtype][view_name] => file_path
+ * @since 2.0
+ */
+function elgg_get_view_locations() {
+ return _elgg_services()->views->getViewLocations();
+}
+
/**
* Return a parsed view.
*
@@ -14,6 +14,8 @@ class ViewsServiceTest extends \PHPUnit_Framework_TestCase {
*/
protected $views;
+ protected $viewsDir;
+
public function setUp() {
$this->viewsDir = dirname(dirname(__FILE__)) . "/test_files/views";
@@ -144,6 +146,15 @@ public function testEmitsDeprecationWarningWhenOldViewNameIsReferenced() {
public function testDefaultNormalizeBehavior($canonical, $alias) {
$this->assertEquals($canonical, $this->views->canonicalizeViewName($alias));
}
+
+ public function testCanGetAllViewLocations() {
+ $locs = $this->views->getViewLocations();
+ $this->assertTrue(isset($locs['default']));
+ reset($locs['default']);
+ $key = key($locs['default']);
+ $this->assertTrue(is_string($key));
+ $this->assertTrue(is_file($locs['default'][$key]));
+ }
public function getExampleNormalizedViews() {
return [

0 comments on commit 7a699f3

Please sign in to comment.