PHP Classes

File: tests/DomHandler/ElementHandlerTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  PHP SOAP Package Generator  >  tests/DomHandler/ElementHandlerTest.php  >  Download  
File: tests/DomHandler/ElementHandlerTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP SOAP Package Generator
Generate package to call SOAP services using WSDL
Author: By
Last change: issue #41 - add utility methods around element occurence constraints,
read more about element occurrence constraints at https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints
Date: 5 years ago
Size: 6,807 bytes
 

Contents

Class file image Download
<?php

namespace WsdlToPhp\PackageGenerator\Tests\DomHandler;

use
WsdlToPhp\PackageGenerator\Tests\TestCase;
use
WsdlToPhp\PackageGenerator\DomHandler\AbstractAttributeHandler;

class
ElementHandlerTest extends TestCase
{
   
/**
     *
     */
   
public function testHasAttribute()
    {
       
$domDocument = DomDocumentHandlerTest::bingInstance();

       
// first element tag
       
$element = $domDocument->getElementByName('element');
       
// first schema tag
       
$schema = $domDocument->getElementByName('schema');

       
$this->assertTrue($element->hasAttribute('minOccurs'));
       
$this->assertTrue($element->hasAttribute('type'));
       
$this->assertFalse($element->hasAttribute('minoccurs'));
       
$this->assertTrue($schema->hasAttribute('targetNamespace'));
       
$this->assertFalse($schema->hasAttribute('targetnamespace'));
    }
   
/**
     *
     */
   
public function testGetAttribute()
    {
       
$domDocument = DomDocumentHandlerTest::bingInstance();

       
// first element tag
       
$element = $domDocument->getElementByName('element');
       
// first schema tag
       
$schema = $domDocument->getElementByName('schema');

       
$this->assertInstanceOf('\\WsdlToPhp\\PackageGenerator\\DomHandler\\AttributeHandler', $schema->getAttribute('elementFormDefault'));
       
$this->assertEmpty($schema->getAttribute('targetnamespace'));
       
$this->assertInstanceOf('\\WsdlToPhp\\PackageGenerator\\DomHandler\\AttributeHandler', $element->getAttribute('name'));
       
$this->assertEmpty($schema->getAttribute('foo'));
    }
   
/**
     *
     */
   
public function testGetElementChildren()
    {
       
$domDocument = DomDocumentHandlerTest::bingInstance();

       
// first schema tag
       
$schema = $domDocument->getElementByName('schema');
       
// first element tag
       
$element = $domDocument->getElementByName('element');

       
$this->assertNotEmpty($schema->getElementChildren());
       
$this->assertContainsOnlyInstancesOf('\\WsdlToPhp\\PackageGenerator\\DomHandler\\AbstractElementHandler', $schema->getElementChildren());
       
$this->assertEmpty($element->getElementChildren());
    }
   
/**
     *
     */
   
public function testGetChildrenByName()
    {
       
$domDocument = DomDocumentHandlerTest::bingInstance();

       
// first sequence tag
       
$sequence = $domDocument->getElementByName('sequence');

       
$childrenByName = $sequence->getChildrenByName('element');
        foreach (
$childrenByName as $child) {
           
$this->assertSame('element', $child->getName());
        }
    }
   
/**
     *
     */
   
public function testGetChildByNameAndAttributes()
    {
       
$domDocument = DomDocumentHandlerTest::bingInstance();

       
// first message tag
       
$message = $domDocument->getElementByName('message');
       
$part = $message->getChildByNameAndAttributes('part', array(
           
'name' => 'parameters',
           
'element' => 'tns:SearchRequest',
        ));

       
$this->assertInstanceOf('\\WsdlToPhp\\PackageGenerator\\DomHandler\\ElementHandler', $part);
       
$this->assertSame('parameters', $part->getAttributeValue('name'));
       
$this->assertSame('SearchRequest', $part->getAttributeValue('element'));
    }
   
/**
     *
     */
   
public function testGetMaxOccursUnbounded()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'CampaignIds',
        ));

       
$this->assertSame('unbounded', $element->getMaxOccurs());
    }
   
/**
     *
     */
   
public function testGetMaxOccursOne()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'NegativeKeywords',
        ));

       
$this->assertSame(AbstractAttributeHandler::DEFAULT_OCCURENCE_VALUE, $element->getMaxOccurs());
    }
   
/**
     *
     */
   
public function testGetMinOccursNone()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'NegativeKeywords',
        ));

       
$this->assertSame(0, $element->getMinOccurs());
    }
   
/**
     *
     */
   
public function testGetMinOccursOne()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'Name',
        ));

       
$this->assertSame(1, $element->getMinOccurs());
    }
   
/**
     *
     */
   
public function testCanOccurSeveralTimes()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'RegionIds',
        ));

       
$this->assertTrue($element->canOccurSeveralTimes());
    }
   
/**
     *
     */
   
public function testCanOccurOnlyOnce()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'CampaignId',
        ));

       
$this->assertTrue($element->canOccurOnlyOnce());
    }
   
/**
     *
     */
   
public function testCanOccurOnlyOnceEvenForOptionalElement()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'NegativeKeywords',
        ));

       
$this->assertTrue($element->canOccurOnlyOnce());
    }
   
/**
     *
     */
   
public function testIsOptional()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'NegativeKeywords',
        ));

       
$this->assertTrue($element->isOptional());
    }
   
/**
     *
     */
   
public function testIsRequired()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'Name',
        ));

       
$this->assertTrue($element->isRequired());
    }
   
/**
     *
     */
   
public function testIsNotRequired()
    {
       
$domDocument = DomDocumentHandlerTest::yandeDirectApiAdGroupsInstance();

       
$element = $domDocument->getElementByNameAndAttributes('element', array(
           
'name' => 'NegativeKeywords',
        ));

       
$this->assertFalse($element->isRequired());
    }
}

For more information send a message to info at phpclasses dot org.