You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArrayTest.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. require_once __DIR__.'/../../../../lib/Twig/Extensions/Extension/Array.php';
  11. class Twig_Tests_Extension_ArrayTest extends PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @dataProvider getShuffleFilterTestData
  15. */
  16. public function testShuffleFilter($data, $expectedElements)
  17. {
  18. foreach ($expectedElements as $element) {
  19. $this->assertTrue(in_array($element, twig_shuffle_filter($data), true)); // assertContains() would not consider the type
  20. }
  21. }
  22. public function testShuffleFilterOnEmptyArray()
  23. {
  24. $this->assertEquals(array(), twig_shuffle_filter(array()));
  25. }
  26. public function getShuffleFilterTestData()
  27. {
  28. return array(
  29. array(
  30. array(1, 2, 3),
  31. array(1, 2, 3),
  32. ),
  33. array(
  34. array('a' => 'apple', 'b' => 'orange', 'c' => 'citrus'),
  35. array('apple', 'orange', 'citrus'),
  36. ),
  37. array(
  38. new ArrayObject(array('apple', 'orange', 'citrus')),
  39. array('apple', 'orange', 'citrus'),
  40. ),
  41. );
  42. }
  43. }