This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Laravel;
use Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider;
use Illuminate\Foundation\Application;
/**
* SlugifyServiceProviderTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @author Colin Viebrock
* @copyright 2012-2014 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class SlugifyProviderTest extends \PHPUnit_Framework_TestCase
{
/** @var Application */
private $app;
/** @var SlugifyServiceProvider */
private $provider;
protected function setUp()
{
$this->app = new Application();
$this->provider = new SlugifyServiceProvider($this->app);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider::register()
*/
public function registerRegistersTheServiceProvider()
{
$this->provider->register();
// the service provider is deferred, so this forces it to load
$this->app->make('slugify');
$this->assertArrayHasKey('slugify', $this->app);
$this->assertInstanceOf('Cocur\Slugify\Slugify', $this->app['slugify']);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider::provides()
*/
public function containsReturnsTheNameOfThProvider()
{
$this->assertContains('slugify', $this->provider->provides());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\Latte;
use Cocur\Slugify\Bridge\Latte\SlugifyHelper;
use Mockery as m;
/**
* SlugifyHelperTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Lukáš Unger <looky.msc@gmail.com>
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class SlugifyHelperTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->slugify = m::mock('Cocur\Slugify\SlugifyInterface');
$this->helper = new SlugifyHelper($this->slugify);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Latte\SlugifyHelper::slugify()
*/
public function slugify()
{
$this->slugify->shouldReceive('slugify')->with('hällo wörld', '_')->once()->andReturn('haello_woerld');
$this->assertEquals('haello_woerld', $this->helper->slugify('hällo wörld', '_'));
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\League;
use Cocur\Slugify\Bridge\League\SlugifyServiceProvider;
use Cocur\Slugify\RuleProvider\DefaultRuleProvider;
use Cocur\Slugify\RuleProvider\RuleProviderInterface;
use Cocur\Slugify\SlugifyInterface;
use League\Container\Container;
use Mockery as m;
class SlugifyServiceProviderTest extends \PHPUnit_Framework_TestCase
{
public function testProvidesSlugify()
{
$container = new Container();
$container->addServiceProvider(new SlugifyServiceProvider());
$slugify = $container->get(SlugifyInterface::class);
$this->assertInstanceOf(SlugifyInterface::class, $slugify);
$this->assertAttributeInstanceOf(DefaultRuleProvider::class, 'provider', $slugify);
}
public function testProvidesSlugifyAsSharedService()
{
$container = new Container();
$container->addServiceProvider(new SlugifyServiceProvider());
$slugify = $container->get(SlugifyInterface::class);
$this->assertSame($slugify, $container->get(SlugifyInterface::class));
}
public function testProvidesSlugifyUsingSharedConfigurationOptions()
{
$container = new Container();
$options = [
'lowercase' => false,
];
$container->share('config.slugify.options', $options);
$container->addServiceProvider(new SlugifyServiceProvider());
/* @var SlugifyInterface $slugify */
$slugify = $container->get(SlugifyInterface::class);
$slug = 'Foo-Bar-Baz';
$this->assertSame($slug, $slugify->slugify($slug));
}
public function testProvidesSlugifyUsingSharedProvider()
{
$container = new Container();
$ruleProvider = $this->getRuleProviderMock();
$container->share(RuleProviderInterface::class, $ruleProvider);
$container->addServiceProvider(new SlugifyServiceProvider());
$slugify = $container->get(SlugifyInterface::class);
$this->assertAttributeSame($ruleProvider, 'provider', $slugify);
}
/**
* @return m\Mock|RuleProviderInterface
*/
private function getRuleProviderMock()
{
$ruleProvider = m::mock(RuleProviderInterface::class);
$ruleProvider
->shouldReceive('getRules')
->withAnyArgs()
->andReturn([])
;
return $ruleProvider;
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\Nette;
use Cocur\Slugify\Bridge\Nette\SlugifyExtension;
use Mockery as m;
/**
* SlugifyExtensionTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Lukáš Unger <looky.msc@gmail.com>
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class SlugifyExtensionTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->extension = new SlugifyExtension();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Nette\SlugifyExtension::loadConfiguration()
*/
public function loadConfiguration()
{
$slugify = m::mock('Nette\DI\ServiceDefinition');
$slugify
->shouldReceive('setClass')
->with('Cocur\Slugify\SlugifyInterface')
->once()
->andReturn($slugify);
$slugify
->shouldReceive('setFactory')
->with('Cocur\Slugify\Slugify')
->once()
->andReturn($slugify);
$helper = m::mock('Nette\DI\ServiceDefinition');
$helper
->shouldReceive('setClass')
->with('Cocur\Slugify\Bridge\Latte\SlugifyHelper')
->once()
->andReturn($helper);
$helper
->shouldReceive('setAutowired')
->with(false)
->once()
->andReturn($helper);
$builder = m::mock('Nette\DI\ContainerBuilder');
$builder
->shouldReceive('addDefinition')
->with('slugify.slugify')
->once()
->andReturn($slugify);
$builder
->shouldReceive('addDefinition')
->with('slugify.helper')
->once()
->andReturn($helper);
$compiler = m::mock('Nette\DI\Compiler');
$compiler
->shouldReceive('getContainerBuilder')
->once()
->andReturn($builder);
$this->extension->setCompiler($compiler, 'slugify');
$this->extension->loadConfiguration();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Nette\SlugifyExtension::beforeCompile()
*/
public function beforeCompile()
{
$latteFactory = m::mock('Nette\DI\ServiceDefinition');
$latteFactory
->shouldReceive('addSetup')
->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
->once()
->andReturn($latteFactory);
$latte = m::mock('Nette\DI\ServiceDefinition');
$latte
->shouldReceive('addSetup')
->with('addFilter', ['slugify', ['@slugify.helper', 'slugify']])
->once()
->andReturn($latte);
$builder = m::mock('Nette\DI\ContainerBuilder');
$builder
->shouldReceive('getByType')
->with('Nette\Bridges\ApplicationLatte\ILatteFactory')
->once()
->andReturn('latte.latteFactory');
$builder
->shouldReceive('hasDefinition')
->with('latte.latteFactory')
->once()
->andReturn(true);
$builder
->shouldReceive('getDefinition')
->with('latte.latteFactory')
->once()
->andReturn($latteFactory);
$builder
->shouldReceive('hasDefinition')
->with('nette.latte')
->once()
->andReturn(true);
$builder
->shouldReceive('getDefinition')
->with('nette.latte')
->once()
->andReturn($latte);
$compiler = m::mock('Nette\DI\Compiler');
$compiler
->shouldReceive('getContainerBuilder')
->once()
->andReturn($builder);
$this->extension->setCompiler($compiler, 'slugify');
$this->extension->beforeCompile();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Plum;
use Cocur\Slugify\Bridge\Plum\SlugifyConverter;
use Mockery;
use PHPUnit_Framework_TestCase;
/**
* SlugifyConverterTest
*
* @package Cocur\Slugify\Bridge\Plum
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2015 Florian Eckerstorfer
* @group unit
*/
class SlugifyConverterTest extends PHPUnit_Framework_TestCase
{
/**
* @test
* @covers Cocur\Slugify\Bridge\Plum\SlugifyConverter::__construct()
* @covers Cocur\Slugify\Bridge\Plum\SlugifyConverter::convert()
*/
public function convertSlugifiesString()
{
$slugify = Mockery::mock('Cocur\Slugify\SlugifyInterface');
$slugify->shouldReceive('slugify')->with('Hello World')->once()->andReturn('hello_world');
$converter = new SlugifyConverter($slugify);
$this->assertSame('hello_world', $converter->convert('Hello World'));
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Plum\SlugifyConverter::__construct()
* @covers Cocur\Slugify\Bridge\Plum\SlugifyConverter::convert()
*/
public function constructorCreatesSlugifyIfNoneIsProvided()
{
$converter = new SlugifyConverter();
$this->assertSame('hello-world', $converter->convert('Hello World'));
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Silex;
use Cocur\Slugify\Bridge\Silex\SlugifyServiceProvider;
use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
/**
* SlugifyServiceProviderTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2014 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class SlugifySilexProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
* @covers Cocur\Slugify\Bridge\Silex\SlugifyServiceProvider
*/
public function register()
{
// it seems like Application is not mockable.
$app = new Application();
$app->register(new SlugifyServiceProvider());
$app->boot();
$this->assertArrayHasKey('slugify', $app);
$this->assertArrayHasKey('slugify.provider', $app);
$this->assertArrayHasKey('slugify.options', $app);
$this->assertInstanceOf('Cocur\Slugify\Slugify', $app['slugify']);
}
/**
* @test
*/
public function registerWithTwig()
{
$app = new Application();
$app->register(new TwigServiceProvider());
$app->register(new SlugifyServiceProvider());
$this->assertTrue($app['twig']->hasExtension(SlugifyExtension::class));
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Symfony;
use Cocur\Slugify\Bridge\Symfony\CocurSlugifyBundle;
use Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension;
/**
* CocurSlugifyBundleTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2014 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class CocurSlugifyBundleTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers Cocur\Slugify\Bridge\Symfony\CocurSlugifyBundle::getContainerExtension()
*/
public function testGetContainerExtension()
{
$bundle = new CocurSlugifyBundle();
static::assertInstanceOf(CocurSlugifyExtension::class, $bundle->getContainerExtension());
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Symfony;
use Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension;
use Mockery as m;
/**
* CocurSlugifyExtensionTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2014 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class CocurSlugifyExtensionTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->extension = new CocurSlugifyExtension();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension::load()
*/
public function load()
{
$twigDefinition = m::mock('Symfony\Component\DependencyInjection\Definition');
$twigDefinition
->shouldReceive('addTag')
->with('twig.extension')
->once()
->andReturn($twigDefinition);
$twigDefinition
->shouldReceive('setPublic')
->with(false)
->once();
$container = m::mock('Symfony\Component\DependencyInjection\ContainerBuilder');
$container
->shouldReceive('setDefinition')
->with('cocur_slugify', m::type('Symfony\Component\DependencyInjection\Definition'))
->once();
$container
->shouldReceive('setDefinition')
->with('cocur_slugify.twig.slugify', m::type('Symfony\Component\DependencyInjection\Definition'))
->once()
->andReturn($twigDefinition);
$container
->shouldReceive('setAlias')
->with('slugify', 'cocur_slugify')
->once();
$this->extension->load([], $container);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the cocur/slugify package.
*
* (c) Enrico Stahn <enrico.stahn@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Symfony;
use Cocur\Slugify\Bridge\Symfony\Configuration;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
public function testAll()
{
$configs = [
[
'lowercase' => true,
'separator' => '_',
'regexp' => 'abcd',
'rulesets' => ['burmese', 'hindi']
],
];
$this->process($configs);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
*/
public function testLowercaseOnlyAcceptsBoolean()
{
$configs = [['lowercase' => 'abc']];
$this->process($configs);
}
/**
* Processes an array of configurations and returns a compiled version.
*
* @param array $configs An array of raw configurations
*
* @return array A normalized array
*/
protected function process($configs)
{
$processor = new Processor();
return $processor->processConfiguration(new Configuration(), $configs);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* This file is part of cocur/slugify.
*
* (c) Florian Eckerstorfer <florian@eckerstorfer.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cocur\Slugify\Tests\Bridge\Twig;
use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Mockery as m;
/**
* SlugifyExtensionTest
*
* @category test
* @package cocur/slugify
* @subpackage bridge
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
* @copyright 2012-2014 Florian Eckerstorfer
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class SlugifyExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Cocur\Slugify\SlugifyInterface|\Mockery\MockInterface
*/
protected $slugify;
/**
* @var SlugifyExtension
*/
protected $extension;
protected function setUp()
{
$this->slugify = m::mock('Cocur\Slugify\SlugifyInterface');
$this->extension = new SlugifyExtension($this->slugify);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Twig\SlugifyExtension::getFilters()
*/
public function getFilters()
{
$filters = $this->extension->getFilters();
$this->assertCount(1, $filters);
$this->assertInstanceOf('\Twig_SimpleFilter', $filters[0]);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\Twig\SlugifyExtension::slugifyFilter()
*/
public function slugifyFilter()
{
$this->slugify->shouldReceive('slugify')->with('hällo wörld', '_')->once()->andReturn('haello_woerld');
$this->assertEquals('haello_woerld', $this->extension->slugifyFilter('hällo wörld', '_'));
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\ZF2;
use Cocur\Slugify\Bridge\ZF2\Module;
/**
* Class ModuleTest
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class ModuleTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Module
*/
private $module;
protected function setUp()
{
$this->module = new Module();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\Module::getServiceConfig()
*/
public function getServiceConfig()
{
$smConfig = $this->module->getServiceConfig();
$this->assertTrue(is_array($smConfig));
$this->assertArrayHasKey('factories', $smConfig);
$this->assertArrayHasKey('Cocur\Slugify\Slugify', $smConfig['factories']);
$this->assertArrayHasKey('aliases', $smConfig);
$this->assertArrayHasKey('slugify', $smConfig['aliases']);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\Module::getViewHelperConfig()
*/
public function getViewHelperConfig()
{
$vhConfig = $this->module->getViewHelperConfig();
$this->assertTrue(is_array($vhConfig));
$this->assertArrayHasKey('factories', $vhConfig);
$this->assertArrayHasKey('slugify', $vhConfig['factories']);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\ZF2;
use Cocur\Slugify\Bridge\ZF2\Module;
use Cocur\Slugify\Bridge\ZF2\SlugifyService;
use Zend\ServiceManager\ServiceManager;
/**
* Class SlugifyServiceTest
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyServiceTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SlugifyService
*/
private $slugifyService;
protected function setUp()
{
$this->slugifyService = new SlugifyService();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
*/
public function invokeWithoutCustomConfig()
{
$sm = $this->createServiceManagerMock();
$slugify = call_user_func($this->slugifyService, $sm);
$this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
// Make sure reg exp is default one
$actual = 'Hello My Friend.zip';
$expected = 'hello-my-friend-zip';
$this->assertEquals($expected, $slugify->slugify($actual));
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\SlugifyService::__invoke()
*/
public function invokeWithCustomConfig()
{
$sm = $this->createServiceManagerMock([
Module::CONFIG_KEY => [
'options' => ['regexp' => '/([^a-z0-9.]|-)+/']
]
]);
$slugify = call_user_func($this->slugifyService, $sm);
$this->assertInstanceOf('Cocur\Slugify\Slugify', $slugify);
// Make sure reg exp is the one provided and dots are kept
$actual = 'Hello My Friend.zip';
$expected = 'hello-my-friend.zip';
$this->assertEquals($expected, $slugify->slugify($actual));
}
protected function createServiceManagerMock(array $config = [])
{
$sm = new ServiceManager();
$sm->setService('Config', $config);
return $sm;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\ZF2;
use Cocur\Slugify\Bridge\ZF2\SlugifyViewHelperFactory;
use Cocur\Slugify\Slugify;
use Zend\ServiceManager\ServiceManager;
use Zend\View\HelperPluginManager;
/**
* Class SlugifyViewHelperFactoryTest
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyViewHelperFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SlugifyViewHelperFactory
*/
private $factory;
protected function setUp()
{
$this->factory = new SlugifyViewHelperFactory();
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelperFactory::__invoke()
*/
public function createService()
{
$sm = new ServiceManager();
$sm->setService('Cocur\Slugify\Slugify', new Slugify());
$vhm = new HelperPluginManager();
$vhm->setServiceLocator($sm);
$viewHelper = call_user_func($this->factory, $vhm);
$this->assertInstanceOf('Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper', $viewHelper);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Cocur\Slugify\Tests\Bridge\ZF2;
use Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper;
use Cocur\Slugify\Slugify;
/**
* Class SlugifyViewHelperTest
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyViewHelperTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SlugifyViewHelper
*/
private $viewHelper;
/**
* @var Slugify
*/
private $slugify;
/**
* @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper::__construct()
*/
protected function setUp()
{
$this->slugify = new Slugify();
$this->viewHelper = new SlugifyViewHelper($this->slugify);
}
/**
* @test
* @covers Cocur\Slugify\Bridge\ZF2\SlugifyViewHelper::__invoke()
*/
public function invoke()
{
$actual = 'Hällo Wörld';
$expected = call_user_func($this->viewHelper, $actual);
$this->assertEquals($expected, $this->slugify->slugify($actual));
$expected = call_user_func($this->viewHelper, $actual, '_');
$this->assertEquals($expected, $this->slugify->slugify($actual, '_'));
}
}