public function testFind()
 {
     $collection = new phTestAbstractFindingCollection();
     /*
      * make and register test[address]
      */
     $array = new phArrayFormDataItem('test');
     $key = new phArrayKeyInfo('address', false, phArrayKeyInfo::STRING);
     $item1 = new phFormDataItem('address');
     $array->registerArrayKey($key, $item1);
     $collection->addData('test', $array);
     /*
      * make and register ids[]
      */
     $array = new phArrayFormDataItem('ids');
     $key = new phArrayKeyInfo('', true, phArrayKeyInfo::NUMERIC);
     $item2 = new phFormDataItem('0');
     $array->registerArrayKey($key, $item2);
     $collection->addData('ids', $array);
     $this->assertSame($item1, $collection->find('test[address]'));
     $this->assertSame($item2, $collection->find('ids[0]'));
     $this->assertTrue($collection->find('ids') instanceof phArrayFormDataItem, 'ids is an array data type');
 }
 protected function getOrCreateArrayDataType(phNameInfo $name, $keys, $currentKeyIndex, phFormViewElement $element, phArrayFormDataItem $currentDataItem)
 {
     $currentKey = $keys[$currentKeyIndex]->isAutoKey() ? $currentDataItem->getNextAutoKey() : $keys[$currentKeyIndex]->getKey();
     if ($currentKeyIndex == sizeof($keys) - 1) {
         // last key
         if (isset($currentDataItem[$currentKey])) {
             $finalItem = $currentDataItem[$currentKey];
         } else {
             $finalItem = $this->createNormalDataItem($currentKey, $element);
             $currentDataItem->registerArrayKey($keys[$currentKeyIndex], $finalItem);
         }
         return $finalItem;
     } else {
         if (isset($currentDataItem[$currentKey])) {
             $nextDataItem = $currentDataItem[$currentKey];
             if (!$nextDataItem instanceof phArrayFormDataItem) {
                 $path = $name->getName();
                 for ($x = 0; $x <= $currentKeyIndex; $x++) {
                     $path .= "[{$keys[$currentKeyIndex]->getKey()}]";
                 }
                 throw new phFormException("Unable to register array type data at {$path} is not an array data type");
             }
         } else {
             $nextDataItem = $this->createArrayDataItem($keys[$currentKeyIndex + 1], $element, $keys[$currentKeyIndex]->getKey());
             $currentDataItem->registerArrayKey($keys[$currentKeyIndex], $nextDataItem);
         }
         return $this->getOrCreateArrayDataType($name, $keys, ++$currentKeyIndex, $element, $nextDataItem);
     }
 }
 /**
  * tests the auto key calcs properly
  */
 public function testAutoKeys()
 {
     $testData = new phArrayFormDataItem('test');
     $this->assertEquals($testData->getNextAutoKey(), 0, 'auto key before registering anything is 0');
     $info = new phArrayKeyInfo('', true, phArrayKeyInfo::NUMERIC);
     $testData->registerArrayKey($info, new phFormDataItem('test'));
     $this->assertEquals($testData->getNextAutoKey(), 1, 'auto key after one register is 1');
     $info = new phArrayKeyInfo('', true, phArrayKeyInfo::NUMERIC);
     $testData->registerArrayKey($info, new phFormDataItem('test'));
     $this->assertEquals($testData->getNextAutoKey(), 2, 'auto key after two register is 2');
 }