Jackalope\Transport\DoctrineDBAL\ClientTest::testPropertyLengthAttribute PHP Method

testPropertyLengthAttribute() public method

    public function testPropertyLengthAttribute()
    {
        $rootNode = $this->session->getRootNode();
        $node = $rootNode->addNode('testLengthAttribute');
        $data = array('simpleString' => array('simplestring', PropertyType::STRING, 12), 'mbString' => array('stringMultibitę¼¢', PropertyType::STRING, 17), 'long' => array(42, PropertyType::LONG, 2), 'double' => array(3.1415, PropertyType::DOUBLE, 6), 'decimal' => array(3.141592, PropertyType::DECIMAL, 8), 'date' => array(new \DateTime('now'), PropertyType::DATE, 29), 'booleanTrue' => array(true, PropertyType::BOOLEAN, 1), 'booleanFalse' => array(false, PropertyType::BOOLEAN, 0), 'name' => array('nt:unstructured', PropertyType::NAME, 15), 'uri' => array('https://google.com', PropertyType::URI, 18), 'path' => array('/root/testLengthAttribute', PropertyType::PATH, 25));
        foreach ($data as $propertyName => $propertyInfo) {
            $node->setProperty($propertyName, $propertyInfo[0], $propertyInfo[1]);
        }
        $this->session->save();
        $statement = $this->getConnection()->executeQuery('SELECT props, numerical_props FROM phpcr_nodes WHERE path = ?', array('/testLengthAttribute'));
        $row = $statement->fetch(\PDO::FETCH_ASSOC);
        $props = $row['props'];
        $decimalProps = $row['numerical_props'];
        foreach ($data as $propertyName => $propertyInfo) {
            $propertyElement = null;
            foreach (array($props, $decimalProps) as $propXml) {
                if (null == $propXml) {
                    continue;
                }
                $doc = new \DOMDocument('1.0', 'utf-8');
                $doc->loadXML($propXml);
                $xpath = new \DOMXPath($doc);
                $propertyElement = $xpath->query(sprintf('sv:property[@sv:name="%s"]', $propertyName));
                if ($propertyElement->length > 0) {
                    break;
                }
            }
            $this->assertEquals(1, $propertyElement->length, 'Property ' . $propertyName . ' exists');
            $values = $xpath->query('sv:value', $propertyElement->item(0));
            /** @var $value \DOMElement */
            foreach ($values as $index => $value) {
                $lengthAttribute = $value->attributes->getNamedItem('length');
                if (null === $lengthAttribute) {
                    $this->fail(sprintf('Value %d for property "%s" is expected to have an attribute "length"', $index, $propertyName));
                }
                $this->assertEquals($propertyInfo[2], $lengthAttribute->nodeValue);
            }
        }
    }