Skip to content

Commit

Permalink
Added test for PathFinderContrib::find()
Browse files Browse the repository at this point in the history
  • Loading branch information
penyaskito committed Jun 15, 2015
1 parent 0140347 commit 62b6aef
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Discovery/PathFinderContrib.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function find($seed) {
// Check if the current directory corresponds to the contrib we are
// looking for.
if ($this->isWantedContrib($dir)) {
return $this->cleanDirPath($dir->getPathName()) . $this->path;
return $this->cleanDirPath($dir->getPathName());
}
}
throw new ClassLoaderException(sprintf('Drupal module "%s" could not be found in the Drupal tree that contains: %s.', $this->moduleName, $seed));
Expand Down
8 changes: 4 additions & 4 deletions src/Discovery/PathFinderCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function find($seed) {
// up and up and up until we reach the Drupal root.
do {
if ($this->isDrupalRoot($directory)) {
return $this->cleanDirPath($directory->getPathName()) . $this->path;
return dirname(realpath($this->cleanDirPath($directory->getPathName())));
}
}
while ($directory = $this->getParentDirectory($directory));
Expand Down Expand Up @@ -82,13 +82,13 @@ protected function getParentDirectory(\DirectoryIterator $directory) {

// Get the parent directory and return a DirectoryIterator.
$path_info = pathinfo($path_name);
if (!empty($path_info['dirname'])) {
if (!empty($path_info['dirname']) && $path_info['dirname'] !== '/') {
try {
return new \DirectoryIterator($path_info['dirname']);
return new \DirectoryIterator(dirname($path_info['dirname']));
}
catch (\UnexpectedValueException $e) {}
}
throw new ClassLoaderException(sprintf('Could not find the parent directory of "%s".', $path_name));
return NULL;
}

}
2 changes: 2 additions & 0 deletions tests/data/docroot/COPYRIGHT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
All Drupal code is Copyright

Empty file.
10 changes: 10 additions & 0 deletions tests/src/Discovery/PathFinderContribTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ public function testConstructor() {
$this->assertEquals('mymodule', $value);
}

/**
* Tests that find() works properly.
*
* @covers ::find()
*/
public function testFind() {
$pathFinder = new PathFinderContrib(['.', 'testmodule']);
$path = $pathFinder->find('data/docroot/');
$this->assertEquals(realpath('data/docroot/sites/all/modules'), $path);
}
}

0 comments on commit 62b6aef

Please sign in to comment.