Commits

Joey Mazzarelli  committed c89a395

new test, not finished

  • Participants
  • Parent commits 53467ba

Comments (0)

Files changed (1)

File src/test/php/SelectorsTest.php

+<?php
+/**
+ * Copyright 2010 Joey Mazzarelli. All rights reserved.
+ *
+ * Redistribution and use in source, with or without modification, is
+ * permitted provided that the following condition is met:
+ *
+ *    1. Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOEY MAZZARELLI ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL JOEY MAZZARELLI OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * official policies, either expressed or implied, of Joey Mazzarelli.
+ */
+
+require_once dirname(__FILE__) . '/TestCase.php';
+
+class Trekel_AttributeTest extends Trekel_TestCase {
+
+  public function setup () {
+    parent::setup();
+    $a1 = new Trekel_SelectorsTest_A("A", 1);
+    $a2 = new Trekel_SelectorsTest_A("A", 2);
+    $a3 = new Trekel_SelectorsTest_A("A", 3);
+    $b1 = new Trekel_SelectorsTest_B("B", 1);
+    $b2 = new Trekel_SelectorsTest_B("B", 2);
+    $b3 = new Trekel_SelectorsTest_B("B", 3);
+  }
+
+  public function stestOne () {
+
+    $a = new Trekel_AttributeTest_A("foo");
+    $b = new Trekel_AttributeTest_B("bar");
+    $c1 = new Trekel_AttributeTest_C2a();
+    $c2 = new Trekel_AttributeTest_C2b("barf");
+    $a->addChild($b);
+    $a->addChild($c1);
+    $a->addChild($c2);
+
+    /**
+     * This is what this looks like graphically
+     *
+     *          A
+     *         /|\
+     *        / | \
+     *       B  C1 C2
+     */
+
+    $parser = new Trekel_Parser();
+    $parser->setSelector('*[name="foo"]');
+    $parseTree = $parser->parse();
+    $evaluator = new Trekel_Evaluator();
+    $evaluator->setParseTree($parseTree);
+    $evaluator->setRootNode($a);
+    $nodes = $evaluator->evaluate();
+    $this->assertEquals(1, count($nodes));
+    $node = $nodes[0];
+    $this->assertEquals("Trekel_AttributeTest_A", get_class($node));
+    $this->assertEquals("foo", $node->getName());
+  }
+
+} // end Trekel_AttributeTest
+
+class Trekel_SelectorsTest_Base {
+  private $children = array();
+  private $parent;
+  public $name = "";
+  public $age = 0;
+  public function __construct ($name = "", $age = 0)
+  { $this->name = $name; $this->age = $age; }
+  public function getChildren () { return $this->children; }
+  public function getParent () { return $this->parent; }
+  public function setParent ($parent) { $this->parent = $parent; }
+  public function getName () { return $this->name; }
+  public function getAge () { return $this->age; }
+  public function addChild ($child) {
+    $child->setParent($this);
+    $this->children[] = $child;
+  }
+}
+class Trekel_SelectorsTest_A extends Trekel_SelectorsTest_Base { }
+class Trekel_SelectorsTest_B extends Trekel_SelectorsTest_Base { }
+class Trekel_SelectorsTest_C extends Trekel_SelectorsTest_Base { }
+class Trekel_SelectorsTest_C1 extends Trekel_SelectorsTest_C   { }
+class Trekel_SelectorsTest_C2 extends Trekel_SelectorsTest_C   { }
+class Trekel_SelectorsTest_D extends Trekel_SelectorsTest_Base { }
+class Trekel_SelectorsTest_E extends Trekel_SelectorsTest_Base { }
+