瀏覽代碼

Test workflow

Luciano Andrade 7 年之前
父節點
當前提交
96d211c948
共有 1 個文件被更改,包括 71 次插入0 次删除
  1. 71 0
      src/FTTHBundle/tests/WorkflowOnuTest.php

+ 71 - 0
src/FTTHBundle/tests/WorkflowOnuTest.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace FTTHBundle\tests;
+
+use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
+
+use FTTHBundle\Entity\ONU;
+
+/**
+ * @package FTTHBundle\tests
+ */
+class WorkflowOnuTest extends KernelTestCase
+{
+
+    protected function setUp()
+    {
+        self::bootKernel();
+
+        $this->em = static::$kernel->getContainer()
+            ->get('doctrine')
+            ->getManager();
+	$this->wr = static::$kernel->getContainer()
+            ->get('workflow.registry');
+
+    }
+
+    function testAdministrative(){
+        $onu = new ONU;
+	$onu->setPonSerialNumber("cafecafecafe");
+	$onu->setClientId(1);
+	$onu->setTenancyId(1);
+
+	try{
+		$this->em->persist($onu);
+		$this->em->flush();
+	}catch(\Exception $e){
+	
+	}
+
+	$this->assertEquals("active", $onu->getAdministrativeState());
+            
+
+	$wf = $this->wr->get($onu, "administrative_state");
+	
+	$wf->apply($onu, "active_to_suspend");
+
+	$this->assertEquals("suspend", $onu->getAdministrativeState());
+
+	$this->em->persist($onu);
+	$this->em->flush();
+
+        $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
+
+	$this->assertEquals("suspend", $newOnu->getAdministrativeState());
+
+	$wf->apply($newOnu, "suspend_to_active");
+
+	$this->em->persist($newOnu);
+	$this->em->flush();
+
+        $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
+	$this->assertEquals("active", $newOnu->getAdministrativeState());
+
+
+	if($newOnu){
+		$newOnu = $this->em->remove($newOnu);
+		$this->em->flush();
+	}
+	
+    }
+}