/lib/Molinos/Base/Tests.php
PHP | 519 lines | 382 code | 81 blank | 56 comment | 2 complexity | 2fb977a3ed3c65cafec2474ed45327d3 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
- <?php
- class Molinos_Base_Tests extends Molinos_Testing_Case
- {
- /**
- * @expectedException InvalidArgumentException
- */
- public function testHtmlEmNoArgs()
- {
- Molinos_Base_XML::em();
- }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testHtmlEmTooManyArgs()
- {
- Molinos_Base_XML::em(1, 2, 3, 4);
- }
- /**
- * @expectedException InvalidArgumentException
- */
- public function testHtmlEmEmptyName()
- {
- Molinos_Base_XML::em(null);
- }
- public function testHtmlEmSimple()
- {
- $html = Molinos_Base_XML::em('br');
- $this->assertEquals('<br/>', $html);
- }
- public function testHtmlEmWithContent()
- {
- $html = Molinos_Base_XML::em('p', 'hello');
- $this->assertEquals('<p>hello</p>', $html);
- }
- public function testHtmlEmWithAttributes()
- {
- $html = Molinos_Base_XML::em('br', array(
- 'class' => 'hidden',
- ));
- $this->assertEquals('<br class=\'hidden\'/>', $html);
- }
- public function testHtmlEmTdThEmpty()
- {
- $html = Molinos_Base_XML::em('td');
- $this->assertEquals('<td> </td>', $html);
- $html = Molinos_Base_XML::em('th');
- $this->assertEquals('<th> </th>', $html);
- }
- public function testHtmlEmptyDiv()
- {
- $html = Molinos_Base_XML::em('div');
- $this->assertEquals('<div></div>', $html);
- $html = Molinos_Base_XML::em('script');
- $this->assertEquals('<script></script>', $html);
- $html = Molinos_Base_XML::em('textarea');
- $this->assertEquals('<textarea></textarea>', $html);
- $html = Molinos_Base_XML::em('span');
- $this->assertEquals('<span></span>', $html);
- $html = Molinos_Base_XML::em('base');
- $this->assertEquals('<base></base>', $html);
- $html = Molinos_Base_XML::em('a');
- $this->assertEquals('<a></a>', $html);
- }
- public function testHtmlAttrs()
- {
- $a = Molinos_Base_XML::attrs(array(
- 'class' => 'test',
- 'title' => 'hello',
- 'width' => 0,
- 'checked' => true,
- ));
- $this->assertEquals(" checked='yes' class='test' title='hello'", $a);
- }
- public function testHtmlNonUniqueClasses()
- {
- $a = Molinos_Base_XML::attrs(array(
- 'class' => 'test ok test ok xyz',
- ));
- $this->assertEquals(" class='test ok xyz'", $a);
- }
- public function testHtmlSimpleList()
- {
- $html = Molinos_Base_XML::simpleList(array('one', 'two'));
- $this->assertEquals('<li>one</li><li>two</li>', $html);
- }
- public function testHtmlSimpleOptions()
- {
- $html = Molinos_Base_XML::simpleOptions(array(
- 'a' => 'first',
- 'b' => 'second',
- ));
- $this->assertEquals("<option value='a'>first</option><option value='b'>second</option>", $html);
- }
- public function testHtmlCdata()
- {
- $this->assertEquals(null, Molinos_Base_XML::cdata(null));
- $this->assertEquals(null, Molinos_Base_XML::cdata(0));
- $this->assertEquals(null, Molinos_Base_XML::cdata(''));
- $this->assertEquals(null, Molinos_Base_XML::cdata(array(123)));
- $this->assertEquals(null, Molinos_Base_XML::cdata(new stdClass()));
- $this->assertEquals('test', Molinos_Base_XML::cdata('test'));
- $this->assertEquals('<![CDATA[ ]]>', Molinos_Base_XML::cdata(' '));
- }
- public function formatExtras()
- {
- $html = Molinos_Base_XML::formatExtras(array(
- array(
- 'style',
- 'test.css'
- ),
- array(
- 'script',
- 'test.js',
- ),
- ));
- $this->assertEquals("<link rel='stylesheet' type='text/css' href='test.css' /><script type='text/javascript' src='test.js'></script>", $html);
- }
- public function testHtmlAttributeName()
- {
- $html = Molinos_Base_XML::em('test', array(
- '1' => 2,
- '_destination' => 1,
- '-destination' => 2,
- ));
- $this->assertEquals('<test/>', $html);
- }
- private $db;
- public function testNodeConnect()
- {
- $this->db = Molinos_Database_Connection::getInstance();
- $this->assertNotNull($this->db);
- }
- public function testNodeCreateNewNode()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'xyz',
- 'name' => 'hello',
- ));
- $this->assertTrue($node instanceof Molinos_Base_Node);
- $this->assertEquals('hello', $node->name);
- $this->assertNull($node->id);
- }
- public function testNodeSetNodeProperty()
- {
- $node = Molinos_Core_API::getInstance("node")->create(array(
- "class" => "xyz",
- ));
- $text = 'hello, world.';
- $node->name = $text;
- $this->assertEquals($text, $node->name);
- }
- public function testNodeIsset()
- {
- $node = Molinos_Core_API::getInstance("node")->create(array(
- "class" => "xyz",
- ));
- $this->assertFalse(isset($node->name));
- $node->name = 'hello';
- $this->assertTrue(isset($node->name));
- }
- public function testNodeCountNodes()
- {
- if ($this->db) {
- $count = $this->db->getResult("SELECT COUNT(*) FROM {node} WHERE `class` = 'type' AND `deleted` = 0");
- $this->assertEquals($count, Molinos_Core_API::getInstance('node')->count(array(
- 'class' => 'type',
- )));
- }
- }
- public function testNodeCountDeletedNodes()
- {
- if ($this->db) {
- $count = $this->db->getResult("SELECT COUNT(*) FROM {node} WHERE `class` = 'type' AND `deleted` = 1");
- $this->assertEquals($count, Molinos_Core_API::getInstance('node')->count(array(
- 'class' => 'type',
- 'deleted' => 1,
- )));
- }
- }
- /**
- * ???????? ???????.
- *
- * ?????? ?????? ?????? ????, ?.?. ?? ???????? ?? ???????, ???
- * ????????? ???????????????? ???????.
- */
- public function testNodeCheckPermissions()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $this->assertTrue($node->checkPermission(Molinos_Auth_ACL::CREATE));
- $this->assertTrue($node->checkPermission(Molinos_Auth_ACL::DELETE));
- }
- /**
- * ???????? ???????? ?????.
- *
- * ??????????? ??????????? action ? ??????? ??????? ?????????.
- */
- public function testNodeFormGet()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $form = $node->getForm();
- $this->assertTrue($form instanceof Molinos_Form_Form);
- $this->assertEquals('api/node/create', $form->action);
- }
- public function testNodeGetFormAction()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $this->assertEquals('api/node/create', $node->getFormAction());
- }
- public function testNodeFormProcess()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $node->formProcess(array(
- 'foo' => 'bar',
- ));
- // ?????? ?? ?????? ????, ?.?. ??? ??????????????? ???? dummy ???? foo ?? ???????.
- $this->assertFalse(isset($node->foo));
- }
- /**
- * ???????? ?????? ??????????????? ??????.
- * @expectedException RuntimeException
- */
- public function testNodeBadMethodCall()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $node->aMethodThatDoesNotExist();
- }
- /**
- * ???????? ????????? ?????.
- */
- public function testNodeGetSchema()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $schema = $node->getFormFields();
- $this->assertTrue(is_array($schema), "Node::getFormFields() must have returned an array.");
- }
- public function testNodeGetActionLinks()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $links = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ))->getActionLinks();
- $this->assertTrue(is_array($links));
- foreach (array('edit', 'delete', 'publish') as $action)
- $this->assertTrue(array_key_exists($action, $links));
- }
- public function testNodeGetActionLinksXML()
- {
- $ctx = $this->ctx;
- $t = new Molinos_Database_Transaction();
- $xml = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ))->getActionLinksXML();
- $this->assertTrue(0 === strpos($xml, '<links>'));
- }
- public function testNodeGetSortedLis()
- {
- $ctx = $this->ctx;
- $nodeapi = Molinos_Core_API::getInstance('node');
- $t = new Molinos_Database_Transaction();
- $class = $this->getNewType();
- $nodeapi->create(array('class' => $class, 'name' => 'z'))->save();
- $nodeapi->create(array('class' => $class, 'name' => 'y'))->save();
- $nodeapi->create(array('class' => $class, 'name' => 'x'))->save();
- $list = $nodeapi->getSortedList($class);
- $this->assertTrue(is_array($list));
- $this->assertFalse(empty($list));
- $list = $nodeapi->getSortedList('dummyx');
- $this->assertTrue(is_array($list));
- $this->assertTrue(empty($list));
- }
- public function testNodeGetName()
- {
- $nodeapi = Molinos_Core_API::getInstance('node');
- $node = $nodeapi->create(array(
- 'class' => 'dummy',
- ));
- $this->assertTrue(null === $node->getName());
- $node = $nodeapi->create(array(
- 'class' => 'dummy',
- 'name' => 'xyz',
- ));
- $this->assertTrue('xyz' === $node->name);
- }
- public function testNodeGetEnabledSections()
- {
- $t = new Molinos_Database_Transaction();
- $nodeapi = Molinos_Core_API::getInstance('node');
- $node = $nodeapi->create(array(
- 'class' => 'dummy',
- ));
- $list = $node->getEnabledSections();
- $this->assertTrue(is_array($list));
- $this->assertTrue(empty($list));
- $node = $nodeapi->create(array(
- 'class' => 'article',
- ));
- $list = $node->getEnabledSections();
- $this->assertTrue(is_array($list));
- $this->assertTrue(empty($list));
- }
- /**
- * @expectedException RuntimeException
- */
- public function testNodeGetImage()
- {
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- $node->getImage();
- }
- /**
- * ???????? ?????????????? ?????????? ?????? ?????. ???????????? ?????
- * ?? ????????? ???? ?? ??????, ??? ?????????? ????????????? ?????????????.
- * ? ????????? ?????? ???????? ???????? ? ????????? ??? ?? ????.
- */
- public function testNodeNoRequiredDefaultFields()
- {
- $node = Molinos_Core_API::getInstance('node')->create(array(
- 'class' => 'dummy',
- ));
- foreach ($node->getFormFields() as $k => $v)
- $this->assertTrue(empty($v['required']), "Must have no mandatory fields in the default schema, but {$k} is.");
- }
- /**
- * ???????? ?????? ?? ?????? ??????? ??? ? ????????? ???????????.
- */
- public function testNodeListURI()
- {
- $t = new Molinos_Database_Transaction();
- $nodeapi = Molinos_Core_API::getInstance('node');
- $type = $nodeapi->create(array(
- 'class' => 'type',
- 'name' => 'testlisturi',
- 'deleted' => 0,
- 'isdictionary' => 0,
- ))->save();
- $node = $nodeapi->create(array(
- 'class' => 'testlisturi',
- ));
- $this->assertEquals('admin/content/list/testlisturi', $node->getListURL());
- $type->isdictionary = true;
- $type->save();
- $this->assertEquals('admin/content/dict/testlisturi', $node->getListURL());
- }
- /**
- * ???????? ?????? getParentIds().
- *
- * ??????? ????? ???????? ??????? ??????????? ????, ????? ??????? ????????
- * ??????? (?? ????????) ? ????????? ???????????? ??????? ????????. ??????
- * ???? ?????? ? ????? ????????????? ???????. ????? ???????? ???????
- * ??????????? ? ???????? ???????????.
- *
- * @url http://code.google.com/p/molinos-cms/issues/detail?id=1895#c7
- */
- public function testNodeGetParentIds()
- {
- $t = new Molinos_Database_Transaction();
- $api = Molinos_Core_API::getInstance('node');
- $type = $this->getNewType();
- $root = $api->create(array(
- 'class' => $type,
- ))->save();
- $child1 = $api->create(array(
- 'class' => $type,
- 'parent_id' => $root->id,
- ));
- $children1 = $child1->getParentIds();
- $child1->save();
- $child2 = $api->create(array(
- 'class' => $type,
- 'parent_id' => $root->id,
- ));
- $children2 = $child2->getParentIds();
- $child2->save();
- $wanted = array($root->id);
- $this->assertEquals($wanted, $children1);
- $this->assertEquals($wanted, $children2);
- }
- /**
- * ???????? ????????? ?????? ?????????????? ? api/url/modify.
- *
- * ?????????? ??? ?????-???? ??????????.
- *
- * @expectedException Molinos_HTTP_Exceptions_BadRequest
- */
- public function testURLModifierNoArguments()
- {
- $this->do_get('api/url/modify');
- }
- public function testURLModifierChangePath()
- {
- $res = $this->do_get('api/url/modify', array(
- 'from' => '/submit/file/ftp?destination=%2Fnode%2F6637%2Fpreview&sendto=6637',
- 'path' => 'submit/file/local',
- ));
- $this->assertEquals('/submit/file/local?destination=%2Fnode%2F6637%2Fpreview&sendto=6637', $res->getLocation($this->ctx));
- }
- public function testTempFolderCleanUp()
- {
- $dirName = Molinos_Core_Utils::tmpdir();
- $now = time();
- touch($fn1 = $dirName . DIRECTORY_SEPARATOR . 'testfile1', $now);
- touch($fn2 = $dirName . DIRECTORY_SEPARATOR . 'testfile2', $now - 2592000);
- $this->assertEquals($now, filemtime($fn1));
- $this->assertEquals($now - 2592000, filemtime($fn2));
- $this->do_get('cron/temp-files-cleaner');
- $this->assertTrue(file_exists($fn1));
- $this->assertFalse(file_exists($fn2));
- unlink($fn1);
- }
- }