diff --git a/core/lib/Drupal/Core/Asset/AssetLibraryRepository.php b/core/lib/Drupal/Core/Asset/AssetLibraryRepository.php index 95a2cb3..5c6b3aa 100644 --- a/core/lib/Drupal/Core/Asset/AssetLibraryRepository.php +++ b/core/lib/Drupal/Core/Asset/AssetLibraryRepository.php @@ -27,17 +27,17 @@ class AssetLibraryRepository { * * @var */ - protected $collector; + protected $factory; - function __construct(AssetLibraryFactory $collector) { - $this->collector = $collector; + function __construct(AssetLibraryFactory $factory) { + $this->factory = $factory; } /** * Gets a library by its composite key. * * @param string $key - * The key of the library, as a string of the form "$module:$name". + * The key of the library, as a string of the form "$module/$name". * * @return \Drupal\Core\Asset\Collection\AssetLibrary * The requested library. @@ -50,7 +50,7 @@ public function get($key) { return $this->libraries[$key]; } - if ($library = $this->collector->getLibrary($key)) { + if ($library = $this->factory->getLibrary($key)) { $this->set($key, $library); } else { @@ -61,10 +61,10 @@ public function get($key) { } public function set($key, AssetLibrary $library) { - if (preg_match('/[^0-9A-Za-z:_-]/', $key)) { + if (preg_match('/[^0-9A-Za-z\/_-]/', $key)) { throw new \InvalidArgumentException(sprintf('The name "%s" is invalid.', $key)); } - elseif (substr_count($key, ':') !== 1) { + elseif (substr_count($key, '/') !== 1) { throw new \InvalidArgumentException(sprintf('Invalid key "%s" provided; asset libraries must have exactly one colon in their key, separating the owning module from the library name.', $key)); } @@ -79,7 +79,7 @@ public function set($key, AssetLibrary $library) { * created already. * * @param string $key - * The key of the library, as a string of the form "$module:$name". + * The key of the library, as a string of the form "$module/$name". * * @return bool * TRUE if the library has been built, FALSE otherwise. diff --git a/core/lib/Drupal/Core/Asset/Factory/AssetLibraryFactory.php b/core/lib/Drupal/Core/Asset/Factory/AssetLibraryFactory.php index 41bd488..f8ba302 100644 --- a/core/lib/Drupal/Core/Asset/Factory/AssetLibraryFactory.php +++ b/core/lib/Drupal/Core/Asset/Factory/AssetLibraryFactory.php @@ -6,8 +6,6 @@ namespace Drupal\Core\Asset\Factory; -use Drupal\Component\Utility\Crypt; -use \Drupal\Core\Asset\AssetLibraryRepository; use Drupal\Core\Asset\Factory\AssetCollector; use Drupal\Core\Asset\Collection\AssetLibrary; use Drupal\Core\Asset\Metadata\DefaultAssetMetadataFactory; @@ -74,7 +72,7 @@ public function __construct(ModuleHandlerInterface $moduleHandler, AssetCollecto * data. */ public function getLibrary($key) { - list($module, $name) = preg_split('/:/', $key); + list($module, $name) = preg_split('/\//', $key); if (!$this->moduleHandler->implementsHook($module, 'library_info')) { // Module doesn't implement hook_library_info(), a library can't exist. diff --git a/core/tests/Drupal/Tests/Core/Asset/AssetLibraryRepositoryTest.php b/core/tests/Drupal/Tests/Core/Asset/AssetLibraryRepositoryTest.php index 599878f..5642bc8 100644 --- a/core/tests/Drupal/Tests/Core/Asset/AssetLibraryRepositoryTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/AssetLibraryRepositoryTest.php @@ -56,7 +56,7 @@ public function createAssetLibraryRepository() { ->with('library_info') ->will($this->returnValue(array('stub1', 'stub2'))); - $factory = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetLibraryFactory', $module_handler); + $factory = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetLibraryFactory', array(), array($module_handler)); return new AssetLibraryRepository($factory); } @@ -66,7 +66,7 @@ public function createAssetLibraryRepository() { public function testSet() { $repository = $this->createAssetLibraryRepository(); $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $repository->set('foo:bar', $library); + $repository->set('foo/bar', $library); $this->assertAttributeContains($library, 'libraries', $repository); } @@ -86,11 +86,11 @@ public function testSetNoColon() { * @covers ::set * @expectedException \InvalidArgumentException */ - public function testSetTooManyColons() { + public function testSetTooManySlashes() { $repository = $this->createAssetLibraryRepository(); $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $repository->set('foo::bar', $library); + $repository->set('foo//bar', $library); } /** @@ -101,7 +101,7 @@ public function testSetInvalidKeyChars() { $repository = $this->createAssetLibraryRepository(); $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $repository->set("$∫≤ˆ\"'\n\t\r", $library); + $repository->set("\$∫≤:ˆ\"'\n\t\r", $library); } /** @@ -112,10 +112,10 @@ public function testHas() { $repository = $this->createAssetLibraryRepository(); $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $this->assertFalse($repository->has('foo:bar')); + $this->assertFalse($repository->has('foo/bar')); - $repository->set('foo:bar', $library); - $this->assertTrue($repository->has('foo:bar')); + $repository->set('foo/bar', $library); + $this->assertTrue($repository->has('foo/bar')); } /** @@ -126,10 +126,10 @@ public function testGetNames() { $repository = $this->createAssetLibraryRepository(); $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $repository->set('foo:bar', $library); - $repository->set('baz:bing', $library); + $repository->set('foo/bar', $library); + $repository->set('baz/bing', $library); - $this->assertEquals(array('foo:bar', 'baz:bing'), $repository->getNames()); + $this->assertEquals(array('foo/bar', 'baz/bing'), $repository->getNames()); } /** @@ -138,14 +138,14 @@ public function testGetNames() { */ public function testGet() { $library = $this->getMock('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary'); - $factory = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetLibraryFactory'); + $factory = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetLibraryFactory', array(), array(), '', FALSE); $factory->expects($this->once()) ->method('getLibrary') - ->with($this->equalTo('foo:bar')) + ->with($this->equalTo('foo/bar')) ->will($this->returnValue($library)); $repository = new AssetLibraryRepository($factory); - $this->assertSame($library, $repository->get('foo:bar')); + $this->assertSame($library, $repository->get('foo/bar')); } } diff --git a/core/tests/Drupal/Tests/Core/Asset/Factory/AssetLibraryFactoryTest.php b/core/tests/Drupal/Tests/Core/Asset/Factory/AssetLibraryFactoryTest.php index cd9443c..30aa78a 100644 --- a/core/tests/Drupal/Tests/Core/Asset/Factory/AssetLibraryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/Factory/AssetLibraryFactoryTest.php @@ -71,9 +71,9 @@ public function testGetLibrary() { $collector = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetCollector'); $factory = new AssetLibraryFactory($module_handler, $collector); - $this->assertFalse($factory->getLibrary('stub1:foo')); + $this->assertFalse($factory->getLibrary('stub1/foo')); - $lib1 = $factory->getLibrary('stub1:solo-nodeps-js'); + $lib1 = $factory->getLibrary('stub1/solo-nodeps-js'); $this->assertInstanceOf('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary', $lib1); $this->assertEquals('solo-nodeps-js', $lib1->getTitle()); @@ -81,7 +81,7 @@ public function testGetLibrary() { $this->assertEquals('http://foo.bar', $lib1->getWebsite()); $this->assertTrue($lib1->isFrozen()); - $lib2 = $factory->getLibrary('stub1:solo-onedep-same'); + $lib2 = $factory->getLibrary('stub1/solo-onedep-same'); $this->assertInstanceOf('\\Drupal\\Core\\Asset\\Collection\\AssetLibrary', $lib2); $this->assertEquals(array(array('stub1', 'solo-nodeps-js')), $lib2->getDependencyInfo()); @@ -100,7 +100,7 @@ public function testGetLibraryModuleDoesNotImplementHook() { $collector = $this->getMock('\\Drupal\\Core\\Asset\\Factory\\AssetCollector'); $factory = new AssetLibraryFactory($module_handler, $collector); - $this->assertFalse($factory->getLibrary('foo:bar')); + $this->assertFalse($factory->getLibrary('foo/bar')); } }