Пример #1
0
 public function testLoadList()
 {
     /* Load data */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     // Act
     $b = $a->getAllStructures();
     // Assert
     $this->assertEquals(3, count($b));
     //TODO Load data from invalid source
     /* Add structures */
     // Arrange
     $a = new Model\StructuresDo();
     //$a->loadFromFile(DIR_BASE.'/test/data/structures_demo.json');
     $numAdd = 5;
     for ($n = 0; $n < $numAdd; $n++) {
         $new_structure = new Model\StructureDo();
         $new_structure->setId("foo {$n}");
         $new_structure->setName("Name foo {$n}");
         $new_structure->setStorage('text/plain');
         $a->add($new_structure);
     }
     // Act
     $b = $a->getAllStructures();
     $this->setExpectedException('\\Acd\\Model\\KeyInvalidException');
     $c = $a->get('foo 3');
     // Assert
     $this->assertEquals(5, count($b));
     $this->assertEquals($c->getId(), 'foo 3');
     // Arrange
     $a = new Model\StructuresDo();
     $new_structure1 = new Model\StructureDo();
     $new_structure1->setId("foo");
     $new_structure1->setName("Name foo");
     $new_structure1->setStorage('text/plain');
     $resultOk = $a->add($new_structure1);
     $new_structure2 = new Model\StructureDo();
     $new_structure2->setId("foo");
     $new_structure2->setName("Name foo");
     $new_structure2->setStorage('text/plain');
     $resultKo = $a->add($new_structure2);
     // Act
     $b = $a->getAllStructures();
     // Assert
     $this->assertEquals(1, count($b));
     $this->assertTrue($resultOk);
     $this->assertFalse($resultKo);
     /* Get structure */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     // Act
     $b = $a->get('chat_tienda');
     // Assert
     $this->assertEquals($b->getId(), 'chat_tienda');
     $this->assertEquals($b->getName(), 'Chat de tienda online');
     $this->assertEquals($b->getStorage(), 'mongodb');
     // Act
     $b = $a->get('programa_tv');
     // Assert
     $this->assertEquals($b->getId(), 'programa_tv');
     $this->assertEquals($b->getName(), 'Programas TV');
     $this->assertEquals($b->getStorage(), 'text/plain');
     // Act
     $b = $a->get('no product');
     $this->assertNull($b);
     /* Delete structure */
     // Arrange
     $a = new Model\StructuresDo();
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     $numInitialStructures = count($a->getAllStructures());
     // Act
     $result = $a->remove('chat_tienda');
     $b = $a->getAllStructures();
     // Assert
     $this->assertTrue($result);
     $this->assertEquals(1, $numInitialStructures - count($b));
     // Arrange
     $a->loadFromFile(DIR_BASE . '/test/data/structures_demo.json');
     $numInitialStructures = count($a->getAllStructures());
     // Act
     $result = $a->remove('no product');
     $b = $a->getAllStructures();
     // Assert
     $this->assertFalse($result);
     $this->assertEquals(0, $numInitialStructures - count($b));
 }
Пример #2
0
<?php

namespace Acd;

require '../autoload.php';
$accion = strtolower($_POST['a']);
$id = $_POST['id'];
$name = isset($_POST['name']) ? $_POST['name'] : null;
$storage = isset($_POST['storage']) ? $_POST['storage'] : null;
$new_field_type = isset($_POST['new_field']) ? $_POST['new_field'] : null;
$fields = isset($_POST['field']) ? $_POST['field'] : array();
$structures = new Model\StructuresDo();
$structures->loadFromFile(\Acd\conf::$DATA_PATH);
try {
    $structureFound = $structures->get($id);
} catch (\Exception $e) {
    $structureFound = null;
}
switch ($accion) {
    case 'edit':
        $returnUrl = 'index.php?a=edit&id=' . urlencode($id);
        $bNeedSave = false;
        break;
    case 'new':
    case 'save':
        $bIdValid = false;
        if ($accion === 'new') {
            $bIdValid = $structureFound === null && $id !== '';
        } else {
            $bIdValid = $structureFound !== null;
        }
Пример #3
0
 case 'new':
     $bResult = isset($_GET['r']) && $_GET['r'] === 'ko' ? false : true;
     $estructura = new Model\StructureDo();
     $skeletonOu->setBodyClass('new');
     $contentOu->setActionType('new');
     $contentOu->setStorageTypes(conf::$STORAGE_TYPES);
     $contentOu->setStorage($estructura->getStorage());
     $headerMenuOu = new View\HeaderMenu();
     $headerMenuOu->setType('back');
     $skeletonOu->setHeadTitle('New structure');
     $skeletonOu->setHeaderMenu($headerMenuOu->render());
     break;
 case 'edit':
     try {
         $id = $_GET['id'];
         $estructura = $structures->get($id);
         $contentOu->setStructureId($id);
         $skeletonOu->setBodyClass('edit');
         $contentOu->setActionType('edit');
         $contentOu->setStructureName($estructura->getName());
         $contentOu->setStorageTypes(conf::$STORAGE_TYPES);
         $contentOu->setStorage($estructura->getStorage());
         $contentOu->setFieldTypes(Model\FieldDo::getAvailableTypes());
         $contentOu->setFields($estructura->getFields());
     } catch (\Exception $e) {
         /* Error, intentando editar una estructura que no existe */
         $skeletonOu->setBodyClass('error');
         $contentOu->setActionType('error');
     }
     $headerMenuOu = new View\HeaderMenu();
     $headerMenuOu->setType('back');