Documentation.php

<?php


namespace Phad\Test\Main;

/**
 * Used for testing code that's written in the documentation
 *
 */
class Documentation extends \Phad\Tester {

    static protected bool $is_if_allowed;


    static public function is_if_allowed(){
        return static::$is_if_allowed;
    }

    public function testIfOnDataNode(){
        $p = $this->phad();

        $data = $this->makeStandardBlogTable();
        
        $rows = $this->dbQuery($p->pdo, 'SELECT * from blog');
        print_r($rows);


        $this->test("if fail does not trigger 403 error (data available)");
        static::$is_if_allowed = false;
        $view = $p->item('Other/IfOnDataNode', ['type'=> 'bear']);

        $this->str_not_contains($view.'', '403 error');
        $this->str_not_contains($view.'', '404 error');
        $this->str_not_contains($view.'', 'bear');
        $this->str_not_contains($view.'', 'Type:');


        $this->test("When if returns true, get data and display no error");
        static::$is_if_allowed = true;
        $view = $p->item('Other/IfOnDataNode', ['type'=> 'bear']);

        $this->str_not_contains($view.'', '403 error');
        $this->str_not_contains($view.'', '404 error');
        $this->str_contains($view.'', 'bear');


        $bad_type = 'nonononono';
        $this->test("if fail does not trigger 403 error, and 404 error is not triggered by data unavailable");
        static::$is_if_allowed = false;
        $view = $p->item('Other/IfOnDataNode', ['type'=> $bad_type]);

        $this->str_not_contains($view.'', '403 error');
        $this->str_not_contains($view.'', '404 error');
        $this->str_not_contains($view.'', $bad_type);
        $this->str_not_contains($view.'', 'Type:');

        $this->test("404 error when `if` code returns true AND data is empty");
        static::$is_if_allowed = true;
        $view = $p->item('Other/IfOnDataNode', ['type'=> $bad_type]);

        $this->str_contains($view.'', '404 error');
        $this->str_not_contains($view.'', '403 error');
        $this->str_not_contains($view.'', $bad_type);
        $this->str_not_contains($view.'', 'Type:');

    }

}