added tests for the in filter
authorfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Sun, 13 Dec 2009 12:55:04 +0000 (12:55 +0000)
committerfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Sun, 13 Dec 2009 12:55:04 +0000 (12:55 +0000)
git-svn-id: http://svn.twig-project.org/trunk@169 93ef8e89-cb99-4229-a87c-7fa0fa45744b

doc/02-Twig-for-Template-Designers.markdown
lib/Twig/runtime.php
test/fixtures/filters/in.test [new file with mode: 0644]
test/unit/integrationTest.php

index cac3278..6d2709a 100644 (file)
@@ -844,7 +844,7 @@ Returns true if the value is contained within another one.
     {{ 'cd'|in('abcde') }}
 
 You can use this filter to perform a containment test on strings, arrays, or
-objects implementing the `ArrayAccess` interface.
+objects implementing the `Traversable` interface.
 
 ### `default`
 
index 4d98244..16e617e 100644 (file)
@@ -97,7 +97,7 @@ function twig_in_filter($value, $compare)
   {
     return false !== strpos($compare, (string) $value);
   }
-  elseif (is_object($compare) && $compare instanceof ArrayAccess)
+  elseif (is_object($compare) && $compare instanceof Traversable)
   {
     return in_array($value, iterator_to_array($compare));
   }
diff --git a/test/fixtures/filters/in.test b/test/fixtures/filters/in.test
new file mode 100644 (file)
index 0000000..4d6e337
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+"in" filter
+--TEMPLATE--
+{{ 1|in([1, 2, 3]) }}
+{{ 5|in([1, 2, 3]) }}
+{{ 'cd'|in('abcde') }}
+{{ 'ad'|in('abcde') }}
+{{ 'foo'|in(foo) }}
+{{ 'a'|in(foo|keys) }}
+--DATA--
+class ItemsIteratorForInFilter implements Iterator
+{
+  protected $values = array('a' => 'foo', 'b' => 'bar');
+  public function current() { return current($this->values); }
+  public function key() { return key($this->values); }
+  public function next() { return next($this->values); }
+  public function rewind() { return reset($this->values); }
+  public function valid() { return false !== current($this->values); }
+}
+return array('foo' => new ItemsIteratorForInFilter())
+--EXPECT--
+1
+
+1
+
+1
+1
index 9b56a86..ee05be2 100644 (file)
@@ -33,7 +33,7 @@ class Foo
   }
 }
 
-$t = new LimeTest(52);
+$t = new LimeTest(53);
 $fixturesDir = realpath(dirname(__FILE__).'/../fixtures/');
 
 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixturesDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)