Ejemplo n.º 1
0
 public function fastFind(Test $test)
 {
     $queryBuilder = $this->getEntityManager()->createQueryBuilder();
     $queryBuilder->select('test')->from('TestBundle\\Entity\\Test', 'test')->where($queryBuilder->expr()->eq('test.ch', ':ch'))->setParameter(':ch', $test->getCh(), Type::STRING);
     $query = $queryBuilder->getQuery();
     return $query->getResult();
 }
Ejemplo n.º 2
0
 public function import(Test $test)
 {
     $xml_user_info = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><test></test>");
     $this->array_to_xml($test->toArray(false), $xml_user_info);
     $xml_file = $xml_user_info->asXML();
     return $xml_file;
 }
Ejemplo n.º 3
0
 private function parsePage(Crawler $crawler)
 {
     $questions = $crawler->filter('table.question');
     $testsArr = $questions->each(function (Crawler $node, $i) {
         $test = new Test();
         //1 set Ask
         $ask = utf8_decode($node->filter('div.question')->text());
         $ask = preg_replace('/\\s+/', ' ', $ask);
         $ask = trim(preg_replace('/^[\\s]?[0-9]*/', '', $ask));
         $test->setAsk($ask);
         $variants = $node->filter('.new_answer')->each(function (Crawler $node, $i) {
             $variant = new Variant();
             $varStr = utf8_decode($node->text());
             $varStr = preg_replace('/\\s+/', ' ', $varStr);
             $varStr = trim($varStr);
             $varStr = substr($varStr, 2);
             $varStr = trim($varStr);
             $variant->setVariant($varStr);
             $right = $node->attr('style');
             if (!empty($right)) {
                 $variant->setPrOtvet(true);
             }
             return $variant;
         });
         $test->setVariants($variants);
         return $test;
     });
     return $testsArr;
 }
 /**
  * @test
  */
 public function import_arr()
 {
     $test = new Test();
     $test->setAsk('Ask test');
     $variant_1 = new Variant();
     $variant_1->setVariant('Variant1');
     $variant_1->setPrOtvet(true);
     $test->addVariant($variant_1);
     $variant_2 = new Variant();
     $variant_2->setVariant('Variant2');
     $variant_2->setPrOtvet(true);
     $test->addVariant($variant_2);
     $variant_3 = new Variant();
     $variant_3->setVariant('Variant3');
     $variant_3->setPrOtvet(false);
     $test->addVariant($variant_3);
     $arr = [$test, $test];
     $test_xml = new TestImporter();
     $xml = $test_xml->import_arr($arr);
     //print_r($xml);
 }
Ejemplo n.º 5
0
 private function _getHtmlTest(Test $test)
 {
     $variantHtml = '';
     foreach ($test->getVariants() as $variant) {
         if ($variant->getPrOtvet()) {
             $variantHtml .= $variant->getVariant();
         }
     }
     $newTestHtml = $test->getAsk() . ' ----- ' . $variantHtml;
     return $newTestHtml;
 }
 public function testIsNotEquivalent()
 {
     $parserController = new ParserController();
     $test1 = new Test();
     $test1->setAsk('Ask test');
     $variant1_1 = new Variant();
     $variant1_1->setVariant('Variant1');
     $variant1_1->setPrOtvet(true);
     $test1->addVariant($variant1_1);
     $variant1_2 = new Variant();
     $variant1_2->setVariant('Variant2');
     $variant1_2->setPrOtvet(true);
     $test1->addVariant($variant1_2);
     $variant1_3 = new Variant();
     $variant1_3->setVariant('Variant3');
     $variant1_3->setPrOtvet(false);
     $test1->addVariant($variant1_3);
     $test2 = new Test();
     $test2->setAsk('Ask test');
     $variant2_3 = new Variant();
     $variant2_3->setVariant('Variant31');
     $variant2_3->setPrOtvet(false);
     $test2->addVariant($variant2_3);
     $variant2_1 = new Variant();
     $variant2_1->setVariant('Variant11');
     $variant2_1->setPrOtvet(true);
     $test2->addVariant($variant2_1);
     $variant2_2 = new Variant();
     $variant2_2->setVariant('Variant21');
     $variant2_2->setPrOtvet(true);
     $test2->addVariant($variant2_2);
     $this->assertFalse($parserController->testIsEquivalent($test1, $test2));
 }
Ejemplo n.º 7
0
 private function calculateCorrectAnswer(Test $test)
 {
     $test->calculateCorrectAnswer();
 }
Ejemplo n.º 8
0
 public function createTestObj($html)
 {
     $test = new Test();
     $test->setAsk($this->getAsk($html));
     $variants = $this->getVariants($html);
     $right_id = $this->getRightVariantPos($html);
     foreach ($variants as $key => $value) {
         $variant = new Variant();
         $variant->setVariant($value);
         if ($key == $right_id) {
             $variant->setPrOtvet(true);
         }
         $test->addVariant($variant);
     }
     return $test;
 }
Ejemplo n.º 9
0
 /**
  * @test
  */
 public function toArray()
 {
     $test = new Test();
     $test->setAsk('Ask test');
     $variant_1 = new Variant();
     $variant_1->setVariant('Variant1');
     $variant_1->setPrOtvet(true);
     $test->addVariant($variant_1);
     $variant_2 = new Variant();
     $variant_2->setVariant('Variant2');
     $variant_2->setPrOtvet(true);
     $test->addVariant($variant_2);
     $variant_3 = new Variant();
     $variant_3->setVariant('Variant3');
     $variant_3->setPrOtvet(false);
     $test->addVariant($variant_3);
     $arr_t2 = $test->toArray(false);
     $this->assertTrue($arr_t2['variants'][0]['variant'] == 'Variant1');
 }