public function testResourceFromIndex()
 {
     $object = new PhpProject();
     $oResource1 = $object->createResource();
     $oResource1->setIndex(2);
     $oResource2 = $object->createResource();
     $oResource2->setIndex(4);
     $this->assertInstanceOf('PhpOffice\\PhpProject\\Resource', $object->getResourceFromIndex(2));
     $this->assertNull($object->getResourceFromIndex(1));
 }
Beispiel #2
0
 /**
  * Resource
  * @param array $record
  */
 private function readRecord50(array $record)
 {
     $oResource = $this->phpProject->createResource();
     foreach ($this->defResource as $key => $method) {
         $oResource->{$method}($record[$key]);
     }
 }
 public function testSave()
 {
     $fileOutput = tempnam(sys_get_temp_dir(), 'PHPPROJECT');
     $oPHPProject = new PhpProject();
     $oResource = $oPHPProject->createResource();
     $oResource->setTitle('ResourceTest');
     $oTask1 = $oPHPProject->createTask();
     $oTask1->setName('Task1Test');
     $oTask1->addResource($oResource);
     $oTask1Child = $oTask1->createTask();
     $oTask1Child->setName('TaskChildTest');
     $oTask1ChildChild1 = $oTask1Child->createTask();
     $oTask1ChildChild1->setName('TaskChildChild1Test');
     $oTask1ChildChild1->setStartDate('2014-08-07');
     $oTask1ChildChild1->setDuration(2);
     $oTask1ChildChild2 = $oTask1Child->createTask();
     $oTask1ChildChild2->setName('TaskChildChild2Test');
     $oTask1ChildChild2->setStartDate('2014-08-06');
     $oTask1ChildChild2->setEndDate('2014-08-10');
     $oTask2 = $oPHPProject->createTask();
     $oTask2->setStartDate('2014-08-07');
     $oTask2->setEndDate('2014-08-13');
     $oTask2->setName('Task2Test');
     $xmlWriter = IOFactory::createWriter($oPHPProject, 'GanttProject');
     $xmlWriter->save($fileOutput);
     $oXMLDocument = new XmlDocument();
     $this->assertTrue($oXMLDocument->elementExists('/project', $fileOutput));
     $this->assertEquals('2014-08-06', $oXMLDocument->getElementAttribute('/project', 'view-date', $fileOutput));
     // Task 1
     $this->assertTrue($oXMLDocument->elementExists('/project/tasks/task[@id="1"]', $fileOutput));
     $this->assertEquals('Task1Test', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="1"]', 'name', $fileOutput));
     $this->assertEquals('2014-08-06', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="1"]', 'start', $fileOutput));
     $this->assertEquals('5', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="1"]', 'duration', $fileOutput));
     // TaskChild
     $this->assertTrue($oXMLDocument->elementExists('/project/tasks/task/task[@id="2"]', $fileOutput));
     $this->assertEquals('TaskChildTest', $oXMLDocument->getElementAttribute('/project/tasks/task/task[@id="2"]', 'name', $fileOutput));
     $this->assertEquals('2014-08-06', $oXMLDocument->getElementAttribute('/project/tasks/task/task[@id="2"]', 'start', $fileOutput));
     $this->assertEquals('5', $oXMLDocument->getElementAttribute('/project/tasks/task/task[@id="2"]', 'duration', $fileOutput));
     // TaskChildChild
     $this->assertTrue($oXMLDocument->elementExists('/project/tasks/task/task/task[@id="3"]', $fileOutput));
     $this->assertEquals('TaskChildChild1Test', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="3"]', 'name', $fileOutput));
     $this->assertEquals('2014-08-07', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="3"]', 'start', $fileOutput));
     $this->assertEquals('2', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="3"]', 'duration', $fileOutput));
     // TaskChildChild
     $this->assertTrue($oXMLDocument->elementExists('/project/tasks/task/task/task[@id="4"]', $fileOutput));
     $this->assertEquals('TaskChildChild2Test', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="4"]', 'name', $fileOutput));
     $this->assertEquals('2014-08-06', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="4"]', 'start', $fileOutput));
     $this->assertEquals('5', $oXMLDocument->getElementAttribute('/project/tasks/task/task/task[@id="4"]', 'duration', $fileOutput));
     // Task 2
     $this->assertTrue($oXMLDocument->elementExists('/project/tasks/task[@id="5"]', $fileOutput));
     $this->assertEquals('Task2Test', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="5"]', 'name', $fileOutput));
     $this->assertEquals('2014-08-07', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="5"]', 'start', $fileOutput));
     $this->assertEquals('7', $oXMLDocument->getElementAttribute('/project/tasks/task[@id="5"]', 'duration', $fileOutput));
     // Resource
     $this->assertTrue($oXMLDocument->elementExists('/project/resources/resource', $fileOutput));
     $this->assertEquals('ResourceTest', $oXMLDocument->getElementAttribute('/project/resources/resource', 'name', $fileOutput));
     // Allocation
     $this->assertTrue($oXMLDocument->elementExists('/project/allocations/allocation', $fileOutput));
     $this->assertTrue($oXMLDocument->elementExists('/project/allocations/allocation[@task-id="1"][@resource-id="0"]', $fileOutput));
 }
Beispiel #4
0
 /**
  * Node "Resources"
  * @param XMLReader $oXML
  * @param \DOMElement $domNode
  */
 private function readNodeResources(XMLReader $oXML, \DOMElement $domNode)
 {
     $oNodes = $oXML->getElements('*', $domNode);
     if ($oNodes->length > 0) {
         foreach ($oNodes as $oNode) {
             if ($oNode->nodeName == 'resource') {
                 $oResource = $this->phpProject->createResource();
                 $this->readNodeResource($oNode, $oResource);
             }
         }
     }
 }
 public function testSave()
 {
     $fileOutput = tempnam(sys_get_temp_dir(), 'PHPPROJECT');
     $oPHPProject = new PhpProject();
     $oResource = $oPHPProject->createResource();
     $oResource->setTitle('ResourceTest');
     $oTask1 = $oPHPProject->createTask();
     $oTask1->setName('Task1Test');
     $oTask1->addResource($oResource);
     $oTask1Child = $oTask1->createTask();
     $oTask1Child->setName('TaskChildTest');
     $oTask1ChildChild1 = $oTask1Child->createTask();
     $oTask1ChildChild1->setName('TaskChildChild1Test');
     $oTask1ChildChild1->setStartDate('2014-08-07');
     $oTask1ChildChild1->setDuration(2);
     $oTask1ChildChild2 = $oTask1Child->createTask();
     $oTask1ChildChild2->setName('TaskChildChild2Test');
     $oTask1ChildChild2->setStartDate('2014-08-06');
     $oTask1ChildChild2->setEndDate('2014-08-10');
     $oTask2 = $oPHPProject->createTask();
     $oTask2->setStartDate('2014-08-07');
     $oTask2->setEndDate('2014-08-13');
     $oTask2->setName('Task2Test');
     $xmlWriter = IOFactory::createWriter($oPHPProject, 'MsProjectMPX');
     $xmlWriter->save($fileOutput);
     $content = file_get_contents($fileOutput);
     $content = explode(PHP_EOL, $content);
     foreach ($content as $line) {
         $line = explode(';', $line);
         switch ($line[0]) {
             case 'MPX':
                 $this->assertEquals('Microsoft Project for Windows', $line[1]);
                 break;
         }
     }
 }